Linking _pages Minimal Mistakes, post_url and link

I’ve been using link for some time to cross reference pages in the collections of my site which is based on the Minimal Mistakes theme.

For collections, these work fine:

[document]: {% link _collection/document.md %}
[post]: {% _posts/2018-0501-post.md %}

where _collection is a collection directory beneath collections (as defined by collections_dir in _config.yml). It works for _posts, and anything else I have there.

Now I cannot get post_url to work. If I try

[post]: {% post_url 2018-0501-post.md }

then the site does not build because the file cannot be found. I guess that is because the post_url code doesn’t know about the movement of posts into collections_dir ?

Should post_url work with posts inside collections_dir ?

I started looking at this because I wanted to link a page (i.e. a document in _pages, which is outside the collections_dir) but I could not work out how to do that with link.

Is it possible to link to a page ?

Remove the file extension and it should work. It’s used slightly different from {% link %} which you provide the full file name.

[post]: {% post_url 2018-05-01-post %}

Ah, yes. That does indeed work like that. Now I just need to work out how to link to a page (that is outside collections_dir). Is that possible (other than linking to the generated file’s location) ?

Check that link above, it has suggestions on determining the correct path of a file when using the link tag.

Ok, so I put {{ page.path }} on a page that I wanted to link to and viewing that page revealed its path as _pages/document.md

But that’s what I thought it was. That’s what I thought I’d tried this morning, and what didn’t work (since deleted so cannot compare). I try it now and, guess what, it works:

[document]({% link _pages/document.md %}) 

So I am somewhat stumped over what I did wrong before, because it works. Appreciate the help but feel a bit green. Thanks for the pointer :slight_smile:

Wel’ it turns out not to be so straightforward and that’s why it didn’t work for me previously.

Looking at {{ page.path }} illustrates that setting a permalink in front matter affects the page path. I understood page.path to refer to the acutal path to the page’s source markup file. But that appears not to be the case.

If a page has no frontmatter permalink then page.path is the path beneath _pages (ie for _pages/directory/document.md it returns directory/document.md and that successfully works with link to reference the page. The rendered page URL is, however, different and follows the permalink set in config.yml.

That’s the behaviour I would expect.

If the page has a frontmatter permalink then it affects page.path. For example a permalink: some/random/path in the frontmatter causes page.path to return some/document.md which is neither the complete permalink nor the real path of the file. In my configuration, this permalink doesn’t affect the URL of the rendered file which continues to follow the permalink set in config.yml.

Furthermore, if the permalink is the same path as the file then the {{ page.path }} becomes the file name only.

All of this leaves three possible results for {{ page.path }}:

  • with permalink different to file location: some/document.md
  • with permalink same as file location: document.md
  • without permalink: directory/document.md

So page.path is not always the acutal path to the page’s source markup file.

I don’t understand what’s happening - is it a bug, am I doing something wrong, I don’t know. I could spend ages researching it (more than I have already) which I can’t really afford. I know enough to get what I want to work but there does seem to be something odd going on…


An afterthought… it’s possible to name files and directories so that there is a conflict between _pages and _collections, which it would appear that _pages wins. However, the requred naming for such a conflict makes this scenario unlikely.