Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include a page's complete frontmatter in its navigation entry #27

Open
noelleleigh opened this issue Feb 14, 2021 · 1 comment · May be fixed by #34
Open

Include a page's complete frontmatter in its navigation entry #27

noelleleigh opened this issue Feb 14, 2021 · 1 comment · May be fixed by #34

Comments

@noelleleigh
Copy link
Contributor

noelleleigh commented Feb 14, 2021

I have a navigation entry named writing, with several child pages. Each child page has one or more tags. To facilitate easy browsing, I want to be able to display the tags of each child page (along with other metadata) when rendering the navigation <ul>.

Example

/writing/moby-dick.md

---
title: &title Moby-Dick
author: Herman Melville
tags:
  - fiction
  - whale
eleventyNavigation:
  key: moby-dick
  title: *title
  parent: writing
---

/writing/a-brief-history-of-time.md

---
title: &title A Brief History of Time
author: Stephen Hawking
tags:
  - non-fiction
  - physics
eleventyNavigation:
  key: a-brief-history-of-time
  title: *title
  parent: writing
---

/writing/index.html (rendered)

<ul>
    <li>
        <a href="/writing/moby-dick" class="title">Moby-Dick</a> by Herman Melville
        <ul>
            <li><a href="collection/fiction" class="tag">#fiction</a></li>
            <li><a href="collection/whale" class="tag">#whale</a></li>
        </ul>
    </li>
    <li>
        <a href="/writing/a-brief-history-of-time" class="title">A Brief History of Time</a> by Stephen Hawking
        <ul>
            <li><a href="collection/non-fiction" class="tag">#non-fiction</a></li>
            <li><a href="collection/physics" class="tag">#physics</a></li>
        </ul>
    </li>
</ul>

See Archive of Our Own for a live example.

But at the moment, page-specific information like tags or author isn't included in the entry returned by eleventyNavigation, making implementing this challenging.

Proposal

Inspired by the collection item data structure, add a field data to the entry returned by eleventyNavigation. This field would contain all data for this piece of content (includes any data inherited from layouts), minus the eleventyNavigation field (to avoid infinite recursion).

With this implemented, the above example could be written as:

/writing/index.njk

{% set navPages = collections.all | eleventyNavigation(eleventyNavigation.key) %}
<ul>
    {%- for entry in navPages %}
    <li>
        <a href="{{ entry.url | url }}">{{ entry.title }}</a> by {{ entry.data.author }}
        <ul>
            {% for tag in entry.data.tags %}
            <li>
                <a href="collection/{{ tag }}">#{{ tag }}</a>
            </li>
            {% endfor %}
        </ul>
    </li>
    {%- endfor %}
</ul>
@noelleleigh
Copy link
Contributor Author

I see this issue was already brought up in #17. It would be great to have an official word on whether this could be considered for inclusion in the library itself.

@noelleleigh noelleleigh linked a pull request Nov 4, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant