site go.astrophena.name/site Index | Files

package site

import "go.astrophena.name/site"

Package site builds https://astrophena.name.

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

Package Files

site.go

Constants

const (
    // Everything is included.
    Dev = Env("dev")
    // Drafts are excluded. Also the base URL is used to derive absolute URLs from
    // relative ones.
    Prod = Env("prod")
)

Available environments.

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.

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
    // Env is the environment to use when building.
    Env Env
    // 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
}

Config represents a build configuration.

type Env

type Env string

Env is the environment for which site can be built.

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.

Version
v0.0.0-20220924114558-5469dbf9d9ed (latest)
Published
Sep 24, 2022
Platform
linux/amd64
Imports
24 packages (graph)
Last checked
2 months ago

Tools for package owners.