gohugoio/hugo

Ability to create pages dynamically?

gkostyanikov opened this issue ยท 22 comments

Using this feature provided by Middleman http://middlemanapp.com/dynamic-pages/ quite often. So maybe somebody will point me to the machinery of doing similar stuff in Hugo or consider adding this feature in future releases?


Edit: New link at https://middlemanapp.com/basics/dynamic-pages/

I think I understand the feature, but not the use case. What do you use it for?

Best,
Steve

-- 
Steve Francia
http://stevefrancia.com
http://spf13.com
http://twitter.com/spf13

On November 25, 2013 at 6:35:47 AM, gkostyanikov (notifications@github.com) wrote:

Using this feature provided by Middleman http://middlemanapp.com/dynamic-pages/ quite often. So maybe somebody will point me to the machinery of doing similar stuff in Hugo or consider adding this feature in future releases?

โ€”
Reply to this email directly or view it on GitHub.

I'm using it for generating tens of thousands pages when most of the data comes from db.

I also need to fill static pages with data from a db (large tables mostly) so I began to hack on that part on my fork here.

My main problem with the approach I chose is that the data formats and queries are hardcoded in hugolib/db.go. So to use this an enduser would have to maintain a fork of hugo.

Simple query strings could go into the frontmatter but what bugs me more is that I don't know how to construct the types for the returned rows to scan into at runtime. I'm not sure it's possible at all because of go's static typing but maybe there is some kind of dark reflection magic i'm not aware of, yet? Another option would be to boil every column down to a string but than you would loose a lot of options (like using .Format on time.Time objects)..

See how we parse config and front matter data from json, toml & yaml. It should provide a good example of reflection.

+1. This would be an amazing feature.

Here is an implementation of one solution on a per page basis:

http://cyrillschumacher.com/2014/12/21/dynamic-pages-with-gohugo.io/

I need some more tipps from the hugo core team to create hugo idiomatic code.

I really like this idea of an approach.

bep commented

+1 Very, very nice. Esp. the remote feature. One concern to think about here is maybe add some kind of cache ... I would hate for my livereload to have to wait for hundreds of remote resources to finish.

Update: @SchumacherFM has submitted a wonderful Pull Request #748: "Feature: GetJson and GetJson in short codes or other layout files" as a solution to this issue.

bep commented

We now have both Data Files and Data driven content -- this is as dynamic as one would get for a static site.

Hi guys,
I'm trying to generate a list of book description pages from a json that contains a list of them, i.e:

[
  { "title", "book A", "description": "description A"},
  { "title", "book B", "description": "description B"},
  { "title", "book C", "description": "description C"}
] 

I would like to get 3 pages with details of given book (generated using same layout). Is that possible?

bep commented

@lukasz-kaniowski not with Hugo alone ...

@bep any recommendations? I'm creating this json file using node scrapper so I can change the sctructure, i.e. devide it into single json file per book. will this help?

bep commented

@lukasz-kaniowski no, you would need to create a script outside Hugo to generate the content pages.

@bep bummer. thanks for your help.

Here is your solution:

http://cyrillschumacher.com/2015/02/09/virtual-pages-with-gohugo.io/

I never made a PR with this feature. It needs more love => Refactoring and hooking into other internal hugo stuff ...

Edit: Source => SchumacherFM@0f32b37

@SchumacherFM nice one. i will have a go with it.

Good luck.

kpym commented

Why is this issue closed ? Is it because there is no hope to see pages generated for each record in a data set ? Or is it because this was implemented in some way since 2015 ?

If this was not done already I want to advocate for this feature.

@bep @spf13
Could you confirm for clarity please:

There is no way to generate dynamic page currently in Hugo out of the box and it will not be implemented?

Details:
Perfect example of dynamic page will be https://middlemanapp.com/basics/dynamic-pages/ as pointed by @gkostyanikov
There is one workaround mentioned here: https://cyrillschumacher.com/2015/02/09/virtual-pages-with-gohugo.io/ by @SchumacherFM (thanks @SchumacherFM ), but this solution does not include adding any dynamic data to the Front Matter ( @SchumacherFM please correct me if I am wrong).
Basically, what I want is to generate dynamic pages using data from remote JSON API or any other datasource / I can generate static json files as well, but to be able fully control generated pages like url, title, taxonomies or any data parameters which should be rendered as part of the content.

It will be very useful for me if you clarify that.

THANKS

So this thing has been bugging me for a while now (especially as I wanted to make it easier for contributors on my website to add content without manually creating folders & files).
So I wrote a temporary solution: kidsil/hugo-data-to-pages

It's a JS wrapper that generates pages from data (and it cleans after itself!).
I'm currently using this to generate pages from YAML files and it seems to be working perfectly.
Would definitely appreciate some feedback.

Cheers

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.