Search code examples
jekyllgithub-pages

Jekyll redirects to a 404 and does not render post.md


I want my index.md seen at

to redirect to pages I have written in markdown

I tried implementing, post_url variable , such as documented in order to successful redirect to a page written in markdown without success, as it points to a 404 at

[Name of Link]({% post_url 2010-07-21-name-of-post %})

http://www.jekyllrb.com/docs/liquid/tags/#linking-to-posts

At first I thought this was an error from the for loop, so I added the link manually as detailed in the documentation specifically for pages written in markdown.

index.md

# Index of all my content

[Library Carpentry Workshop July 2020]({% post_url 2020-07-27-library-carpentry-workshop-american-university-notes %})


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

_config.yml

theme: jekyll-theme-slate
url: https://jtm-lis.github.io
baseurl: /Julien_Tremblay_McLellan #NO TRAILING SLASH
title: Julien Tremblay McLellan's Website
author: Julien Tremblay McLellan
email: [email protected]
description: > # this means to ignore newlines until "baseurl:"
  Write an awesome description for your new site here. You can edit this
  line in _config.yml. It will appear in your document head meta (for
  Google search results) and in your feed.xml site description.
# social links
twitter_username: jtm-lis # DO NOT include the @ character, or else the build will fail!
github_username:  jtm-lis # DO NOT include the @ character, or else the build will fail!

show_excerpts: true # set to false to remove excerpts on the homepage

What am I doing wrong?


Solution

  • The problem here is that the link does not use the site.baseurl, so instead of linking to

    https://jtm-lis.github.io/Julien_Tremblay_McLellan/2020/07/27/library-carpentry-workshop-american-university-notes.html

    you are linking to

    https://jtm-lis.github.io/2020/07/27/library-carpentry-workshop-american-university-notes.html which does not exist.

    The fix is easy though, you just need to add site.baseurl to your link as in

    [Name of Link]({% post_url 2010-07-21-name-of-post | prepend: site.baseurl %})
    

    When doing this, you may encounter an other problem on your localhost environment, since most likely your site.baseurl folder does not exist there. So it will work on your live site, but has broken links in your local environment.

    To work normally on localhost just override the baseurl property when you serve it:

    jekyll serve --baseurl ""
    

    or if you work with bundler

    bundler exec jekyll serve --baseurl ""