Giter VIP home page Giter VIP logo

hydrogenjs / hydrogen Goto Github PK

View Code? Open in Web Editor NEW
166.0 2.0 9.0 1.45 MB

๐ŸŽˆ 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.

Home Page: https://hydrogen-js.netlify.app/

License: MIT License

JavaScript 9.70% Batchfile 0.09% TypeScript 89.35% Dockerfile 0.62% HTML 0.24%
static-site static-site-generator javascript nodejs lit-html string-literals typescript api data template-engine

hydrogen's Introduction

๐ŸŽˆ Hydrogen

Voted the world's lightest static-site generator built with TypeScript โค It uses ๐Ÿ”ฅ lit-html inspired templating for super duper performant template generation.

BTW Hydrogen is much faster than @11ty/eleventy ๐Ÿ˜œ

Netlify Status Version codecov Downloads/week License

Features

  • โšก Millisecond Builds. With the global average attention span being 8 seconds, why wait seconds for your builds when you can wait milliseconds. Read the SLA.
  • ๐Ÿ”ฅ JavaScript Templates. With ES6 template literals, who needs template engines like pug and handlebars. You now have access to the full-power of a JavaScript.
  • ๐Ÿ”Œ Use External APIs. Plug into your data with remote APIs.
  • ๐Ÿ•ถ Powerful Metadata API. Get the best SEO for your static pages.
  • ๐Ÿ”จ Build Hooks. Customize the build process to fit your needs
  • ๐Ÿ’พ Service Worker friendly. Build powerful offline-first experiences

Quick start

Add Hydrogen CLI to your project

$ npm install hydrogen-cli --save-dev

Create a simple index.js file with below code

const page = ({ title, data, head }) => `
  <!DOCTYPE html>
  <html>
    <head>
      <title>${title}</title>
      ${head}
    </head>
    <body>
      <h2>${data.project}</h2>
      <p>${data.description}</p>
    <body>
  </html>
`;

module.exports = {
  page,
  title: 'Welcome to Hydrogen',
  data: () => ({
    project: 'Hydrogen',
    description: 'Super fast static-site generator'
  }),
  head: ({ data }) => [
    ['meta', { name: 'description', content: data.description }]
  ]
}

Run the below command to generate your template to HTML

$ npx hydrogen generate index.js

The below HTML is outputted to an HTML file with the same name as the source index.html

  <!DOCTYPE html>
  <html>
    <head>
      <title>Welcome to Hydrogen</title>
      <meta name="description" content="Super fast static-site generator" />
    </head>
    <body>
      <h2>Hydrogen</h2>
      <p>Super fast static-site generator</p>
    <body>
  </html>

If you want to see a more advanced setup using Hydrogen, checkout โš™ Advanced Setup

Development

Pull requests are more than welcome :)

  1. Install Docker
  2. Clone repo
  3. All commands are in the package.json file

Docker is optional and if you want to debug the build process refer to ๐Ÿ› Debugging Build Process

Run the below commands:

$ yarn docker:setup # Builds Docker image and create Docker container

$ yarn docker:start # Starts Docker image

$ yarn docker:cli:dev # Runs CLI in dev mode

This will run your changes to the Hydrogen CLI over the Hydrogen documentation

Note: There are pre-commit and pre-push hooks that run tests

Roadmap

V1

  • Debugging - How to debug a Hydrogen build process
  • Project rewrite - To improve modularity
  • Improve documention

hydrogen's People

Contributors

schalkventer avatar shailen-naidoo avatar waydelyle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hydrogen's Issues

Add a template project

Add an sample-project or example folder which someone can view on Github and maybe download, or copy from cloned repo.

Or, for more convenience for a user, add commands to make it locally.

For example:

Setup skeleton project with the .js and public files but all empty. This would create content in the current directory. Let the user make the directory themselves.

npx hydrogen create-skeleton

Setup project using the content examples in README.md. Maybe flesh the examples out more to showcase advanced functionality.
npx hydrogen create-sample

Docs: add explanations

  • Add line for help. npx hydrogen -h or --help
  • Add explicit lines for running the dev server. I am not figuring it out. npx dev ?
  • Offer an alternative server. e.g. provide instructions to navigate to dist directory and start an http server with node.

Docs: Extend installation instructions

Add to install instructions.

Link to the Yarn page which has install instructions on it.

And then a command npm install -g npx to install npx. Or the yarn equivalent if yarn will install npx.

Give both routes for devs - the yarn route and the npm route

Link to actual projects

Once you create a sample hosted site or some developers make some sites, link to them in your README.md as a showcase.

Can I have and HTML and a CSS file separately

Is your feature request related to a problem? Please describe.
I would like to use files separately.
I don't like Single Files Components when I work with a team.
I need the designer and the layout artist work without knowing that we are using hydrogen o whatever framework.

Describe the solution you'd like
I want to import an html file an render it into hydrogen:
Ex:
const pageIndex = fs.readFileSync('./pages/index.html').toString()
const page = ({ data }) => pageIndex // ๐Ÿค” I don't know how to mix with string literals

Additional context
I need file separately because designers and layout artists can works individual without any dependency on each other.

Docs: Restructure and split up documentation

Separate instructions into Installation and Usage sections. I usually have docs/installation.md and docs/usage.md which I link to on Docs section of README.md to keep it light.

You can have configuration of package.json in Installation, website / project layout in a Web Dev or Static Site Development section and move the build commands to a Build or Run section.

Build hooks

The goal of Hydrogen is to be as flexible as possible to all users, I figured the best way to make it even more flexible is to add build hooks which would allow users to do just about anything they can think:

Here are a list of Hooks that I want to expose via a file called hydrogen.hooks.js

exports.beforeDistRemoved = async (ctx) => {
};

exports.afterDistRemoved = async (ctx) => {
};

exports.beforeBuild = async (ctx) => {
};

exports.afterBuild = async (ctx) => {
};

exports.beforeEachPage = async (ctx) => {
};

exports.afterEachPage = async (ctx) => {
};

exports.beforeServiceWorkerGenerated = async (ctx) => {
};

exports.afterServiceWorkerGenerated = async (ctx) => {
};

Rebuild Hydrogen from the ground up

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

Feature: hyperlink between pages

Add instructions (or functionality if it doesn't exist yet) to link in the JS between pages. e.g. How to link to page a.html or b/c.html from within index.html.

jekyll uses a page system for the link function, so you have to just know the path to the .md file in the project and it will figure out the HTML path for you.

Components

const Tooltip = ({ dev }, text) => `
  <tooltip>
    <p>${text}</p>
  </tooltip>
` 
const { Tooltip } = require('./components')

module.exports = {
  Tooltip
}
module.exports = ({ components }) => `
<html>
  <body>
    ${components.Tooltip('Hello World')}
  </body>
</html>
`

Create sample src dir

In sample project, public, create src to contain thejs, css directories.
Or assets.

Footer API

In the docs the header api is commonly used to insert script tags, this is not great, script tags should come last on the page

One working solution is of course to just write script tags into the layout or page template, but an alternative would be to have a footer api, which is exactly the same as the header api, which you can place at the end of your page instead. This would be more in line with the usage in the docs

Include Template Path in hydrogen.routes.js

Is your feature request related to a problem? Please describe.

I really like what hydrogen does. I'm looking to build a simple static site without client side rendering and there just aren't options that will take a list of paths, data, and a template and render it to an HTML file.

Hydrogen is the closest things I've seen, the only thing it lacks is the ability to explicitly define the template to use... instead it falls back to _index.js in the folder of the routes defined in hydrogen.routes.js.

While this solution works, it doesn't allow the user to use two different templates within the same folder of their site structure.

Such as having both /contact and /about.

Describe the solution you'd like
Reading over how getPages.ts works, I believe it should be doable to allow users to explicitly define the template to use.

Something such as would work well:


  {
    path: "/blogs/setting-up-a-service-worker",
    data: {
      post: 2
    }
   template: "/path/to/template/"
  }

This would allow the user to define their entire site in the hydrogen.routes.js file and then just worry about templates.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.