gscg

gscg is a static site generator for Gemini capsules. It reads Gemtext files with TOML front matter and renders them with your templates.

gscg was heavily inspired by Zola, the static site generator written in Rust.

Installing

go install git.sr.ht/~blainsmith/gscg@latest

There are two commands.

gscg init [dir]
gscg build [--drafts] [--root DIR] [--content DIR] [--output DIR]

gscg init creates a capsule in dir, or in the current directory if dir is left off. It will not write into a directory that already has a config.toml.

gscg build renders the capsule. It takes four flags.

FlagDoes
--draftsAlso render pages and sections marked draft = true.
--root DIRThe capsule directory, the one with config.toml in it. Defaults to the current directory.
--content DIRContent directory, overriding content_dir.
--output DIROutput directory, overriding output_dir.

Configuration

config.toml goes in the root of the capsule. Only base_url is required.

base_url = "gemini://example.org"
title = "Example Capsule"
description = "Notes and projects."
author = "Your Name"
default_language = "en"
content_dir = "content"
output_dir = "public"

generate_feeds = true
feed_filename = "feed.xml"
feed_limit = 0

[extra]
footer = "Built with gscg"
KeyDefaultIs
base_urlrequiredThe capsule's address. It must start with gemini://. A trailing slash is removed.
titleemptyThe capsule's name.
descriptionemptyA line about the capsule.
authoremptyThe feed author. With feeds on and no author, the build warns and the feed says Unknown.
default_languageenThe feed's language tag.
content_dircontentWhere the Gemtext files are.
output_dirpublicWhere the built capsule is written. It must be inside the capsule directory; gscg will not delete anything outside it.
generate_feedstrueWhether to render the feed.
feed_filenamefeed.xmlThe feed's name in the root of the capsule.
feed_limit0How many entries to include. 0 means all of them.
[extra]emptyYour own keys, for your templates to read.

Note that unknown keys are ignored with a warning, so a misspelt key will not stop the build.

All of these are available to templates as .Config, under their Go names: .Config.BaseURL, .Config.Title, .Config.DefaultLanguage, .Config.FeedLimit, .Config.Extra.footer.

Content

Front matter

Every Gemtext file starts with front matter: a line that is exactly +++, some TOML, then another line that is exactly +++. The rest of the file is the body.

+++
title = "Hello Capsule"
description = "The first post."
+++
The body starts here. It is plain Gemtext.

=> / Home

No key is mandatory, but the opening and closing +++ are required. gscg will not build a .gmi file without them. Unknown keys inside the front matter are ignored with a warning.

Sections and pages

A directory is a section if it has an index.gmi in it. The root of the content directory is always a section, with or without one.

Every other .gmi file in that directory is a page of the section.

content/
  index.gmi                      the root section
  about/
    index.gmi                    a section with no pages
  blog/
    index.gmi                    a section
    2026-11-30-hello.gmi         a page of blog
    2026-12-01-gemtext.gmi       a page of blog

A .gmi file in a directory with no index.gmi is an orphan. It is rendered like any other page, and it shows up in allPages and in the feed, but it has no section. .Section is not set for it, and a section's draft flag and sort_by do not apply. The page template from gscg init shows how to handle this.

Output paths

Sections and pages are each written as a directory with an index.gmi in it, so every path ends in a slash.

SourcePathWritten to
content/blog/index.gmi/blog/public/blog/index.gmi
content/blog/2026-11-30-hello.gmi/blog/hello/public/blog/hello/index.gmi

If two files would be written to the same path, the build fails and names both files.

Assets

Files in the content directory that do not end in .gmi are copied as they are, keeping their path. An image at content/images/logo.png is served at /images/logo.png.

Files that start with a dot are skipped, as are files ending in ~ or .swp and directories whose name starts with a dot.

Page front matter

KeyIs
titleThe page's title. Defaults to the slug.
descriptionA line about the page. Used as the feed summary.
dateWhen the page was published. Sets the feed order and is the key for date sorting.
updatedWhen the page was last changed.
slugThe last part of the page's path. Defaults to the filename.
pathThe page's full path, used instead of the one its file would give it.
weightAn integer, for sections sorted by weight. Lower comes first.
draftSet to true to leave the page out of a build.
authorsA list of names. The feed uses the first one.
include_in_feedsWhether the page is in the feed. Defaults to true.
[extra]Your own keys, for your templates to read.

Section front matter

These keys go in a directory's index.gmi.

KeyIs
titleThe section's title. Defaults to the directory name.
descriptionA line about the section.
sort_byHow to order the section's pages. See Sorting.
weightAn integer, for ordering the section among its siblings.
draftSet to true to leave the section and everything under it out of a build.
[extra]Your own keys, for your templates to read.

Dates and slugs from filenames

A filename that starts with a date sets both the page's date and its slug, so the front matter only needs a title.

FilenameDateSlug
2026-11-30-hello-capsule.gmi2026-11-30hello-capsule
2026-11-30.gmi2026-11-302026-11-30
notes-on-gemtext.gminonenotes-on-gemtext

A date or slug in the front matter takes priority over the filename.

Slugs are lowercased, and any run of characters that is not a letter or a digit becomes one hyphen. Notes on Gemtext! becomes notes-on-gemtext.

How dates are read

A date with no UTC offset is read as UTC. 2026-11-30 is 2026-11-30T00:00:00Z no matter what timezone the build runs in.

date = 2026-11-30                  read as 2026-11-30T00:00:00Z
date = 2026-11-30T09:00:00         read as 2026-11-30T09:00:00Z
date = 2026-11-30T09:00:00-05:00   read as 2026-11-30T14:00:00Z

Add an offset when the time of day matters.

Sorting

A section's sort_by sets the order of .Section.Pages.

sort_byOrder
dateNewest first, by date.
update_dateNewest first, by updated, falling back to date.
titleAlphabetical.
weightLowest weight first.
noneBy filename. This is the default.

With date or update_date, each page also gets .Page.Lower and .Page.Higher, the next older and next newer page in the section. The page template uses these for its previous and next links. The other orders leave them unset.

With date or update_date, a page that has no date is dropped with a warning. It is not listed in the section and it is not rendered. Give it a date, or use a different sort_by.

Subsections are ordered by weight, then by path.

Drafts

Pages and sections marked draft = true are left out of the build unless you pass --drafts.

A draft section also drafts its pages, its subsections and their pages. Orphans have no section above them, so only their own draft flag applies.

Templates

A capsule has four templates, and all four are required.

TemplateRenders
templates/index.gmiThe root section, and nothing else.
templates/section.gmiEvery other section.
templates/page.gmiEvery page.
templates/feed.xmlThe Atom feed.

They are Go text templates. There are no partials and no inheritance, so each template is complete on its own. Reading a variable that does not exist is an error, so a misspelt name will fail the build.

What each template gets

TemplateVariables
page.gmi.Config .Page .Section .CurrentPath
section.gmi, index.gmi.Config .Section .CurrentPath
feed.xml.Config .FeedURL .LastUpdated .Pages .Lang

.CurrentPath is the path being rendered. Use it to mark the current item in a menu.

In page.gmi, .Section is the page's own section. It is not set for orphan pages, so reach it with {{ with .Section }}.

There is no capsule-wide variable. Use allPages to get at pages other than the one being rendered.

Page variables

VariableIs
.Title .Description .ContentThe title, description and body.
.Date .UpdatedMay be unset, so use {{ with }}.
.Slug .Path .Permalink.Path starts at the root of the capsule, .Permalink is the full gemini:// URL.
.AuthorsThe list from the front matter.
.Draft .Weight .IncludeInFeedsAs given in the front matter.
.Lower .HigherThe next older and next newer page in the section, under a date sort.
.ExtraThe page's [extra] table.
.RelativePathThe source file, relative to the content directory.

Section variables

VariableIs
.Title .Description .ContentThe title, description and body of its index.gmi.
.Path .PermalinkThe same as a page's.
.PagesThe section's pages, in its sort order.
.SubsectionsThe sections directly below it.
.ExtraThe section's [extra] table.
.RelativePathIts index.gmi, relative to the content directory.

Functions

FunctionDoesExample
dateFormats a date as 2026-11-30.{{ with .Page.Date }}{{ date . }}{{ end }}
rfc3339Formats a date for the feed.{{ rfc3339 .LastUpdated }}
xmlEscapes text for the feed.{{ xml .Config.Title }}
allPagesEvery page in the capsule, newest first.{{ range allPages }}
limitThe first n pages of a list.{{ range limit allPages 5 }}

Examples

A page template with the date, links to the neighbouring pages, and a link back up:

# {{ .Page.Title }}
{{ with .Page.Date }}{{ date . }}{{ end }}

{{ .Page.Content }}

{{ with .Page.Higher }}=> {{ .Path }} Newer: {{ .Title }}
{{ end -}}
{{ with .Page.Lower }}=> {{ .Path }} Older: {{ .Title }}
{{ end -}}
{{ with .Section }}=> {{ .Path }} Back to {{ .Title }}
{{ else }}=> / Home
{{ end -}}

Note the {{ else }} branch, which covers orphan pages. They have no section to link back to.

A section template that lists its pages:

# {{ .Section.Title }}
{{ with .Section.Content }}
{{ . }}
{{- end }}
{{ if .Section.Pages }}
{{ range .Section.Pages -}}
=> {{ .Path }} {{ with .Date }}{{ date . }} {{ end }}{{ .Title }}
{{ end -}}
{{ end }}
=> / Home

{{- and -}} trim the whitespace on that side of the tag. Gemtext is line based, so use them to control the blank lines in the output.

Feeds

Unless generate_feeds is false, gscg renders templates/feed.xml to feed_filename in the root of the capsule. gscg init writes an Atom feed; edit the template to produce something else.

A page is in the feed if it has a date, is not a draft, and its include_in_feeds is not false.

Entries are ordered newest first by updated, falling back to date.

.LastUpdated is the most recent date in the feed. It is taken before feed_limit is applied.

Deploying

The output is a directory tree of index.gmi files. Serve output_dir with any Gemini server, or upload it to a host that serves Gemini for you.

Every build replaces the whole output directory, so publish the whole tree rather than syncing single files into a live one.