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.
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.
| Flag | Does |
|---|---|
--drafts | Also render pages and sections marked draft = true. |
--root DIR | The capsule directory, the one with config.toml in it. Defaults to the current directory. |
--content DIR | Content directory, overriding content_dir. |
--output DIR | Output directory, overriding output_dir. |
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"
| Key | Default | Is |
|---|---|---|
base_url | required | The capsule's address. It must start with gemini://. A trailing slash is removed. |
title | empty | The capsule's name. |
description | empty | A line about the capsule. |
author | empty | The feed author. With feeds on and no author, the build warns and the feed says Unknown. |
default_language | en | The feed's language tag. |
content_dir | content | Where the Gemtext files are. |
output_dir | public | Where the built capsule is written. It must be inside the capsule directory; gscg will not delete anything outside it. |
generate_feeds | true | Whether to render the feed. |
feed_filename | feed.xml | The feed's name in the root of the capsule. |
feed_limit | 0 | How many entries to include. 0 means all of them. |
[extra] | empty | Your 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.
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.
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.
Sections and pages are each written as a directory with an index.gmi in
it, so every path ends in a slash.
| Source | Path | Written 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.
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.
| Key | Is |
|---|---|
title | The page's title. Defaults to the slug. |
description | A line about the page. Used as the feed summary. |
date | When the page was published. Sets the feed order and is the key for date sorting. |
updated | When the page was last changed. |
slug | The last part of the page's path. Defaults to the filename. |
path | The page's full path, used instead of the one its file would give it. |
weight | An integer, for sections sorted by weight. Lower comes first. |
draft | Set to true to leave the page out of a build. |
authors | A list of names. The feed uses the first one. |
include_in_feeds | Whether the page is in the feed. Defaults to true. |
[extra] | Your own keys, for your templates to read. |
These keys go in a directory's index.gmi.
| Key | Is |
|---|---|
title | The section's title. Defaults to the directory name. |
description | A line about the section. |
sort_by | How to order the section's pages. See Sorting. |
weight | An integer, for ordering the section among its siblings. |
draft | Set to true to leave the section and everything under it out of a build. |
[extra] | Your own keys, for your templates to read. |
A filename that starts with a date sets both the page's date and its slug, so the front matter only needs a title.
| Filename | Date | Slug |
|---|---|---|
2026-11-30-hello-capsule.gmi | 2026-11-30 | hello-capsule |
2026-11-30.gmi | 2026-11-30 | 2026-11-30 |
notes-on-gemtext.gmi | none | notes-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.
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.
A section's sort_by sets the order of
.Section.Pages.
sort_by | Order |
|---|---|
date | Newest first, by date. |
update_date | Newest first, by updated, falling back to date. |
title | Alphabetical. |
weight | Lowest weight first. |
none | By 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.
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.
A capsule has four templates, and all four are required.
| Template | Renders |
|---|---|
templates/index.gmi | The root section, and nothing else. |
templates/section.gmi | Every other section. |
templates/page.gmi | Every page. |
templates/feed.xml | The 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.
| Template | Variables |
|---|---|
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.
| Variable | Is |
|---|---|
.Title .Description .Content | The title, description and body. |
.Date .Updated | May be unset, so use {{ with }}. |
.Slug .Path .Permalink | .Path starts at the root of the capsule, .Permalink is the full gemini:// URL. |
.Authors | The list from the front matter. |
.Draft .Weight .IncludeInFeeds | As given in the front matter. |
.Lower .Higher | The next older and next newer page in the section, under a date sort. |
.Extra | The page's [extra] table. |
.RelativePath | The source file, relative to the content directory. |
| Variable | Is |
|---|---|
.Title .Description .Content | The title, description and body of its index.gmi. |
.Path .Permalink | The same as a page's. |
.Pages | The section's pages, in its sort order. |
.Subsections | The sections directly below it. |
.Extra | The section's [extra] table. |
.RelativePath | Its index.gmi, relative to the content directory. |
| Function | Does | Example |
|---|---|---|
date | Formats a date as 2026-11-30. | {{ with .Page.Date }}{{ date . }}{{ end }} |
rfc3339 | Formats a date for the feed. | {{ rfc3339 .LastUpdated }} |
xml | Escapes text for the feed. | {{ xml .Config.Title }} |
allPages | Every page in the capsule, newest first. | {{ range allPages }} |
limit | The first n pages of a list. | {{ range limit allPages 5 }} |
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.
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.
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.