build

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2026 License: Unlicense Imports: 22 Imported by: 0

Documentation

Overview

Package build implements the static site build step that renders markdown content files into complete HTML pages.

Index

Constants

This section is empty.

Variables

View Source
var Command = &cli.Command{
	Name:   "build",
	Usage:  "Render a content directory to a static HTML site",
	Action: buildAction,
	Flags: append([]cli.Flag{
		&cli.StringFlag{
			Name:        "input",
			Aliases:     []string{"i"},
			Usage:       "Path to the input directory",
			Required:    true,
			Destination: &buildOpts.contentDir,
		},
		&cli.StringFlag{
			Name:        "pub",
			Aliases:     []string{"p"},
			Usage:       "Path to the output pub directory",
			Required:    true,
			Destination: &buildOpts.pubDir,
		},
		&cli.StringFlag{
			Name:        "assets",
			Aliases:     []string{"a"},
			Usage:       "Path to static assets directory (CSS, JS); embedded defaults used if not set",
			Destination: &buildOpts.assetsDir,
		},
		&cli.StringFlag{
			Name:        "base-url",
			Usage:       "Base URL of the site (e.g. https://example.com) used to build absolute URLs in sitemap.xml; sitemap is omitted if not set",
			Destination: &buildOpts.baseURL,
		},
		&cli.BoolFlag{
			Name:        "include-drafts",
			Usage:       "Include pages marked draft: true in the output",
			Destination: &buildOpts.includeDrafts,
		},
		&cli.BoolFlag{
			Name:        "include-private",
			Usage:       "Include body content of pages marked private: yes in the output",
			Destination: &buildOpts.includePrivate,
		},
		&cli.BoolFlag{
			Name:        "debug",
			Usage:       "Add a debug footer to every rendered page",
			Destination: &buildOpts.debug,
		},
	}, logging.Flags...),
}

Functions

func SelectFeatureImage

func SelectFeatureImage(fm FrontMatter, imageDir string) string

SelectFeatureImage returns the URL of the best available feature image for a page, based on its front-matter metadata and the images available in imageDir (the filesystem directory to check for file existence, typically the "images/" subdirectory of the content root).

Returns empty string when no suitable image is found.

Selection cascade (highest to lowest priority):

  1. fm.Image is set → return it directly (person-specific photo from gen)
  2. Layout/section-specific image: diary, search, list* pages each have a dedicated image name
  3. Place category: select by placetype (city, town, village, hamlet, parish) with fallback to generic place image
  4. Citation/source category: use category-sources image
  5. Person category: progressive fallback from most-specific to least: person-{gender}-{era}-{trade}-{maturity}.webp → person-{gender}.webp
  6. Default: default-oak.webp

Types

type Builder

type Builder struct {
	ContentDir string
	PubDir     string
	// AssetsDir, if non-empty, is a directory of static assets (css/, js/)
	// to copy into PubDir. When empty the assets embedded in the binary are used.
	AssetsDir string
	// Debug, when true, adds a debug footer to every rendered page.
	Debug bool
	// BaseURL, if non-empty, is the scheme+host used to build absolute <loc>
	// URLs in sitemap.xml (e.g. "https://example.com"). When empty, no
	// sitemap.xml is written.
	BaseURL string
	// IncludeDrafts, when true, publishes pages with draft: true in their
	// front-matter instead of skipping them.
	IncludeDrafts bool
	// IncludePrivate, when true, renders the full body of pages with
	// private: yes in their front-matter. When false, the body is hidden
	// and a placeholder message is shown instead.
	IncludePrivate bool
	// contains filtered or unexported fields
}

Builder walks a content directory and renders each file into a pub directory.

func (*Builder) Build

func (b *Builder) Build() error

Build walks ContentDir and processes every file into PubDir. Markdown files are parsed, rendered through goldmark, and written through a layout template. All other files are copied verbatim. Static assets (CSS, JS) are written from the embedded binary assets or from AssetsDir if set.

Build uses a two-pass strategy: the first pass collects child pages for every section so that section index files with empty bodies can have a generated child listing injected before rendering.

type FrontMatter

type FrontMatter struct {
	// Core identification
	ID      string   `yaml:"id"`
	Title   string   `yaml:"title"`
	Layout  string   `yaml:"layout"`
	Draft   flexBool `yaml:"draft"`
	Private flexBool `yaml:"private"`
	Hide    flexBool `yaml:"hide"`

	// Page description
	Summary   string `yaml:"summary"`
	Category  string `yaml:"category"`
	Image     string `yaml:"image"`
	BasePath  string `yaml:"basepath"`
	TreeTitle string `yaml:"treetitle"`
	LastMod   string `yaml:"lastmod"`
	Converted bool   `yaml:"converted"`

	// Taxonomy
	Tags    []string `yaml:"tags"`
	Aliases []string `yaml:"aliases"`

	// Pagination (list pages only)
	First string `yaml:"first"`
	Last  string `yaml:"last"`
	Next  string `yaml:"next"`
	Prev  string `yaml:"prev"`

	// Person-specific
	Gender         string   `yaml:"gender"`
	Era            string   `yaml:"era"`
	Maturity       string   `yaml:"maturity"`
	Trade          string   `yaml:"trade"`
	GrampsID       string   `yaml:"grampsid"`
	Slug           string   `yaml:"slug"`
	WikiTreeID     string   `yaml:"wikitreeid"`
	MarkdownFormat string   `yaml:"markdownformat"`
	Ancestor       flexBool `yaml:"ancestor"`

	// Place-specific
	PlaceType    string `yaml:"placetype"`
	BuildingKind string `yaml:"buildingkind"`

	// Calendar-specific
	Month string `yaml:"month"`

	// Question/story-specific
	People     flexStrings         `yaml:"people"`
	Author     string              `yaml:"author"`
	Started    string              `yaml:"started"`
	Updated    string              `yaml:"updated"`
	Status     string              `yaml:"status"`
	Ai         string              `yaml:"ai"`
	StoryParts []map[string]string `yaml:"storyparts"`

	// Sidebar link lists (person pages)
	Links       []map[string]string `yaml:"links"`
	Descendants []map[string]string `yaml:"descendants"`

	// Sitemap control: {disable: "1"} suppresses the page from sitemap.xml
	Sitemap map[string]string `yaml:"sitemap"`
}

FrontMatter holds the metadata written by genster into the YAML front-matter block (delimited by ---) of each markdown content file.

func ParseDocument

func ParseDocument(content string) (fm FrontMatter, body string, err error)

ParseDocument splits a genster-generated markdown file into its YAML front-matter and body text. The front-matter block must be delimited by lines containing only "---". If no front-matter block is present, fm is zero-valued and body equals the full input.

type NavEntry struct {
	URL   string
	Title string
}

NavEntry is a link to an adjacent page used for previous/next navigation. A zero-value NavEntry (empty URL) means no adjacent page exists.

type PageData

type PageData struct {
	FrontMatter
	Body       template.HTML
	Tree       TreeData
	Section    string      // human-readable section name inferred from path (e.g. "Stories", "Research Diary")
	PrevEntry  NavEntry    // previous page in sequence (e.g. previous diary entry); zero if none
	NextEntry  NavEntry    // next page in sequence (e.g. next diary entry); zero if none
	Children   []childPage // non-nil when page uses diaryentries or storieshome layout
	DiaryYears []string    // descending list of diary years for sidebar nav (diaryhome and diaryentries only)
	Debug      bool        // true when the build was invoked with --debug
	PageLayout string      // resolved layout name, available to debug footer
}

PageData is passed to each page template during rendering. Embedding FrontMatter lets templates access fields like {{.Title}}, {{.Layout}}, etc. directly alongside {{.Body}} and {{.Tree}}.

type TreeData

type TreeData struct {
	Title    string
	BasePath string
}

TreeData holds site-level metadata for the genealogy tree a page belongs to. It is populated from the tree's section index page and is available in all templates as {{.Tree.Title}}, {{.Tree.BasePath}}, etc., without needing to repeat the information in every page's front-matter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL