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

Global data/metadata: stop the namespace madness somehow #48

Open
lyzadanger opened this issue Feb 23, 2024 · 0 comments
Open

Global data/metadata: stop the namespace madness somehow #48

lyzadanger opened this issue Feb 23, 2024 · 0 comments
Labels
tech debt tech tasks and cleanup

Comments

@lyzadanger
Copy link
Owner

lyzadanger commented Feb 23, 2024

I hold that site data/metadata is a form of content, and as such, I am adamant about maintaining it separately from site implementation. I had previously kept metadata in .yaml and that has been fine with 11ty also, once I extended 11ty to support YAML.

One of the things most people love about 11ty is its data cascade, which makes this global metadata, well, global. But I'd really, really like to namespace the global data to avoid unintentional merges and conflicts. I do not want any of my truly global site metadata to be mutable, and as such, I don't need it merged.

I suppose a use case would be more helpful here.

Currently I have a notion of being able to group content into "series." The series themselves are defined in a metadata file, series.yaml. I do want metadata about the various series-es to be available globally.

To associate a piece of content with a series, what I'd like to be able to do is add a metadata (e.g. front-matter) key to that content, series, that could reference the identifier (slug in my case) of the series in which it should be included. However, I cannot do that because this local series value would merge and overwrite the global series value (array of "series" objects).

What I want in the context of the piece of context's template on render is something like:

{
  global: {
    series: [
      {
        slug: 'my-series-slug',
        title: 'A series of thingies',
        description: 'Some sort of thingy batch',
      },
      // ...
    ],
  },
  series: 'my-series-slug',
  // ...
}

but what I get is:

{
  series: 'my-series-slug',
  // ...
}

Because the local series value obliterates the global one. So I've lamed out and used a local key of inSeries, so that I get:

{
  series: [
    {
      slug: 'my-series-slug',
      title: 'A series of thingies',
      description: 'Some sort of thingy batch',
    },
    // ...
  ],
  inSeries: 'my-series-slug',
  // ...
}

This does not satisfy me, though I understand it's by design. I've ended up with a content metadata key that is named awkwardly as a result of implementation details of eleventy.

11ty keys global metadata by its filename, i.e. series.yaml in my case becomes a top-level series entry in template context. I could rename the file (and as such probably all global data files to establish a convention) with a prefix, e.g. But then I'm renaming my source data files to account for a 11ty implementation detail.

There may be some entirely straightforward way to accomplish this that I just haven't googled onto yet.

@lyzadanger lyzadanger added the tech debt tech tasks and cleanup label Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tech debt tech tasks and cleanup
Projects
None yet
Development

No branches or pull requests

1 participant