-
I want some of my tags to have their own homepages, in a sense to make the tag a 'series' with a root homepage that links to the list of pages containing that tag (i am thinking i want to limit this to the tag property so i can easily change my mind about if a tag should constitute a 'series'). I have tag pages automatically set up based on this tip, but I'm not sure how to add content to that page I'm imagining a 'tags' folder with files named after the tag in question, then import that path directly into my I guess I'm also curious about the general idea of providing metadata to "collection list" pages (ie tag#1 is reverse chronological, tag#2 content has different metadata to pull into its listing page etc) Are there any other patterns for doing something like this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
@thedamon Since you said you want "some of my tags to have their own homepages", I randomly went with a global data file which controls which tags are a series and holds their descriptions, etc. https://github.com/pdehaan/11ty-3033#readme src/_data/series.jsmodule.exports = [
{name: "cat", description: "this is something about a cat."},
{name: "dog", description: "this is a sentence about how dogs are better than cats."},
{name: "bird", description: "birds are lousy pets."},
]; src/_tags.njkThen, in my template, I just paginate over that array if valid series tags and generate the pages: ---
pagination:
data: series
size: 1
alias: tag
permalink: "/tags/{{ tag.name | slugify }}/"
---
<header>
<h1>{{ tag.name }}</h1>
<p>{{ tag.description }}</p>
</header>
<section data-count="{{ collections[tag.name] | length }}">
{% for p in collections[tag.name] %}
<article>
<h1>{{ p.data.title }}</h1>
<a href="{{ p.url }}">More…</a>
</article>
{% endfor %}
</section> OUTPUT> eleventy
[11ty] Writing www/tags/cat/index.html from ./src/pages/_tags.njk
[11ty] Writing www/tags/dog/index.html from ./src/pages/_tags.njk
[11ty] Writing www/tags/bird/index.html from ./src/pages/_tags.njk
[11ty] Writing www/pages/six/index.html from ./src/pages/six.njk
[11ty] Writing www/pages/five/index.html from ./src/pages/five.njk
[11ty] Writing www/pages/four/index.html from ./src/pages/four.njk
[11ty] Writing www/pages/three/index.html from ./src/pages/three.njk
[11ty] Writing www/pages/one/index.html from ./src/pages/one.njk
[11ty] Writing www/pages/two/index.html from ./src/pages/two.njk
[11ty] Wrote 9 files in 0.05 seconds (v2.0.1) And my generated www/tags/cat.html file looks like this (since I had two files which had <header>
<h1>cat</h1>
<p>this is something about a cat.</p>
</header>
<section data-count="2">
<article>
<h1>Four</h1>
<a href="/pages/four/">More…</a>
</article>
<article>
<h1>One</h1>
<a href="/pages/one/">More…</a>
</article>
</section> I didn't have anything tagged with "bird", so thats a mostly empty page; although I'm sure it could be tweaked to not generate the page if there are zero posts for that series [using <header>
<h1>bird</h1>
<p>birds are lousy pets.</p>
</header>
<section data-count="0">
</section> |
Beta Was this translation helpful? Give feedback.
-
This helps a lot, thank you! I think a data object like that will give me a great way of controlling a lot of the functionality I'm looking for :). One thing I'm not sure about though, is some of these have much longer "intro" content.. like a short article, maybe with images, or at least several paragraphs. I was thinking of putting those into |
Beta Was this translation helpful? Give feedback.
-
Yeah that does it! i wasn't sure if i needed or how to source from files like that dynamically, but that does it for sure |
Beta Was this translation helpful? Give feedback.
-
Follow up question as I'm working on this more — how can I check that the file actually exists? It seems to break if i add a tag that doesn't have an equivalent
|
Beta Was this translation helpful? Give feedback.
Sounds like you want longer and more complex than multiline YAML content... In that case, I might drop a bunch of .md files in your ./src/_includes dir and name them after the tags and then use something like this with the EleventyRenderPlugin plugin:
And my ./src/_includes/dog.md file looks like this work of genius:
And my updated eleventy.config.js has these tweaks:
+const { EleventyRenderPlugin } = require("@1…