hydrogenjs / hydrogen

🎈 Hydrogen. Voted (by me) the world's lightest static-site generator built with TypeScript ❤ It uses 🔥 lit-html inspired templating for super duper performant template generation.
https://hydrogen-js.netlify.app/
MIT License
167 stars 9 forks source link

Rebuild Hydrogen from the ground up #58

Open shailen-naidoo opened 4 years ago

shailen-naidoo commented 4 years ago

I want to look into rebuilding Hydrogen for better modularity between the core "services", now that Hydrogen is gaining more and more traction each day, more features and ideas are coming into the pipeline. Making the project more modular can aid its rapid growth.

The main parts of Hydrogen are to:

  1. Fetch page and layout templates
  2. Merge page and layout templates
  3. Execute Data, Head and Routes API
  4. Save output to there corresponding HTML files

The Routes API has the potential to be at the core of Hydrogen due to its low-level nature of dynamically defining routes and selecting a template to pipe the data to. Essentially it would aggregate the data and dispatch to the template generator

hydrogen.routes.js

module.exports = async () => [
  {
    path: '/',
    data: {},
    template: '/templates/homepage.js'
  },
  {
    path: '/docs/creating-a-project',
    data: {},
    template: '/templates/doc.js'
  }
]

Hydrogen generates a structure very similar to the one above internally during the getPages() phase

In theory, if the Routes API gets built out, we can just define a pages structure and read from the structure and give that data to the Routes API in order for Hydrogen to build the routes to HTML