eleventy
eleventy copied to clipboard
URL as anchor links in collections
Hi. I have a bunch of files in a directory which I'd like to output on a page (via collections) but not to separate files, and I'd like these sections to have a URL with an anchor which I can reference elsewhere. So for example:
/some-directory
/another-dir/
index.njk
/sections
sections.json
section-1.md
section-2.md
...
where the URLs would be /some-directory/another-dir#section-1, /some-directory/another-dir#section-2, ...
// index.njk
{% for item in collections.sections %}
{{ item.url }}
{% endfor %}
I'm really scratching my head on this one, but all I got is some convoluted way to try to get the parent path in the front-matter, but it's really messy, not dynamic and I don't have a single value to call later:
// sections.json
{
"permalink": false,
"anchorPath": "some-directory/another-dir",
"tags": "sections"
}
Would the upcoming computed data feature be the most practical way to do this or am I missing something?
Any help would be much appreciated.
Would markdown-it-anchor help you in the meantime?
This looks like a job for pagination navigation.
@Ryuno-Ki Although I could consider having each entry in a single md file, it doesn't seem as if I'd be able to iterate over a list of anchors elsewhere in the site. @reubenlillie This could do the trick, I need to dig into this a bit more.
I believe this is a duplicate of #889, which will probably head into the enhancement queue soon.