Avatar Ilya Mateyko

go.astrophena.name/site Module

GitHub repository | Commit (d2ffa3a)

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

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 logger.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
	// SkipFeed determines if the feed for site shouldn't be built.
	SkipFeed bool
	// Vanity determines if the site is vanity import domain built with vanity
	// package. If so, navigation links created with navLink will point to URLs
	// derived from PrimaryURL instead of BaseURL.
	Vanity bool
	// PrimaryURL is the base URL for navigation links when Vanity set to true.
	PrimaryURL *url.URL
	// contains filtered or unexported fields
}

Config represents a build configuration.

type Page

type Page struct {
	Title       string            `json:"title"`                  // title: Page title, required.
	Permalink   string            `json:"permalink"`              // permalink: Output path for the page, required.
	Template    string            `json:"template"`               // template: Template that should be used for rendering this page, required.
	ContentOnly bool              `json:"content_only,omitempty"` // content_only: Determines whether this page should be rendered without header and footer, false by default.
	Date        *date             `json:"date,omitempty"`         // date: Publication date in the 'year-month-day' format, e.g. 2006-01-02, optional.
	Draft       bool              `json:"draft,omitempty"`        // draft: Determines whether this page should be not included in production builds, false by default.
	MetaTags    map[string]string `json:"meta_tags,omitempty"`    // meta_tags: Determines additional HTML meta tags that will be added to this page, optional.
	Summary     string            `json:"summary,omitempty"`      // summary: Page summary, used in RSS feed, optional.
	Type        string            `json:"type,omitempty"`         // type: Used to distinguish different kinds of pages, page by default.
	CSS         []string          `json:"css,omitempty"`          // css: Additional CSS files that should be loaded, optional.
	JS          []string          `json:"js,omitempty"`           // js: Additional JavaScript files that should be loaded, optional.
	// contains filtered or unexported fields
}

Page represents a site page. The exported fields is the front matter fields.

Directories

vanity Package vanity builds https://go.astrophena.name.