generator

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package generator writes rendered HTML, assets, sitemaps, and feeds to the output directory.

Package generator writes rendered HTML, assets, sitemap, and Atom feed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyDir added in v1.0.4

func CopyDir(srcDir, dstDir string) error

CopyDir recursively copies all files from srcDir into dstDir.

func GenerateFeeds

func GenerateFeeds(outDir, baseURL, siteTitle string, articles []*model.ProcessedArticle, cfg model.Config) error

GenerateFeeds writes feed.xml (RSS 2.0) and atom.xml (Atom 1.0) to outDir. Articles are sorted newest-first. baseURL must not have a trailing slash. When cfg has I18n.Locales configured, per-locale feeds are also written:

{locale}/feed.xml and {locale}/atom.xml for each non-default locale.

The root feed.xml / atom.xml contain only articles from the default locale (or all articles when i18n is not configured).

func GenerateSitemap

func GenerateSitemap(outDir, baseURL string, articles []*model.ProcessedArticle, virtualPages []*model.VirtualPage, extraURLs []string, cfg model.Config) error

GenerateSitemap writes sitemap.xml to outDir, listing all article URLs, virtual pages produced by SitePlugins (e.g. /bookshelf/), and any extra URL paths supplied via extraURLs (e.g. taxonomy and archive pages). When articles have Translations populated (i18n), xhtml:link hreflang alternates are included for SEO. Articles are sorted newest-first. baseURL must not have a trailing slash. When cfg has I18n.Locales configured, the locale index pages (/ and /ja/ etc.) are prepended to the sitemap as important entry points.

func TaxonomyURLs added in v1.0.17

func TaxonomyURLs(site *model.Site, cfg model.Config) []string

TaxonomyURLs returns the canonical URL paths (with trailing slash) for all page-1 taxonomy and archive listing pages generated by this site. Pagination sub-pages (/page/N/) are intentionally excluded. Returned paths are relative to the site root, e.g. "/tags/go/", "/categories/architecture/", "/archives/2024/", "/archives/2024/01/".

Types

type HTMLGenerator

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

HTMLGenerator satisfies OutputGenerator by writing HTML pages and assets.

func NewHTMLGenerator

func NewHTMLGenerator(outDir string, engine gohantemplate.TemplateEngine, cfg model.Config) *HTMLGenerator

NewHTMLGenerator returns an HTMLGenerator that writes to outDir.

func (*HTMLGenerator) Generate

func (g *HTMLGenerator) Generate(site *model.Site, changeSet *model.ChangeSet) error

Generate writes all HTML pages and copies static assets. Generate writes all HTML pages for site into g.outDir. changeSet is forwarded to the OGP image generator only; HTML pages are always fully regenerated regardless of changeSet.

type OGPGenerator

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

OGPGenerator generates OGP thumbnail images for articles at build time.

func NewOGPGenerator

func NewOGPGenerator(outDir, contentDir string, cfg model.OGPConfig) *OGPGenerator

NewOGPGenerator returns an OGPGenerator configured from cfg. contentDir should be the absolute path to the content directory so that article FilePaths (absolute) can be matched against changeSet entries (relative to contentDir). Pass "" to disable that conversion.

func (*OGPGenerator) Generate

func (g *OGPGenerator) Generate(site *model.Site, changeSet *model.ChangeSet) error

Generate creates one PNG per article in public/ogp/{slug}.png. Articles whose output file already exists are skipped when changeSet is non-nil and the article is not in the changed set.

type OutputGenerator

type OutputGenerator interface {
	// Generate writes all HTML pages, copies static assets, and generates OGP
	// images into outDir.  Only files in changeSet (or all files when changeSet
	// is nil) are written.
	Generate(site *model.Site, changeSet *model.ChangeSet) error
}

OutputGenerator takes the fully-rendered site data and writes all output files to the configured output directory.

Sitemap and feed generation are handled by the package-level GenerateSitemap and GenerateFeeds functions, which are i18n-aware and kept separate from the HTML generation step.

Jump to

Keyboard shortcuts

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