【问题标题】:Excerpt post not linking correctly in jekyll摘录帖子在 jekyll 中没有正确链接
【发布时间】:2014-04-17 15:17:10
【问题描述】:

我正在构建一个非常简单的网站,其中包含一个 Jekyll 博客。博客位于不同的模板 (blog.html) 中,站点位于默认模板 (index.html) 中。我正在尝试在链接到博客的主页(默认 index.html)中添加帖子的摘录,但我的 URL 已损坏。

_config.yml:

name: Patterns - Target Creative
markdown: redcarpet
pygments: true
baseurl: /patterns
url: http://localhost/patterns/

这就是我在主页中插入帖子摘录的方式:

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

摘录出现在主页上,但链接已损坏。我需要做什么才能使变量 {{ post.url }} 正确链接。

The link being populated: http://localhost:4000/jekyll/update/2014/02/04/Live-Shape-Tool-in-Photoshop-CC.html

谢谢,

朱利亚诺

【问题讨论】:

    标签: jekyll


    【解决方案1】:

    您需要在链接的开头添加site.baseurl。否则,Jekyll 将假定链接应该以 http://localhost:4000 而不是 http://localhost:4000/patterns 开头。

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

    Project Page URL Structure。虽然本文是在考虑 GitHub Pages 的情况下编写的,但它也为任何指定非空 site.baseurl 的 Jekyll 站点提供了有用的信息。

    另外,请注意,在本地测试您的网站时应使用jekyll serve --baseurl '',这样您就可以在http://localhost:4000/ 而不是http://localhost:4000/patterns/ 上查看您网站的索引。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多