【问题标题】:jekyll blog permalink breaks and yields "404 not found"jekyll 博客永久链接中断并产生“404 未找到”
【发布时间】:2016-09-10 07:02:27
【问题描述】:

我创建了一个包含几页和几篇博客文章的小型网站。它托管在我组织的服务器上,我将 _site/ 目录的所有内容通过 ftp 传输到网站的子目录中。因此 Jekyll 站点位于 http://myusername.foobar.foo/thiswebsite/ 。

在我的 _config.yml 中

baseurl: "/thiswebsite"
url: "http:// myusername.foobar.foo"

现在所有页面都能正确显示。但博客文章不会。

在每篇博文的 YAML 前言中:

permalink: /:title.html

然后我最终在 index.html 页面上生成了指向 http://myusername.foobar.bar/blog-title.html 的博客文章的链接,但实际的博客文章位于 http://myusername.foobar.bar /thiswebsite/blog-title.html。因此,如果人们点击 index.html 上的链接,他们将看到 404。

在 index.html 上我有:

{% for post in site.posts %}
  <h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
  <blockquote>
  {{ post.excerpt }}
  </blockquote>
{% endfor %}

我原以为{{ post.url }} 会自动为帖子插入正确的 URL,但显然这并没有发生。 :(

我在哪里搞砸了?

Jekyll 版本 3.1.2

注意:http:// 后面的空格是故意的,因为 StackExchange 认为我在发布链接,这显然是不允许的。在我实际的 markdown 和 html 中,它们是正确的 URL。

【问题讨论】:

  • 在配置中设置 baseurl 时需要 {{site.baseurl}}{{post.url}}

标签: jekyll


【解决方案1】:

链接到收藏品(帖子是收藏品)或页面:

例如:&lt;a href="{{ site.baseurl }}{{ post.url }}"&gt;{{ post.title }}&lt;/a&gt;

&lt;a href="{{ post.url | prepend: site.baseurl }}"&gt;{{ post.title }}&lt;/a&gt;

资源链接(图片、脚本、css...)也是如此。

例如:&lt;link rel="stylesheet" href="{{ "/css/main.css" | prepend: site.baseurl }}"&gt;

&lt;script src="{{ site.baseurl }}/js/script.js"&gt;&lt;/script&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-06
    • 2016-07-19
    • 2015-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多