简体   繁体   English

摘录文章在jekyll中未正确链接

[英]Excerpt post not linking correctly in jekyll

I'm building a very simple website with a blog in Jekyll. 我正在用Jekyll中的博客构建一个非常简单的网站。 The blog lives in a different template (blog.html) and the site lives in a default template (index.html). 该博客位于另一个模板(blog.html)中,该网站位于一个默认模板(index.html)中。 I'm trying to add excerpts of the posts in the main page (default index.html) linking to the blog but I'm getting broken URLs. 我试图在链接到博客的主页(默认index.html)中添加帖子摘录,但URL断开了。

_config.yml: _config.yml:

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

And this is how I'm inserting excerpts of the post in the main page: 这就是我在主页中插入帖子摘录的方式:

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

Excerpts appear on the main page but links are broken. 摘录显示在主页上,但链接断开。 What do I need to do to have the variable {{ post.url }} link correctly. 我需要怎么做才能正确连接变量{{post.url}}。

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

Thanks, 谢谢,

Juliano 尤利亚诺

You need to add site.baseurl to the beginning of your links. 您需要将site.baseurl添加到链接的开头。 Otherwise, Jekyll will assume that links should start with http://localhost:4000 instead of http://localhost:4000/patterns . 否则,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>

See Project Page URL Structure . 请参阅项目页面URL结构 While this article was written with GitHub Pages in mind, it also has useful information for any Jekyll site that specifies a non-empty site.baseurl . 虽然本文是考虑GitHub Pages编写的,但它对于指定非空site.baseurl任何Jekyll站点也具有有用的信息。

Also, note that you should use jekyll serve --baseurl '' when testing your site locally so you can view your site's index at http://localhost:4000/ instead of http://localhost:4000/patterns/ . 另外,请注意,在本地测试站点时,应使用jekyll serve --baseurl '' ,以便您可以在http://localhost:4000/而不是http://localhost:4000/patterns/查看站点的索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM