11ty / eleventy-base-blog

A starter repository for a blog web site using the Eleventy static site generator.
https://demo-base-blog.11ty.dev/
MIT License
1.25k stars 617 forks source link

<title> for tags pages is missing #15

Closed mathiasbynens closed 6 years ago

mathiasbynens commented 6 years ago

e.g. https://11ty.github.io/eleventy-base-blog/tags/second-tag/ doesn't mention the current tag in the title.

mathiasbynens commented 6 years ago
title: {{ tag }}

...strangely results in [object Object], despite {{ tag }} showing up as the tag text in the body text, and {{ tag }} expanding as expected in the permalink: frontmatter. Any idea what's up?

zachleat commented 6 years ago

Hmm… I suppose it is a bit unexpected that title: {{ tag }} would not render there. permalink is one of the only front matter keys that does render in the local template engine.

I suppose, technically Eleventy could loop through each front matter variable and attempt to render each value individually. But we’d need to create a dependency graph of front matter variables there, to ensure we rendered in the correct order. That being said, we don’t do any of this right now.

We only render permalink and I think one other undocumented case. We do expose a renderData object in front matter that does render the content inside of it. It was undocumented because I wasn’t really happy about it.

For example, if the tags.njk template had this front matter:

---
pagination:
  data: collections
  size: 1
  alias: tag
layout: layouts/home.njk
renderData:
  title: Tagged “{{ tag }}”
permalink: /tags/{{ tag }}/
---

and the layout title were changed to:

<title>{{ renderData.title or title or metadata.title }}</title>

This works as expected. I will make that change but this will cement renderData forever and now I’m a little sad 😇

I am open to more complicated-behind-the-curtain solutions here, if you have suggestions!

zachleat commented 6 years ago

I think the reason I’m not real happy about renderData is that I’m not even sure if you can use it inside of permalink or vice versa. You get into weird cases where order matters.

mathiasbynens commented 6 years ago

This is now resolved. Thanks! I’m closing the issue.

zachleat commented 4 years ago

Watch for eleventyComputed https://github.com/11ty/eleventy/issues/481 to drop soon in 0.11.0 that will solve all these problems in a much better way.

e.g.

---
pagination:
  data: collections
  size: 1
  alias: tag
layout: layouts/home.njk
eleventyComputed:
  title: Tagged “{{ tag }}”
permalink: "/tags/{{ tag }}/"
---

and

<title>{{ title or metadata.title }}</title>