For my website I have stored links and other information about all pages in a data file.
data/pages.yaml
:
pageA:
link: /some-long-url-subject-to-change.html
name: PageA name
info: Some other related info
Then, in my HAML template (source/test.haml
), I can print relative path to pageA with = data.pages.pageA.link
.
Now, I want to use markdown syntax to reference that page by its name (pageA).
Example (source/test.haml
):
.info
:markdown
This is some text with a [manual link](https://google.com) to somewhere.
This is another text with a [data-referenced link](pageA) to that page.
In the same way as first “manual link” links to Google, I would like second link to use relative path stored in data file to create a link. One solution that I see to solve this problem would be to replace (pageA)
text with evaluation of = data.pages.pageA.link
prior to it being rendered by markdown.
I assume this would be possible by creating custom helper, but I can’t quite nail it.
Ps. I now posted my attempted solution in a reply with primitive substitution and explained how it didn’t work for me.