Is there a way to use the path to a specific blog post as a taxonomy item, and be able to embed that post in a different one that points to the former within its metadata? For example, given a post at /blog/related-post
, I want to call it in a second post using:
[taxonomies]
related=["blog/related-post","<others here if more than one>"]
From there I want to retrieve and embed data from those related posts further down in /blog/second-post, say the linked title, and summary? By setting it up this way instead of using tags, my assumption is it would reduce build times since it’s only processing related items when specifically added.
Any way to accomplish this?
If anyone’s looking to do the same thing, I found a way to make this work without using taxonomies by creating a custom variable instead. In the front matter of a post itself, you can do something like:
[extra]
related=["blog/<first post>.md","blog/<second post>.md", etc.]
to which you can add any number of related posts as you write them. Then in your page template, you can use looping code in tandem with the get_page
function to access the relevant data from each of the related posts:
{% if page.extra.related %}
<h2>Related posts:</h2>
{% set items = page.extra.related %}
{% for item in items %}
{% set post = get_page(path=item) %}
<a href="{{ post.permalink}}">{{ post.title }}</a><br/>
{{ post.description }}
<br/><br/>
{% endfor %}
{% endif %}
The beauty of using this as opposed to taxonomy tags, is it’s only triggered when the variable itself is present, and will only pull the specific linked posts. I’d think this would maintain great build performance, as it doesn’t involve pulling from a tag across the entirety of your content files (even if you’re limiting the number of related tag posts that get retrieved).