static-site-generator

module
v0.0.0-...-7635d6e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2023 License: MIT

README

ssg is yet another static site generator

For a real world usage example see klingtnet/klingtnet.github.io.

Installation

If you've a Go distribution installed then just run:

$ go install github.com/klingtnet/static-site-generator/cmd/ssg@latest

Otherwise you can use one of the pre build binaries from the releases page.

Usage

First you need a configuration file, for all available options refer to example.config.json. Second, and most important, is content. The absolute minimum is a folder containing just an index.md. The folder structure of a more complex page is shown below:

content/
├── about-me.md
├── articles
│   ├── bye.md
│   └── hello.md
├── index.md
├── images
    └── photo.webp
└── notes
    └── index.md
    └── something-else.md
static/
└── assets
    └── base.css

For this example ssg will generate:

  • a navigation menu containing all root pages and first-level subdirectories with markdown files, i.e. [home,about,articles,notes]
  • a list page for the articles directory (since no index.md was present)
  • no list page for notes, instead index.md is assumed to be the list page
  • images is just copied
  • contents from static directory will copied as is
output/
├── about-me.html
├── articles
│   ├── bye.html
│   ├── hello.html
│   └── index.html
├── index.html
└── notes
    ├── index.html
    └── something-else.html
└── assets
    └── base.css

Anything besides the root index.md is optional.

Development

Thanks to Go's excellent profiling support it is very easy to generate a CPU and memory profile. The following commands shows how to do this for a benchmark:

$ go test -cpuprofile cpu.prof -memprofile mem.prof -bench=BenchmarkGenerator ./generator/

Generated profiles can then be analyzed using pprof, e.g. by running go tool pprof -http :9999 cpu.prof. Profiles should be analyzed for any performance optimization to verify if they bring a benefit or not.

Directories

Path Synopsis
cmd
ssg
Package main implements the CLI for ssg, a static site generator.
Package main implements the CLI for ssg, a static site generator.
Package frontmatter provides a parser for page metadata stored in markdown code blocks.
Package frontmatter provides a parser for page metadata stored in markdown code blocks.
Package generator implements the static site generator.
Package generator implements the static site generator.
distribute
Package distribute provides concurrency primitives, like limited distribution of work.
Package distribute provides concurrency primitives, like limited distribution of work.
Package slug provides functions for translating page titles into a representation that is safe to use in URLs.
Package slug provides functions for translating page titles into a representation that is safe to use in URLs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL