3

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.

David Scott
  • 796
  • 2
  • 5
  • 22
  • it looks like you are right - I don't use post_url but it was my understanding that it worked as you have been using it. Now it looks like it wants the correct path no matter what (I don't think it is deprecated, just new behavior - wants full path?). There is also `link` which does much the same thing, but it looks like it wants the path too. – Ron Nov 17 '18 at 07:02
  • Needing the path is actually more likely to change for me though, as I adjust my archiving. The path is likely to change, but the link structure is not. If the path is required... it's actually easier for me to do absolute URLs given that those are weirdly less likely to change.. – David Scott Nov 18 '18 at 09:01
  • I have the same probem in 2022. Now it says that's deprecated. It still works but I'm looking for a solution and I haven't found anything viable. – Mario Codes Sep 26 '22 at 09:40
  • Unsurprised. I used the recommendation in the answer below, but then, after that I ended up just migrating off of Jekyll. – David Scott Sep 27 '22 at 19:35

1 Answers1

3

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.

Mr. Hugo
  • 11,887
  • 3
  • 42
  • 60