我正在Jekyll建立一个非常简单的博客网站。该博客位于不同的模板(blog.html)中,该网站位于默认模板(index.html)中。我正在尝试添加链接到博客的主页面(默认index.html)中的帖子摘录,但我的网址已损坏。
_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
谢谢,
Juliano的
答案 0 :(得分: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/
查看网站的索引。