go.astrophena.name/site Module
Personal site and a Go package that builds it.
package site
import "go.astrophena.name/site"
Package site builds https://astrophena.name.
Disclaimer
Here be dragons: this package is intended only for building https://astrophena.name and has no backward compatibility.
Directory Structure
Site has the following directories:
build This is where the generated site will be placed by default. pages All content for the site lives inside this directory. HTML and Markdown formats can be used. static Files in this directory will be copied verbatim to the generated site. templates These are the templates that wrap pages. Templates are chosen on a page-by-page basis in the front matter. They must have the '.html' extension.
Page Layout
Each page must be of the supported format (HTML or Markdown) and have JSON front matter in the beginning:
{ "title": "Hello, world!", "template": "layout", "permalink": "/hello-world" }
See Page for all available front matter fields.
Index
- func Build(c *Config) error
- func Serve(ctx context.Context, c *Config, addr string) error
- type Config
- type Logf
- type Page
Functions
func Build
func Build(c *Config) error
Build builds a site based on the provided Config.
func Serve
func Serve(ctx context.Context, c *Config, addr string) error
Serve builds the site and starts serving it on a provided host:port.
Types
type Config
type Config struct { // Title is the title of the site. Title string // Author is the name of the author of the site. Author string // BaseURL is the base URL of the site. BaseURL *url.URL // Src is the directory where to read files from. If empty, uses the current // directory. Src string // Dst is the directory where to write files. If empty, uses the build // directory. Dst string // Logf specifies a logger to use. If nil, log.Printf is used. Logf Logf // Prod determines if the site should be built in a production mode. This // means that drafts are excluded and the base URL is used to derive absolute // URLs from relative ones. Prod bool // contains filtered or unexported fields }
Config represents a build configuration.
type Logf
type Logf func(format string, args ...any)
Logf is a simple printf-like logging function.
type Page
type Page struct { Title string `json:"title"` // title: Page title, required. Summary string `json:"summary"` // summary: Page summary, used in RSS feed, optional. Type string `json:"type"` // type: Used to distinguish different kinds of pages, page by default. Permalink string `json:"permalink"` // permalink: Output path for the page, required. Date *date `json:"date"` // date: Publication date in the 'year-month-day' format, e.g. 2006-01-02, optional. Draft bool `json:"draft"` // draft: Determines whether this page should be not included in production builds, false by default. Template string `json:"template"` // template: Template that should be used for rendering this page, required. ContentOnly bool `json:"content_only"` // content_only: Determines whether this page should be rendered without header and footer, false by default. // contains filtered or unexported fields }
Page represents a site page. The exported fields is the front matter fields.