Home
Softono

Gozer

Open source MIT Go
76
Stars
5
Forks
3
Issues
4
Watchers
2 months
Last Commit

 About Gozer

Fast, opinionated and simple static site generator in a single static binary.

Platforms

Web Self-hosted

Languages

Go

Links

Need Help Installing Gozer?

We provide expert installation service for this software. Our team will install, configure, and secure Gozer on your server. plans start at just $30.

Gozer

Gozer is a fast & simple static site generator written in Golang.

  • Converts Markdown and djot to HTML.
  • Allows you to use page-specific templates.
  • Creates an XML sitemap for search engines.
  • Creates an RSS feed for feed readers.

The example directory contains a barebones example of a Gozer site.

Installation

You can install Gozer by first installing a Go compiler and then running:

go install github.com/dannyvankooten/gozer

Usage

Run gozer new to quickly generate an empty directory structure.

├── config.toml                # Configuration file
├── content                    # Posts and pages
│   └── index.md
├── public                     # Static files
└── templates                  # Template files
    └── default.html

Then, run gozer build to generate your site.

Any Markdown files placed in your content/ directory will result in an HTML page in your build directory after running gozer build.

For example:

  • content/index.md creates a file build/index.html so it is accessible over HTTP at /
  • content/about.md creates a file build/about/index.html so it is accessible over HTTP at /about/.

Commands

Run gozer without any arguments to view the help text.

Gozer - a fast & simple static site generator

Usage: gozer [OPTIONS] <COMMAND>

Commands:
    build   Deletes the output directory if there is one and builds the site
    serve   Builds the site and starts an HTTP server on http://localhost:8080
    watch   Builds the site and watches for file changes
    new     Creates a new site structure in the given directory

Options:
    -r, --root <ROOT> Directory to use as root of project (default: .)
    -c, --config <CONFIG> Path to configuration file (default: config.toml)
        --listen <INTERFACE:PORT> Interface to listen on; only used with 'serve',
                 'INTERFACE' is optional. e.g. '--listen :9000 serve'

Content files

Each file in your content/ directory should end in .md or .dj and have TOML front matter specifying the page title:

+++
title = "My page title"
+++

Page content here.

djot note djot has not settled on a syntax for front matter. Until issue #35 is resolved, TOML front matter in djot documents are used.

Templates

The default template for every page is default.html. You can override it by setting the template variable in your front matter.

+++
title = "My page title"
template = "special-page.html"
+++

Page content here.

Templates are powered by Go's standard html/template package, so you can use all the actions described here.

Every template receives the following set of variables:

Pages       # Slice of all pages in the site
Posts       # Slice of all posts in the site (any page with a date in the filename)
Site        # Global site properties: Url, Title
Meta        # All keys from config.toml (for example: title, url, custom fields)
Page        # The current page: Title, Permalink, UrlPath, DatePublished, DateModified, Meta
Title       # The current page title, shorthand for Page.Title
Content     # The current page's HTML content.
Now         # Timestamp of build, instance of time.Time

Meta contains all keys from your config.toml. Front matter keys are available on Page.Meta.

<meta name="description" content="{{ index .Meta "description" }}">

{{ if index .Page.Meta "draft" }}
    <p>This page is still a draft.</p>
{{ end }}

The Page variable is an instance of the object below:

type Page struct {
    // Title of this page
    Title         string

    // Template this page uses for rendering. Defaults to "default.html".
    Template      string

    // Time this page was published (parsed from file name).
    DatePublished time.Time

    // Time this page was last modified on the filesystem.
    DateModified  time.Time

    // The full URL to this page, including the site URL.
    Permalink     string

    // URL path for this page, relative to site URL
    UrlPath       string

    // Path to source file for this page, relative to content root
    Filepath      string

    // Parsed front matter values, keyed by TOML key
    Meta          map[string]any

    // Deprecated: use Meta.
    Attrs         map[string]any
}

To show a list of the 5 most recent posts:

{{ range (slice .Posts 0 5) }}
    <a >{{ .Title }}</a> <small>{{ .DatePublished.Format "Jan 02, 2006" }}</small><br />
{{ end }}

Contributing

Gozer development happens on GitHub.

License

Gozer is open-sourced under the MIT license.