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

Where should the eleventyComputed.js global data file be placed? #1101

Closed
anaurelian opened this issue Apr 15, 2020 · 3 comments
Closed

Where should the eleventyComputed.js global data file be placed? #1101

anaurelian opened this issue Apr 15, 2020 · 3 comments

Comments

@anaurelian
Copy link

Where should the eleventyComputed.js global data file be placed? I have tried many ways, and it does not work:

  • /src/eleventyComputed.js
  • /src/eleventyComputed.11tydata.js
  • /src/_data/eleventyComputed.js
  • /src/_data/eleventyComputed.11tydata.js
module.exports = {
  eleventyComputed: {
    eleventyNavigation: {
      key: data => data.page.url,
      title: data => data.title,
    }
  }
};

I'm using v0.11.0-beta.3. Thank you.

@ThePeach
Copy link

are you overriding any configuration? if so, can you please share.

@anaurelian
Copy link
Author

anaurelian commented Apr 16, 2020

@ThePeach

are you overriding any configuration? if so, can you please share.

  ...

  eleventyConfig.addPlugin(eleventyNavigationPlugin);

  eleventyConfig.setDataDeepMerge(true);

  return {
    dir: {
      input: 'src',
      includes: '_includes',
      data: '_data',
      output: '_site',
    },
    passthroughFileCopy: true,
    htmlTemplateEngine: "njk",
    markdownTemplateEngine: "njk"
  }

I also like to mention that a kb.11tydata.js file with the same content placed in /src/kb/ works.

@anaurelian
Copy link
Author

Sorry, this was kind of a silly mistake from my part, the contents of the _data/eleventyComputed.js file should be:

module.exports = {
  eleventyNavigation: {
    key: data => data.page.url,
    title: data => data.title,
  }
};

This correctly writes to the eleventyComputed.eleventyNavigation object, no need to add eleventyComputed: after module.exports, because the file name is already eleventyComputed.

I was doing it wrong:

module.exports = {
  eleventyComputed: {
    eleventyNavigation: {
      key: data => data.page.url,
      title: data => data.title,
    }
  }
};

This was writing to an eleventyComputed.eleventyComputed.eleventyNavigation object, not to to the eleventyComputed.eleventyNavigation object.

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