Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Easily generate pages per metadata #15

Closed
MoOx opened this issue Sep 15, 2015 · 19 comments
Closed

Easily generate pages per metadata #15

MoOx opened this issue Sep 15, 2015 · 19 comments
Assignees

Comments

@MoOx
Copy link
Owner

MoOx commented Sep 15, 2015

Eg:

  • tags
  • date (year, year/month...)

with a way to sort / paginate results

@thangngoc89
Copy link
Contributor

Dynamic routing mind help

Add a NotFound route. Don't use * to catch all route.

@MoOx
Copy link
Owner Author

MoOx commented Feb 26, 2016

For this, we will have indeed to really use react-router. But I think * will be a requirement since we don't know (when writing routes) what pages you will have.

@thangngoc89
Copy link
Contributor

We do. After md-collection-loader finishes, we know all the routes available. User web_modules/src/routes.js should be a small slice of routes. Statinamic will control the others

@MoOx
Copy link
Owner Author

MoOx commented Feb 26, 2016

Statinamic will control the others

That's why there is a *.

@thangngoc89
Copy link
Contributor

Yeah. sorry :)

@MoOx
Copy link
Owner Author

MoOx commented Feb 26, 2016

And * is the recommended way to catch all routes (and so not found).
Not found is kind of our PageContainer || PageError.

@thangngoc89
Copy link
Contributor

I'll take a look at this later. Really want a tags system

@MoOx
Copy link
Owner Author

MoOx commented Feb 26, 2016

I will work on it after introducing search in the default boilerplate

The idea is to use routes with names like "tag/:tags", read routes to find ":tags" and generate pages based on all metadata "tags".

Something like that. This way user will be able to control url generations.

@MoOx
Copy link
Owner Author

MoOx commented Feb 26, 2016

It's a requirement for me too :)

@thangngoc89
Copy link
Contributor

Sound easy. Haha. How about I work on search and you work on this. Adding search is much easier.

@MoOx
Copy link
Owner Author

MoOx commented Feb 26, 2016

Let's do this.

@thangngoc89
Copy link
Contributor

I have a upcoming project that needs a static site generator. Tagging system is a requirement so I did a little research for making such a system for Statinamic.

And here is the result : thangngoc89/blog#89
Nothing fancy there. It stills a proof of concept, need a lot of tests and a patch in statinamic core to make it work. I'll walk you through the process:

  • Hook a callback to webpack's compiler done event
  • Get tags list from statinamic/lib/content-loader/cache.js
  • With each tags, push a new object to cache.js
cache.push({
  __url: `/tags/${item}`,
   __resourceUrl: `/tags/${item}/index.html`
})
  • Catch this routes in React Router (tags/:tag)
  • Make a new Component to show posts with current tags in React Router
  • That's it for static build. To make it work for dev mode, I need to make reading dataUrl optional

Wrap these LoC in a condition (check for availability of item.__dataUrl)
https://github.com/MoOx/statinamic/blob/81baba84c5b8a49564ef8b2c82996148bf8f02ed/src/builder/server.js#L155-L165

Probably 404 page will be benefit from this patch too. No need for download data file for such a page.

But there is some issues to solve:

  • How to inject tag data to Tag Component (to be safe, you'll will have to slugify the tag, we need to inject the original tag to the Component since slugify every tag we found is costly and make the js bundle bigger)
  • The Webpack plugin is ugly, we probably need to provide a clean API for this.

@MoOx
Copy link
Owner Author

MoOx commented Mar 19, 2016

I will work on this after 0.9 (I was supposed to but, life and shit...).

I want this to be really simple. A route and a layout/component should be enough. I think we need to use something like redial to have a universal way to fetch data so we can use a component during build or on client runtime (currently for pages, there is 2 pieces of code to get data, one for static and one for client, which kind of sucks).

@thangngoc89
Copy link
Contributor

life and shit...

Don't worry, you're doing a really good job.

A route and a layout/component should be enough

👍 I love simple

@thangngoc89
Copy link
Contributor

async-props is another option. It's from react-router creator. and it uses react-router middleware

@MoOx
Copy link
Owner Author

MoOx commented May 17, 2016

I am on it. Should not take that long and user API will be straight forward (nothing specific, just routes with parameters that match name in the frontmatter and boom, generation).

@MoOx
Copy link
Owner Author

MoOx commented Aug 23, 2016

This is implemented in 0.16 🎉

@MoOx MoOx closed this as completed Aug 23, 2016
@blairanderson
Copy link

@MoOx do you have a link to the source on this? i cannot find documentation

@MoOx
Copy link
Owner Author

MoOx commented Feb 27, 2017

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

No branches or pull requests

3 participants