Search code examples
jekyll

Jekyll Internal Post Links


This is a pretty niche problem, but... I run a blog that runs on Jekyll and I post very regularly. To keep my editing sane I regularly archive posts, and those archived posts get a pretty strict structure. But, I go a full year before archiving.

Where this hurts is in links to other posts. I used to be able to absolutely reference the file name (per jekyll markdown internal links), but this appears to be being deprecated:

Deprecation: A call to '{% post_url 2018-09-06-peppermint %}' did not match a post using the new matching method of checking name (path-date-slug) equality. Please make sure that you change this tag to match the post's name exactly.

Now, if I have to include the full path to the file, then when I archive my posts for the year I have to parse all of the posts for the entire year and update any links between them to include the new file path for their archived location, defeating the point of using this tool at all. A direct link to the page would actually be better, given that I change my URL structure less often.

Is there a better solution for internal links that doesn't depend on the file structure, allowing a file to be moved without having to update every link to that file?

Example File structure:

 _posts
   -2018
     -post1
     -post2
     -etc
   -Archive
     -2017
     -2016

If there's no better answer, I may just have to go back to using absolute external links.


Solution

  • Solution 1. Use your own include

    Create an post_url.html file and write this:

    {% include post_url.html slug="2018-09-06-peppermint" %}
    

    The include (called post_url.html) should find the post with the right slug and echo the link, like this:

    {% assign link = site.posts | where:'slug',include.slug %}
    <a href="{{ link[0].url }}">{{ link[0].title }}</a>
    

    Solution 2. Search and replace

    You have to parse posts? A simple search and replace on all files, looking for (/2018/ and replace with (/Archive/2018/ should do the trick (if you use markdown links). This should take just a few seconds.