Giter Club home page Giter Club logo

staticgen's Introduction

Staticgen

A static website generator that lets you use HTTP servers and frameworks you already know. Just tell Staticgen how to start your server, then watch it crawl your site and generate a static version with all of the pages and assets required.

About

If you're unfamiliar, you can actually use the decades-old wget command to output a static website from a dynamic one, this project is purpose-built for the same idea, letting your team to use whatever HTTP servers and frameworks you're already familiar with, in any language.

I haven't done any scientific benchmarks or comparisons yet, but here are some results on my 2014 8-core MBP:

Installation

Via gobinaries.com:

$ curl -sf https://gobinaries.com/tj/staticgen/cmd/staticgen | sh

Configuration

Configuration is stored within a ./static.json file in your project's root directory. The following options are available:

  • command — The server command executed before crawling.
  • url — The target website to crawl. Defaults to "http://127.0.0.1:3000".
  • dir — The static website output directory. Defaults to "build".
  • pages — A list of paths added to crawl, typically including unlinked pages such as landing pages. Defaults to [].
  • concurrency — The number of concurrent pages to crawl. Defaults to 30.

Guide

First create the ./static.json configuration file, for example here's the config for Go server, the only required property is command:

{
  "command": "go run main.go",
  "concurrency": 50,
  "dir": "dist"
}

Below is an example of a Node.js server, note that NODE_ENV is assigned to production so that optimizations such as Express template caches are used to improve serving performance.

{
  "command": "NODE_ENV=production node server.js"
}

Run the staticgen command to start the pre-rendering process:

$ staticgen

Staticgen executes the command you provided, waits for the server to become available on the url configured. The pages and assets are copied to the dir configured and then your server is shut down.

By default the timeout for the generation process is 15 minutes, depending on your situation you may want to increase or decrease this with the -t, --timeout flag, here are some examples:

$ staticgen -t 30s
$ staticgen -t 15m
$ staticgen -t 1h

When launching the command, Staticgen sets the STATICGEN environment variable to 1, allowing you to alter behaviour if necessary.

To view the pre-rendered site run the following command to start a static file server and open the browser:

$ staticgen serve

See the examples directory for full examples.

Notes

Staticgen does not pre-render using a headless browser, this makes it faster, however it means that you cannot rely on client-side JavaScript manipulating the page.


GoDoc

Sponsors

This project is sponsored by CTO.ai, making it easy for development teams to create and share workflow automations without leaving the command line.

And my GitHub sponsors:

staticgen's People

Contributors

maxchehab avatar nickhudkins avatar tj 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  avatar  avatar  avatar  avatar  avatar

staticgen's Issues

Resource URL rewriting

I use imgix for all of my images, so it'd be nice to just replace those when compiling for production

Validate fragments

I had a few which were broken, might be nice as a separate tool though

error saving error=context canceled

Prerequisites

  • I searched to see if the issue already exists.

Description

When attempting to use staticgen against a live site, it runs for some time and then I get this:

 ERROR[0008] error saving              error=context canceled url=https://mydomain/somepath/file.pdf
 ERROR[0008] error saving              error=context canceled url=https://mydomain/somepath/other-file.pdf
 FATAL[0008] error: crawling: &{%!w(string=stopping: &{%!w(string=getting process group id: %!w(syscall.Errno=3))})}

  INFO[0008] Stopping server, sending SIGTERM

Note the domain is obfuscated here and below. I'll DM the real domain in slack.

Steps to Reproduce

Use this static.json

{
  "command": "true",
  "url": "https://mydomain/"
}

Then run staticgen

Not able to install

I'm on ChromeOS, I follow the install instructions:

$ curl -sf https://gobinaries.com/tj/staticgen/cmd/staticgen | sh

\x1b[38;5;61m  ==>\x1b[0;00m Downloading github.com/tj/staticgen/cmd/staticgen@master
\x1b[38;5;61m  ==>\x1b[0;00m Resolved version master to v1.0.1
\x1b[38;5;61m  ==>\x1b[0;00m Downloading binary for linux amd64
\x1b[38;5;61m  ==>\x1b[0;00m Installing staticgen to /usr/local/bin
install: cannot change permissions of ‘/usr/local/bin’: Operation not permitted

Alternatively, could there be a way to execute staticgen without installing it? the curl | sh command could execute the binary instead of installing it.

Minify CSS

Add option to minify CSS output, right now you have to do this yourself after performing the build.

Usage in CI tools

This may be a dumb question, but is it possible to use staticgen to build sites within CI (continuous integration) tools, such as Netlify builds and/or Github Actions? It's non-obvious to me since it requires the site be to be accessible via a URL.

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.