generator

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package generator provides functionality for generating static HTML blog sites from markdown files.

The generator uses the functional options pattern for configuration. Required parameters are passed as positional arguments, while optional parameters are configured via option functions.

TODO: Add usage examples

The Generator returns all generated content in memory via GeneratedBlog. Callers are responsible for I/O operations such as writing files to disk or serving content via HTTP.

The Generator is safe for concurrent use once created, though Generate operations should not be run concurrently on the same Generator instance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GeneratedBlog

type GeneratedBlog struct {
	Posts map[string][]byte // Posts maps a slug to raw HTML bytes for each post
	Index []byte            // Index contains the raw HTML for the blog index page
	Tags  map[string][]byte // Tags maps each tag name to its tag page HTML
}

GeneratedBlog contains all the HTML content for a complete static blog site.

It includes individual post pages, the main index page, and tag pages. All content is stored as raw HTML bytes ready to be written to files or served via HTTP.

Post slugs are derived from markdown filenames. Tag names are extracted from post front matter. For more info see pkg/models/Post.

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator produces HTML output based on its input configuration. It reads markdown files from a configured filesystem and renders them as HTML using templates.

A Generator is safe for concurrent use after creation, but Generate operations should not be called concurrently on the same instance.

func New

func New() (*Generator, error)

New creates a new Generator with the specified options. It returns an error if the configuration is invalid or if required resources cannot be initialized.

Options can be provided to customize behavior such as template directories, posts per page, and other generation parameters.

func (*Generator) Generate

func (g *Generator) Generate(ctx context.Context) (*GeneratedBlog, error)

Generate reads markdown post files from the configured filesystem and generates a complete static blog site as HTML.

It returns a GeneratedBlog containing all rendered HTML content including individual post pages, tag pages, and the index page. The returned content is in-memory only; callers are responsible for writing to disk or serving via HTTP as needed.

Generate respects the provided context and will return early with context.Canceled or context.DeadlineExceeded if the context is canceled or times out.

It returns an error if markdown files cannot be read, parsing fails, or template rendering encounters an error.

type GeneratorConfig

type GeneratorConfig struct {
	PostsDir     fs.FS // The filesystem containing the input posts in markdown
	TemplatesDir fs.FS // The filesystem containing the templates to use
}

GeneratorConfig contains all the configuration to control how a Generator operates.

PostsDir specifies the filesystem containing markdown post files. Each file should contain front matter metadata and post content.

TemplatesDir specifies the filesystem containing HTML templates for rendering the blog. If not specified, default templates will be used.

type Option

type Option func(*GeneratorConfig)

Option is a function which modifies a GeneratorConfig. Options are used to configure optional parameters when creating a new Generator.

Jump to

Keyboard shortcuts

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