Pelican Internal Article Linking

Posted on Fri 10 July 2020 in Dev Resources

Cover image
Image by Matteo Catanese

When setting up this blog I had a heck of a time figuring out how to do linking between articles. Turns out it is pretty easy. The pelican docs show how this is possible. The key is to use relative references back to the markdown file you are trying to link to. When it crunches the output, it will be rendered correctly to the html.

suppose your project is using the following directory structure

articles
    └── 2020
        ├── first-article
        │   ├── first_article.md
        │   ├── img
        │   │   ├── cactus1.jpg
        │   │   └── cactus2.jpg
        │   └── notebooks
        ├── git-submodules
        │   ├── img
        │   │   ├── cactus1.jpg
        │   │   └── cactus2.jpg
        │   ├── notebooks
        │   └── post.md
        ├── liquid-tags
        │   ├── img
        │   │   ├── cactus1.jpg
        │   │   └── cactus2.jpg
        │   ├── liquid-tags.md
        │   └── notebooks
        ├── pelican-autostatic
        │   ├── img
        │   │   ├── cactus1.jpg
        │   │   └── cactus2.jpg
        │   ├── notebooks
        │   └── post.md
        └── pelican-internal-linking
            ├── img
            │   ├── cactus1.jpg
            │   └── cactus2.jpg
            ├── notebooks
            └── post.md

If you want to link to the pelican-autostatic article from this article you would create the link like so.

[pelican-autostatic]({filename}../pelican-autostatic/post.md) 

If this is still confusing, check out the raw markdown file for this post so you can see how it works.