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

Page indexes #47

Closed
KyleAMathews opened this issue Sep 25, 2015 · 8 comments
Closed

Page indexes #47

KyleAMathews opened this issue Sep 25, 2015 · 8 comments

Comments

@KyleAMathews
Copy link
Contributor

Frequently when creating a site you'll want to reference pages elsewhere e.g. on index pages or menu sections.

To simplify this, it'd be nice if you could create ad-hoc page indexes something like:

const blogIndex = createIndex('/blog/*.md', {sort: (page) => page.meta.date})

// Now on an index page.
latestBlogPosts = blogIndex({first: 10})

// Render links...
@MoOx
Copy link

MoOx commented Sep 28, 2015

I handled this in statinamic by creating a collection.json in the webpack loader that consume md.

I also provide a simple helper to play with the collection.

@KyleAMathews
Copy link
Contributor Author

The page index json could be written out to file as a custom module. The createIndex call could be rewritten by a babel plugin perhaps to be a require call to the custom module e.g. createIndex() becomes require('indices/a12'). If this sounds crazy and you're curious I'll clarify :)

@andreypopp
Copy link

You might be interested in Query API for sitegen which does similar thing: https://sitegen.github.io/api

It doesn't implement chunked indices yet though so all metadata is always in the main chunk (which can be an overhead for super large sites > 1000 pages or something).

@KyleAMathews
Copy link
Contributor Author

👍 yeah, that's pretty much what I'm thinking for v1 of this. v2 where I'm writing out custom modules w/ metadata could be a later optimization.

@andreypopp
Copy link

Also note that passing a function for sorting is not a great API for that purpose, I think, cause that function should be evaluated during build at webpack context (so it can sort and then chunk results).

The API should be static enough, for example using query string:

let index = createIndex('./posts/*.md?sort-by=published_date&chunk-by=50')

@KyleAMathews
Copy link
Contributor Author

Not 100% sure now this is needed. It's been simple enough to either filter/sort pages or to put index information in config files. Closing for now but if someone has strong thoughts on this, we can reopen it in the future.

@MoOx
Copy link

MoOx commented Feb 26, 2016

For people which are interested, statinamic will handle that and more by adding a way to generate pages based on some metadata filters (eg: pages per categories, year, tags etc)

MoOx/phenomic#15

@KyleAMathews
Copy link
Contributor Author

@MoOx a utility module for pagination (filter then sort then paginate) would be a nice project that could be shared across projects. It'd definitely be nice for Gatsby sites. I closed this issue as it's not something that'll be handled natively in core. Instead components will declare themselves as multi-page components as described in #33 (comment) and handle pagination there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants