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

Directory Data File in Top Level Input Directory is not parsed #935

Closed
zachleat opened this issue Feb 14, 2020 · 4 comments
Closed

Directory Data File in Top Level Input Directory is not parsed #935

zachleat opened this issue Feb 14, 2020 · 4 comments

Comments

@zachleat
Copy link
Member

Say I am using eleventy --input=docs and have a docs/docs.11tydata.js data file. Currently this file is not included in the data cascade. While this is very much related to #245, to me this is more of a bug.

#245 handles the use case when the folder for data file naming is out of the project scope (and may be different from project to project clone). This issue is specific to an explicit input directory.

@zachleat
Copy link
Member Author

Looking through the documentation I don’t think we need to change anything here. To me https://www.11ty.dev/docs/data-template-dir/ already suggests this behavior even though it leaves off variations based on --input for brevity.

@zachleat
Copy link
Member Author

If anyone finds instances of things that do need changes, let me know!

@mvolkmann
Copy link

Maybe you are correct, but I think there are two issues to consider.

The first issue is efficiency in building a site. If a site is using pagination to display 10 items per page that are obtained from a REST service that returns 200 items, the REST service will be invoked 20 times every time the site is built UNLESS that data source is global.

The second issues is the possibility that one of those REST calls might return different data because data was added to or deleted from a database that the REST service queries while the site was being built. That could result in publishing an inconsistent site.

I can imagine not wanting to make the data global because it is only used by a subset of the site.

@paulshryock
Copy link
Contributor

paulshryock commented Mar 10, 2020

The first issue is efficiency in building a site. If a site is using pagination to display 10 items per page that are obtained from a REST service that returns 200 items, the REST service will be invoked 20 times every time the site is built UNLESS that data source is global.

The second issues is the possibility that one of those REST calls might return different data because data was added to or deleted from a database that the REST service queries while the site was being built. That could result in publishing an inconsistent site.

@mvolkmann, grab the API data once in .eleventy.js and assign it to an Eleventy collection, which can then be used multiple times in layouts and templates:

function getEndpoint = function(options) {
  // Call an endpoint and return a response
}

const host = 'https://example.com'

module.exports = function (eleventyConfig) {
  eleventyConfig.addCollection('articles', async collection => {
    const response = await getEndpoint({ url: host + '/api/articles' })
    return response.data
  })
}

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

3 participants