慕妍 發表於 2022-10-19 17:31:00

教程|用 Jekyll 在 Github Pages 上搭建个人网站

<h2 id="开始">开始</h2>
<p>按照Jekyll官网的指示:</p>
<pre><code>gem install bundler jekyll
</code></pre>
<p>但是进行下一步时,显示<code>command not found: jekyll</code>。</p>
<p>查了下,根据这篇文章,尝试<code>sudo</code>:</p>
<pre><code>sudo gem install jekyll
</code></pre>
<p>之后就可以正常运行<code>jekyll</code>了,继续</p>
<pre><code>jekyll new my-awesome-site
cd my-awesome-site
bundle exec jekyll serve
</code></pre>
<p>然而报错<code>cannot load such file -- webrick (LoadError)</code>。Google一下,找到一些讨论串(或者博文),顺着找到Github上的issue,根据它说的运行</p>
<pre><code>bundle add webrick
</code></pre>
<p>之后,可以正常运行<code>bundle exec jekyll serve</code>了,问题解决!</p>
<p>现在,可以用浏览器打开<code>http://127.0.0.1:4000/</code>上看到示例<br>
网站了。</p>
<h3 id="没有用的操作">没有用的操作</h3>
<p>参照官网的Troubleshooting部分,更新<code>gem</code>:</p>
<pre><code>gem update --system
</code></pre>
<p>这一步很慢,不知道有什么解决办法……</p>
<pre><code>jekyll new my-awesome-site
cd my-awesome-site
bundle exec jekyll serve
</code></pre>
<h2 id="github-pages">Github Pages</h2>
<p>根据Github Pages的说明,创建一个叫 <em>username</em>.github.io 的仓库即可。先把它克隆到本地,以进一步操作。</p>
<p>之后,参照官方的使用 Jekyll 设置 GitHub Pages 站点的介绍进行操作,正常进行Creating a GitHub Pages site with Jekyll - GitHub Docs的操作即可。</p>
<p>可以用Github Desktop来进行某些操作。</p>
<h3 id="关于baseurl">关于baseurl</h3>
<p>如果你的仓库就是 <em>username</em>.github.io 的话,baseurl留空就行了,即使你把你的站点放在了类似 <code>/docs</code> 的子文件夹里,而不要按照Creating a GitHub Pages site with Jekyll - GitHub Docs的第13步操作,在 <code>_config.yml</code> 里进行如下操作:</p>
<pre><code class="language-yml">baseurl: /REPOSITORY-NAME/      # place folder name if the site is served in a subfolder
</code></pre>
<p>如果真这么做了的话,网站会崩掉。参见</p>
<p>如果真想在 <code>/docs</code> 下访问,根据这个回答,似乎需要把这个文件夹 split 到一个叫 docs 的仓库中,详见Splitting a subfolder out into a new repository - GitHub Docs。</p><br><br>
来源:https://www.cnblogs.com/frank3215/p/16807158.html
頁: [1]
查看完整版本: 教程|用 Jekyll 在 Github Pages 上搭建个人网站