This answer 仍然有效。但我必须承认,调整 baseurl 并不是真正可移植的。你不可能总是猜到正确的路径。
让我们尝试让它在具有诸如./path/to 之类的亲戚网址的文件系统上运行。
我们需要调整什么
检查索引页面,坐在file:///path/to/_site/index.html,我们可以发现一些潜在的问题:
- 样式不起作用
- 帖子按照
/:categories/:year/:month/:day/:title.html permalink 模式链接,如file:///jekyll/update/2016/08/05/welcome-to-jekyll.html。而且我们知道文件夹层次结构在使用相对链接时是一场噩梦。
- 页。唯一的一个是已经定义的指向
/about/ 的永久链接,这在文件系统中不起作用,因为它解析为 file:///about/
为了避免文件夹分层地狱,我们将在根目录下创建每个帖子和页面。
重新定义永久链接
在 _config.yml 我们添加:
defaults:
-
scope:
type: "posts"
values:
permalink: :slug:output_ext
-
scope:
type: "pages"
values:
permalink: :basename:output_ext
现在任何帖子都在根目录下生成。
但是这个 about 页面仍然是在 about 文件夹中生成的。为什么?
因为前面的永久链接会覆盖默认配置。我们从 about.md 前面的内容中删除了permalink: /about/,现在我们的页面在根/path/to/_site/about.html 处生成。好!
重写链接
我们现在使用./ 表达式使我们的链接相对于root。
_includes/head.html
<link rel="stylesheet" href="{{ "/css/main.css" | prepend: site.baseurl }}">
变成
<link rel="stylesheet" href="{{ "./main.css" }}">
_includes/header.html
<a class="site-title" href="{{ site.baseurl }}/">{{ site.title }}</a>
变成
<a class="site-title" href="./index.html">{{ site.title }}</a>
和
<a class="page-link" href="{{ my_page.url | prepend: site.baseurl }}">{{ my_page.title }}</a>
变成
<a class="page-link" href="./{{ my_page.url }}">{{ my_page.title }}</a>
index.html
<a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
变成
<a class="post-link" href="./{{ post.url }}">{{ post.title }}</a>
您现在可以导航了。
记得把所有东西都保留在根目录下就可以了。