x-govuk / govuk-eleventy-plugin

Write documentation using Markdown and publish it using GOV.UK styles.
https://x-govuk.github.io/govuk-eleventy-plugin/
MIT License
55 stars 14 forks source link

Global computed data overrides global data set in consuming app #346

Closed lhokktyn closed 1 week ago

lhokktyn commented 1 month ago

The global data applied for eleventyComputed here ...

eleventyConfig.addGlobalData(
  'eleventyComputed',
  require('./lib/data/eleventy-computed.js')
)

... overrides any data that I set in my consuming app, e.g.

eleventyConfig.addGloblData('eleventyComputed.myGlobalVar', () => (data) => "abc");

I would expect the above to result in;

eleventyComputed: {
  eleventyNavigation: {
    key: (data) => getKey(data),
    parent: (data) => getParent(data),
    excerpt: (data) => data.eleventyNavigation.excerpt || data.description
  },
  myGlobalVar: (data) => "abc",
}

But myGlobalVar is actually not present.

I believe this is a result of the issue described here.

Hacking a change into /main/index.js fixes the issue:

eleventyConfig.addGlobalData(
  'eleventyComputed.eleventyNavigation',
  require('./lib/data/eleventy-computed.js').eleventyNavigation
)

I'll look at submitting a PR for this.