2
votes

I'm building a very simple website with a blog in Jekyll. The blog lives in a different template (blog.html) and the site lives in a default template (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.

_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.

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

Thanks,

Juliano

1

1 Answers

1
votes

You need to add site.baseurl to the beginning of your links. Otherwise, Jekyll will assume that links should start with http://localhost:4000 instead of 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. 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.

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/.