Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Main ¶
Main serves a single embedded site (templates/, posts/, static/) on the -port flag (default 4321), hot-reloading from the working tree in development. It is shorthand for Serve with one mount.
func Serve ¶
func Serve(mounts ...Mount)
Serve builds a host-routed server over the given mounts and listens on the -port flag (default 4321). The first mount is the fallback for unmatched hosts; each domain also answers on "<label>.localhost". In development (run via `go run`), each mount hot-reloads templates/posts/static from its Dir.
Types ¶
type FeedConfig ¶
type FeedConfig struct {
BaseURL string // absolute site root, e.g. "https://filipsalo.se"
Title string // feed title; defaults to the BaseURL host
Subtitle string // optional one-line description
Author string // author display name, e.g. "Filip Salo"
}
FeedConfig configures the Atom and JSON feeds. Feeds are only served when BaseURL is set, since a feed needs absolute URLs.
type Mount ¶
type Mount struct {
Domain string // canonical hostname, e.g. "infix.se"
FS fs.FS // embedded content: templates/, static/, optional posts/
Dir string // optional on-disk dir for dev hot-reload (e.g. "." or "filipsalo.se")
Aliases []string // optional extra hostnames to answer on
Feed FeedConfig // optional Atom + JSON feeds; defaults BaseURL to "https://<Domain>"
// OGImage, if set, renders a social-card PNG for a page; the site then
// serves it (cached) at "<page path>/og.png". The renderer owns the design.
OGImage func(*Page) ([]byte, error)
}
Mount binds a hostname to a content root for Serve.
type Page ¶
type Page struct {
Path string
Slug string
Title string
Date time.Time
// IsDraft marks a work in progress. Drafts are listed and served only when
// drafts are enabled (in development); in production they're absent from
// listings and 404 on direct access. A draft needs no date — without one it
// gets a preview URL under /drafts/<slug>. Set with `Draft: true`.
IsDraft bool
// IsUnlisted keeps a finished, public post out of listings (the archive
// and the home page's recent posts) while still serving it on direct
// access. Set with `Unlisted: true` in the front matter.
IsUnlisted bool
IsPage bool // a standalone page (from pages/), not a dated post
Template string
Body string
Tags []string
Lang string // BCP 47 language tag, e.g. "en" or "sv"
Summary string // a short (one or two sentence) description
// Aliases are old URLs that should permanently redirect to this page,
// e.g. after a slug change. Each is either a root-relative path
// ("/2006/05/24/old-slug") or a bare slug ("old-slug"), the latter
// resolved against the page's own URL scheme. Set with a comma-separated
// `Aliases:` front-matter field.
Aliases []string
// Styles and Scripts are page-specific assets injected into <head>. A bare
// name (app.css) resolves to the page's own URL — i.e. a file colocated in
// its folder, served at "<page path>/app.css"; a value starting with "/" or
// containing "://" is used verbatim (a shared "/static/..." asset or an
// external URL). Set with comma-separated `Styles:` / `Scripts:` fields.
Styles []string
Scripts []string
// AssetDir is the content-FS directory whose sibling files are served as
// this page's colocated assets, set when the page is a folder with an
// index.md (otherwise ""). Its files are reachable at "<page path>/<file>".
AssetDir string
// Meta holds any front-matter fields that aren't recognized above,
// keyed by their lower-cased name (e.g. {{ .page.Meta.notes }}).
Meta map[string]string
}
Page represents a known web page
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server dispatches requests to per-host Sites based on the request Host header, so several independent sites can share one binary and port.
type Site ¶
type Site struct {
// contains filtered or unexported fields
}
Site represents a website
func (*Site) Handler ¶
Handler returns the site's http.Handler, building (and caching) it on first use so a multi-site server can dispatch without rebuilding the mux on every request.
func (*Site) ListenAndServe ¶
ListenAndServe starts the web server
func (*Site) WithDrafts ¶
WithDrafts controls whether draft posts (those with `Draft: true` in their front matter) are listed and served. It's off by default; Serve and Main turn it on in development, so drafts are visible while running locally but never reachable in production.
func (*Site) WithFeed ¶
func (s *Site) WithFeed(cfg FeedConfig) *Site
WithFeed configures the Atom and JSON feeds. With no BaseURL set, no feeds are served.
func (*Site) WithOGImage ¶
WithOGImage registers a function that renders a social-card PNG for a page. When set, the site serves "<page path>/og.png" by calling it and caching the bytes. The renderer owns the card's look and fonts; gotic only handles the route, the page lookup, and the cache — so card design stays in the site.
func (*Site) WithTmplFuncs ¶
WithTmplFuncs adds template functions