Discussion
Loading...

Post

Log in
  • About
  • Code of conduct
  • Privacy
  • About Bonfire
katherine
katherine
@kayserifserif@sunny.garden  ·  activity timestamp 5 days ago

hello eleventy friends — is there a good way to generate pages for separate data files (instead of one single data file)? e.g. i have `item1.json`, `item2.json`, and `item3.json` and i want to produce `item1.html`, `item2.html` and `item3.html` using the same template.

the "create pages from data" help page (https://www.11ty.dev/docs/pages-from-data/) doesn't seem to help with this setup so i'm a little lost digging around here. thank you in advance if anyone has tips!

#11ty #eleventy

Eleventy

Create Pages From Data

A docs page for Eleventy, a simpler static site generator.
  • Copy link
  • Flag this post
  • Block
Saneef H. Ansari
Saneef H. Ansari
@saneef@front-end.social  ·  activity timestamp 5 days ago

@kayserifserif Here is hack to achieve this, https://github.com/saneef/11ty-pages-from-json/blob/main/src/index.11tydata.js

Not quite neat though :D

GitHub

11ty-pages-from-json/src/index.11tydata.js at main · saneef/11ty-pages-from-json

Contribute to saneef/11ty-pages-from-json development by creating an account on GitHub.
  • Copy link
  • Flag this comment
  • Block
Bob Monsour
Bob Monsour
@bobmonsour@indieweb.social  ·  activity timestamp 5 days ago

@saneef @kayserifserif If you did this to combine the data files into a single file, you could then use that file as input to a template that uses pagination that could create a page for each item in the file. https://www.11ty.dev/docs/pagination/#paginate-a-global-or-local-data-file

Eleventy

Pagination

A docs page for Eleventy, a simpler static site generator.
  • Copy link
  • Flag this comment
  • Block
Saneef H. Ansari
Saneef H. Ansari
@saneef@front-end.social  ·  activity timestamp 5 days ago

@bobmonsour @kayserifserif

Yup! I agree with Bob. Ideal way would be to keep all entries in a single JSON (as array) or an YAML file. That is how I do in a couple of websites.

But, here I assume, for some reason they need to be in separate JSON files. ;)

  • Copy link
  • Flag this comment
  • Block

BT Free Social

BT Free is a non-profit organization founded by @ozoned@btfree.social . It's goal is for digital privacy rights, advocacy and consulting. This goal will be attained by hosting open platforms to allow others to seamlessly join the Fediverse on moderated instances or by helping others join the Fediverse.

BT Free Social: About · Code of conduct · Privacy ·
Bonfire social · 1.0.2-alpha.34 no JS en
Automatic federation enabled
Log in
Instance logo
  • Explore
  • About
  • Code of Conduct