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

Generate pages on the fly from data #159

Open
dagostinelli opened this issue Feb 20, 2018 · 9 comments
Open

Generate pages on the fly from data #159

dagostinelli opened this issue Feb 20, 2018 · 9 comments

Comments

@dagostinelli
Copy link

Current State
Put HTML and markdown into .html files stored in /pages and you get a url per page:

/pages
..../home.html
..../contactus.html
..../info1.html
/layouts
..../default.html
/data
....<empty>

$ foundation build

// resulting URLs
http://example.com/home.html
http://example.com/contactus.html
http://example.com/info1.html

Requested Capability
Put HTML and markdown into a hierarchical JSON doc get a url per page:

/pages
..../empty
/layouts
..../default.html
/data
....pages.json (this is a 10MB JSON file with a record per page)

$ foundation build

// resulting URLs
http://example.com/home.html
http://example.com/contactus.html
http://example.com/info1.html

I have a use-case for this. My project has a SQL database and we'd like to create a static, read-only site where there is 1 page per record. I can write a program to create the json file from the database and I can also generate a whole bunch of /pages/.html files from the database. In current state, I will have to generate a whole bunch of /pages/.html files.

Potential API:
The root parameter can take a directory for physical .html files and/or a hierarchical JSON doc.

var jsonDocOfPagesData = <generate a hierarchical json doc, records for pages and directories>

/// ...

.pipe(panini({
  root: ['src/pages/', jsonDocOfPagesData],
  layouts: 'src/layouts/',
  partials: 'src/partials/',
  data: 'src/data/',
  helpers: 'src/helpers/'
}))
@gakimball
Copy link
Contributor

I have ideas for the API for this, but they aren't finalized.

What I currently have in the v2 alpha of Panini is the ability to convert any kind of file into a page. You write a function that takes in files matching a pattern like /blog-posts/*.md, and each file can be converted into a page.

What I don't have is the ability to turn any arbitrary data source into a page. In your example, you're converting a single file, a JSON file, into multiple pages.

@dagostinelli
Copy link
Author

In another variation, perhaps the output can be like this where each file under plant_records is a single record turned into a file.

/dist
..../home.html
..../contactus.html
..../plant_records
..../plant_records/24.html
..../plant_records/25.html
..../plant_records/26.html
..../plant_records/27.html
..../plant_records/28.html
..../plant_records/29.html

@w-biggs
Copy link

w-biggs commented Mar 25, 2019

I'm interested in this as well. If I have a JSON array, and I want to generate a page for each item in the array, where that item is passed into that page as data, there doesn't seem to be a way to do that currently.

@lendlsmith
Copy link

@gakimball can you post a copy of this function please. Currently i am only getting it to work if i put the file name but not if i use /*.md

@TD540
Copy link

TD540 commented Aug 26, 2019

@w-biggs @dagostinelli
Anyone found a good solution to this? I'm looking for the same thing :)

@erutan
Copy link

erutan commented Apr 26, 2020

Also looking for /*.md functionality.

@dagostinelli
Copy link
Author

@TD540 @w-biggs @erutan I ended up writing my own. I called it spoonbill

https://github.com/dagostinelli/spoonbill

It doesn't use Foundation per-se. You can actually use anything you want with it. Foundation included.

Basically, I replaced Panini with a Makefile and a python script that can take any-old .md file and spit out HTML. Ask me about it over at the spoon bill repository if you want to see examples of how to use it.

Though simple, Spoonbill and it's Makefile together are actually very powerful.

@dagostinelli
Copy link
Author

dagostinelli commented Apr 27, 2020

Oh, and to do the data.json -> .md conversion, I used another python script to do that. It is custom made for the web sites (can't really share it) But you can imagine how it might work.

data.json -> convert.py -> tons of .md files

/src
..../home.md
..../contactus.md
..../plant_records
..../plant_records/24.md
..../plant_records/25.md
..../plant_records/26.md
..../plant_records/27.md
..../plant_records/28.md
..../plant_records/29.md

Then I used spoonbill to convert the .md files into .html files (via the makefile)

/dist
..../home.html
..../contactus.html
..../plant_records
..../plant_records/24.html
..../plant_records/25.html
..../plant_records/26.html
..../plant_records/27.html
..../plant_records/28.html
..../plant_records/29.html

Works fast and does a great job.

@erutan
Copy link

erutan commented Apr 27, 2020

There’s plenty proper static site generators out there - I just use this occasionally for the speed / simplicity. :)

Someone else was inputting content, and markdown preview didn’t want to show up on their editor due to the file extension. I ended up just telling it to treat all .html extensions as markdown.

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

7 participants