statik
statik copied to clipboard
How to deal with internal link?
Hi,
I have the following problem: I would link to make internal link in a data. For example
---
title: Second post
author: paul
---
## Overview
This is the content of the **second** post.
Go to [First post]( ??? )
The problem is that the url of the first post is defined in the views and generated by statik. Is there a way to access to it in data? It looks like a snake biting its own tail... :-/
This is definitely a necessary feature, but like you say, quite tricky to implement. The ideal way of implementing this would most likely involve some kind of Markdown pre-processing or post-processing on rendered templates. One idea I've had in this regard is to use a custom, Statik-specific URL schema that would be translated into the relevant relative URL for the target element (called a "reverse URL lookup").
For example, if you had a Post
model whose instance is rendered by the view posts.yml
, and the path to a post is built up by /{{ post.date|date("%Y/%m/%d") }}/{{ post.slug }}
(as it is on my personal blog), and you wanted to refer from one post to another (whose primary key is, for example, first-post
), you'd use some kind of URL schema like so:
Go to [first post](statik://posts/first-post) ...
where the URL schema is statik://<view-name>/<primary-key>
for a complex view, or just statik://<view-name>
if it's a simple view.
This would then be processed to:
Go to <a href="/2018/01/07/first-post/">first post</a> ...
For now, as per my blog, I've hard-coded relative links from one post to another, because the permalink doesn't change.