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

Expose page's frontmatter data to transformers #2965

Open
elmuerte opened this issue Jun 16, 2023 · 1 comment
Open

Expose page's frontmatter data to transformers #2965

elmuerte opened this issue Jun 16, 2023 · 1 comment

Comments

@elmuerte
Copy link

Is your feature request related to a problem? Please describe.

With #1522 this.page was added for transformers. However this page data does not contain any of the front matter data.

{
  date: 2023-06-12T17:44:18.978Z,
  inputPath: './src/content/404.html',
  fileSlug: '404',
  filePathStem: '/404',
  outputFileExtension: 'html',
  templateSyntax: 'liquid',
  url: '/404.html',
  outputPath: 'dist/404.html'
}

If the frontmatter data was included it would allow pages to inform transformers to take certain actions.

Describe the solution you'd like

I would like to see the page object to also contain the front matter data

{
  date: 2023-06-12T17:44:18.978Z,
  inputPath: './src/content/404.html',
  fileSlug: '404',
  filePathStem: '/404',
  outputFileExtension: 'html',
  templateSyntax: 'liquid',
  url: '/404.html',
  outputPath: 'dist/404.html',
  data {
    title: '404 page',
    myCustomerFrontMatterElement: ['foo', 'bar']
  }
}

In case the frontmatter was:

---
title: 404 page
myCustomerFrontMatterElement:
  - foo
  - bar
---

### Describe alternatives you've considered

_No response_

### Additional context

_No response_
@mofosyne
Copy link

mofosyne commented Mar 1, 2024

Adding my voice here. I was adding a custom location to a post front matter for https://github.com/mofosyne/call-to-action-map-static-site

location:
  address: 1 barrack st, masslen, IL USA
  latitude: -45.862
  longitude: 24.7844
  name: 'Top NEP Engineering Products'
  description: 'Venue for neptunia fans gathering'

and while it works when doing pagenation, I was unable to directly access it via what I was expecting to be {{page.data.location | json}}


For now, figured out a workaround

  {% comment %} Workaround for https://github.com/11ty/eleventy/issues/2965 {% endcomment %}
  {%- for post in collections.posts -%}
    {% if page.url == post.url and post.data.location %}
      <div class="post-location">
        <h2>Location</h2>
        <i>lat:{{post.data.location.latitude}}, long:{{post.data.location.longitude}}</i>
        </br>
        <strong>{{post.data.location.name}}</strong>
      {%- if post.data.location.description %}
        </br>
        {{post.data.location.description}}
      {%- endif %}
      {%- if post.data.location.address %}
        </br>
        <a target="_new" href="https://www.openstreetmap.org/?mlat={{post.data.location.latitude}}&mlon={{post.data.location.longitude}}">{{post.data.location.address}}</a>
      {%- endif %}
      </div>
    {% endif %}
  {%- endfor -%}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants