site

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompanionMarkdown added in v1.0.0

func CompanionMarkdown(s *Site, p *content.Page) string

CompanionMarkdown returns clean markdown for a page's companion .md file. It prepends a title heading if the raw content doesn't already start with one. If the page's frontmatter includes llms_data, the referenced data files are appended as YAML blocks, making data-driven page content available to LLMs.

func Filter

func Filter(pages []*content.Page, predicate func(*content.Page) bool) []*content.Page

Filter returns pages matching a predicate function

func First

func First(pages []*content.Page) *content.Page

First returns the first page, or nil if empty

func GetDataAs

func GetDataAs[T any](s *Site, key string) T

GetDataAs attempts to return data cast to a specific type Returns nil if not found or type assertion fails

func GroupBySection

func GroupBySection(pages []*content.Page) map[string][]*content.Page

GroupBySection groups pages by their section

func Last

func Last(pages []*content.Page) *content.Page

Last returns the last page, or nil if empty

func Limit

func Limit(pages []*content.Page, n int) []*content.Page

Limit returns the first n pages from the slice If n >= len(pages), returns the original slice

func Offset

func Offset(pages []*content.Page, n int) []*content.Page

Offset returns pages starting from index n If n >= len(pages), returns nil

func Paginate

func Paginate(pages []*content.Page, pageNum, perPage int) []*content.Page

Paginate returns a slice of pages for a given page number (1-indexed)

func Reverse

func Reverse(pages []*content.Page) []*content.Page

Reverse returns a copy of pages in reverse order

func SortByDate

func SortByDate(pages []*content.Page, ascending bool) []*content.Page

SortByDate returns a copy of pages sorted by date If ascending is true, oldest first; otherwise newest first

func SortByTitle

func SortByTitle(pages []*content.Page) []*content.Page

SortByTitle returns a copy of pages sorted alphabetically by title

func SortByWeight

func SortByWeight(pages []*content.Page) []*content.Page

SortByWeight returns a copy of pages sorted by weight (ascending), then date (descending)

Types

type AssetsConfig

type AssetsConfig struct {
	InputDir    string `yaml:"inputDir"`
	OutputDir   string `yaml:"outputDir"`
	Minify      bool   `yaml:"minify"`
	Fingerprint bool   `yaml:"fingerprint"`
}

AssetsConfig configures asset processing

type AtomAuthor

type AtomAuthor struct {
	Name string `xml:"name"`
}

AtomAuthor represents an author in an Atom feed

type AtomEntry

type AtomEntry struct {
	Title   string      `xml:"title"`
	Link    AtomFLink   `xml:"link"`
	ID      string      `xml:"id"`
	Updated string      `xml:"updated"`
	Summary string      `xml:"summary,omitempty"`
	Author  *AtomAuthor `xml:"author,omitempty"`
}

AtomEntry represents an entry in an Atom feed

type AtomFLink struct {
	Href string `xml:"href,attr"`
	Rel  string `xml:"rel,attr,omitempty"`
	Type string `xml:"type,attr,omitempty"`
}

AtomFLink represents a link in an Atom feed

type AtomFeed

type AtomFeed struct {
	XMLName xml.Name    `xml:"feed"`
	Xmlns   string      `xml:"xmlns,attr"`
	Title   string      `xml:"title"`
	Link    []AtomFLink `xml:"link"`
	Updated string      `xml:"updated"`
	ID      string      `xml:"id"`
	Author  *AtomAuthor `xml:"author,omitempty"`
	Entries []AtomEntry `xml:"entry"`
}

AtomFeed represents an Atom 1.0 feed

type AtomLink struct {
	Href string `xml:"href,attr"`
	Rel  string `xml:"rel,attr"`
	Type string `xml:"type,attr"`
}

AtomLink represents the atom:link element for RSS feed self-reference

type BuildConfig

type BuildConfig struct {
	// Drafts includes draft pages in the build when true
	Drafts bool `yaml:"drafts,omitempty"`
	// Future includes pages with future dates when true
	Future bool `yaml:"future,omitempty"`
}

BuildConfig contains build-time options

type Config

type Config struct {
	Title       string        `yaml:"title"`
	BaseURL     string        `yaml:"baseURL"`
	Description string        `yaml:"description,omitempty"`
	Language    string        `yaml:"language,omitempty"`
	Content     ContentConfig `yaml:"content"`
	Assets      AssetsConfig  `yaml:"assets"`
	OutputDir   string        `yaml:"outputDir"`
	ThemeColor  string        `yaml:"themeColor,omitempty"`

	// Taxonomies lists the taxonomy names to build (e.g., ["tags", "categories"])
	// Each taxonomy extracts terms from page frontmatter with the same key
	Taxonomies []string `yaml:"taxonomies,omitempty"`

	// Menus defines navigation menus (e.g., "main", "footer")
	Menus map[string][]MenuItemConfig `yaml:"menus,omitempty"`

	// DataDir is the directory containing data files (YAML/JSON)
	DataDir string `yaml:"dataDir,omitempty"`

	// StaticDir is the directory containing files to copy to the output root
	// (favicons, etc.). Defaults to "static".
	StaticDir string `yaml:"staticDir,omitempty"`

	// Build contains build-time options
	Build BuildConfig `yaml:"build,omitempty"`

	// Highlight configures syntax highlighting for code blocks
	Highlight HighlightConfig `yaml:"highlight,omitempty"`

	// Params holds arbitrary user-defined parameters accessible in templates
	// via s.Config.Params["key"]. Environment overrides merge into this map.
	Params map[string]any `yaml:"params,omitempty"`

	// LLMs configures llms.txt generation for LLM-friendly content discovery
	LLMs LLMsConfig `yaml:"llms,omitempty"`
}

Config represents the site configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a configuration with sensible defaults

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads configuration from a YAML file

func LoadConfigOrDefault

func LoadConfigOrDefault(path string) (*Config, error)

LoadConfigOrDefault loads configuration or returns defaults if file doesn't exist

func LoadConfigWithEnv

func LoadConfigWithEnv(basePath string, env string) (*Config, error)

LoadConfigWithEnv loads the base config and merges an environment-specific override file on top of it. For example, with basePath "config.yaml" and env "production", it looks for "config.production.yaml" in the same directory. If env is empty, behaves identically to LoadConfig. If the env override file does not exist, the base config is used without error.

func (*Config) AssetsInputPath

func (c *Config) AssetsInputPath(base string) string

AssetsInputPath returns the absolute path to the assets input directory

func (*Config) AssetsOutputPath

func (c *Config) AssetsOutputPath(base string) string

AssetsOutputPath returns the absolute path to the assets output directory

func (*Config) ContentPath

func (c *Config) ContentPath(base string) string

ContentPath returns the absolute path to the content directory

func (*Config) DataPath

func (c *Config) DataPath(base string) string

DataPath returns the absolute path to the data directory

func (*Config) OutputPath

func (c *Config) OutputPath(base string) string

OutputPath returns the absolute path to the output directory

func (*Config) Save

func (c *Config) Save(path string) error

Save writes the configuration to a YAML file

func (*Config) StaticPath

func (c *Config) StaticPath(base string) string

StaticPath returns the absolute path to the static directory

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid

type ContentConfig

type ContentConfig struct {
	Dir           string `yaml:"dir"`
	DefaultLayout string `yaml:"defaultLayout"`
}

ContentConfig configures content processing

type HighlightConfig

type HighlightConfig struct {
	// Style is the Chroma style name (e.g., "monokai", "github", "dracula").
	// When set, code blocks are syntax-highlighted and a chroma.css file is generated.
	// Empty string disables syntax highlighting.
	Style string `yaml:"style,omitempty"`
	// LineNumbers adds line numbers to code blocks when true
	LineNumbers bool `yaml:"lineNumbers,omitempty"`
}

HighlightConfig configures syntax highlighting for code blocks

type JSONFeed

type JSONFeed struct {
	Version     string         `json:"version"`
	Title       string         `json:"title"`
	HomePageURL string         `json:"home_page_url"`
	FeedURL     string         `json:"feed_url"`
	Description string         `json:"description,omitempty"`
	Language    string         `json:"language,omitempty"`
	Items       []JSONFeedItem `json:"items"`
}

JSONFeed represents a JSON Feed 1.1

type JSONFeedItem

type JSONFeedItem struct {
	ID            string `json:"id"`
	URL           string `json:"url"`
	Title         string `json:"title"`
	ContentText   string `json:"content_text,omitempty"`
	Summary       string `json:"summary,omitempty"`
	DatePublished string `json:"date_published,omitempty"`
	Author        *struct {
		Name string `json:"name"`
	} `json:"author,omitempty"`
}

JSONFeedItem represents an item in a JSON Feed

type LLMsConfig added in v1.0.0

type LLMsConfig struct {
	// Enabled turns on llms.txt generation
	Enabled bool `yaml:"enabled"`
	// Description overrides the site description in the llms.txt blockquote
	Description string `yaml:"description,omitempty"`
	// Sections defines explicit content sections for llms.txt.
	// If empty, sections are auto-derived from the site's directory structure.
	Sections []LLMsSectionConfig `yaml:"sections,omitempty"`
	// Exclude lists section patterns to exclude from llms.txt (e.g., "internal")
	Exclude []string `yaml:"exclude,omitempty"`
}

LLMsConfig configures llms.txt generation for LLM-friendly content discovery. When Enabled is true, the build generates llms.txt, llms-full.txt, and companion .md files alongside each HTML page.

type LLMsSectionConfig added in v1.0.0

type LLMsSectionConfig struct {
	// Name is the display name for the section heading
	Name string `yaml:"name"`
	// Pattern is the section name (content directory) to match
	Pattern string `yaml:"pattern"`
	// Priority is "required" (default) or "optional".
	// Optional sections are grouped under "## Optional" in the output.
	Priority string `yaml:"priority,omitempty"`
}

LLMsSectionConfig defines a section in the llms.txt output.

type MenuItem struct {
	Name   string
	URL    string
	Weight int
	Active bool // Set during rendering based on current page
}

MenuItem represents a menu item with runtime state

type MenuItemConfig struct {
	Name   string `yaml:"name"`
	URL    string `yaml:"url"`
	Weight int    `yaml:"weight,omitempty"`
}

MenuItemConfig represents a menu item in configuration

type Paginator

type Paginator struct {
	Items      []*content.Page // pages for current page
	TotalItems int             // total number of items across all pages
	PerPage    int             // items per page
	TotalPages int             // total number of pages
	PageNum    int             // current page number (1-indexed)
	HasPrev    bool            // true if there's a previous page
	HasNext    bool            // true if there's a next page
	PrevURL    string          // URL of previous page (empty if no prev)
	NextURL    string          // URL of next page (empty if no next)
	PageURLs   []string        // URLs for all pages (for building navigation)
	BaseURL    string          // base URL for this paginated section
}

Paginator handles pagination of page collections with navigation URLs

func NewPaginator

func NewPaginator(pages []*content.Page, perPage int, baseURL string) *Paginator

NewPaginator creates a paginator for a page collection baseURL should end with a slash (e.g., "/blog/")

func (*Paginator) First

func (p *Paginator) First() int

First returns the first page number (always 1)

func (*Paginator) Last

func (p *Paginator) Last() int

Last returns the last page number

func (*Paginator) Page

func (p *Paginator) Page(num int) *Paginator

Page returns a new paginator configured for a specific page number (1-indexed) The returned paginator has Items set to just the items for that page

func (*Paginator) Pages

func (p *Paginator) Pages() []int

Pages returns a slice of page numbers for building navigation For example, if on page 5 of 10, might return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

func (*Paginator) URL

func (p *Paginator) URL(pageNum int) string

URL returns the URL for a specific page number

type RSSChannel

type RSSChannel struct {
	Title         string    `xml:"title"`
	Link          string    `xml:"link"`
	Description   string    `xml:"description"`
	Language      string    `xml:"language,omitempty"`
	LastBuildDate string    `xml:"lastBuildDate,omitempty"`
	AtomLink      AtomLink  `xml:"atom:link"`
	Items         []RSSItem `xml:"item"`
}

RSSChannel represents the channel element of an RSS feed

type RSSFeed

type RSSFeed struct {
	XMLName xml.Name   `xml:"rss"`
	Version string     `xml:"version,attr"`
	Atom    string     `xml:"xmlns:atom,attr"`
	Channel RSSChannel `xml:"channel"`
}

RSSFeed represents an RSS 2.0 feed

type RSSItem

type RSSItem struct {
	Title       string `xml:"title"`
	Link        string `xml:"link"`
	Description string `xml:"description,omitempty"`
	PubDate     string `xml:"pubDate,omitempty"`
	GUID        string `xml:"guid"`
	Author      string `xml:"author,omitempty"`
}

RSSItem represents an item in an RSS feed

type Section

type Section struct {
	// Name is the section identifier (directory name)
	Name string

	// Title is the display title (from _index.md or derived from Name)
	Title string

	// Description is from _index.md frontmatter
	Description string

	// Pages contains all pages in this section, sorted by date descending
	Pages []*content.Page

	// URL is the section's URL path (e.g., /blog/)
	URL string

	// Index is the _index.md page for this section (if it exists)
	Index *content.Page
}

Section represents a content section (e.g., blog, docs)

func (*Section) PageCount

func (s *Section) PageCount() int

PageCount returns the number of regular pages (excluding _index.md)

func (*Section) RegularPages

func (s *Section) RegularPages() []*content.Page

RegularPages returns pages excluding _index.md

type Site

type Site struct {
	Config       *Config
	Pages        []*content.Page
	Sections     map[string]*Section
	Taxonomies   map[string]*Taxonomy
	Menus        map[string][]*MenuItem
	Data         map[string]any
	BuildTime    time.Time
	AssetVersion string // content hash for cache-busting query strings
	// contains filtered or unexported fields
}

Site represents a static site with all its content and configuration

func New

func New(configPath string) (*Site, error)

New creates a new Site instance

func NewWithConfig

func NewWithConfig(config *Config) *Site

NewWithConfig creates a new Site with an existing configuration

func NewWithEnv

func NewWithEnv(configPath string, env string) (*Site, error)

NewWithEnv creates a new Site, merging an environment-specific config override. For example, NewWithEnv("config.yaml", "production") loads config.yaml then merges config.production.yaml on top. If env is empty, behaves like New().

func (*Site) AllMenus

func (s *Site) AllMenus() []string

AllMenus returns all menu names

func (*Site) AllSections

func (s *Site) AllSections() []*Section

AllSections returns all sections (excluding _root if empty)

func (*Site) AllTags

func (s *Site) AllTags() map[string]int

AllTags returns all unique tags across all pages with their counts

func (*Site) Atom

func (s *Site) Atom(pages []*content.Page, title, subtitle string) string

Atom generates an Atom 1.0 feed for the given pages

func (*Site) Build

func (s *Site) Build(ctx context.Context) error

Build builds the entire site

func (*Site) BuildAssets

func (s *Site) BuildAssets(ctx context.Context) error

BuildAssets builds all assets (CSS, JS, static files)

func (*Site) Clean

func (s *Site) Clean() error

Clean removes the output directory

func (*Site) Default404

func (s *Site) Default404() string

Default404 generates a minimal 404 page as a fallback. Users can override this by creating content/404.md or placing 404.html in static/.

func (*Site) Feed

func (s *Site) Feed() string

Feed generates an Atom 1.0 feed for the site

func (*Site) GenerateTemplComponents

func (s *Site) GenerateTemplComponents(ctx context.Context) error

GenerateTemplComponents runs templ generate on the components directory

func (*Site) GetData

func (s *Site) GetData(key string) any

GetData returns data by key, supporting nested paths with "/" For example: GetData("team") or GetData("config/settings")

func (*Site) GetOutputPath

func (s *Site) GetOutputPath(url string) string

GetOutputPath converts a URL path to a filesystem output path This is a helper for user's rendering code

func (*Site) GetSection

func (s *Site) GetSection(name string) *Section

GetSection returns a section by name

func (*Site) GetTaxonomy

func (s *Site) GetTaxonomy(name string) *Taxonomy

GetTaxonomy returns a taxonomy by name, or nil if not found

func (*Site) GetTerm

func (s *Site) GetTerm(taxonomy, termSlug string) *Term

GetTerm returns a specific term from a taxonomy

func (*Site) JSON

func (s *Site) JSON(pages []*content.Page, title, description string) string

JSON generates a JSON Feed 1.1 for the given pages

func (*Site) LLMsFull added in v1.0.0

func (s *Site) LLMsFull() string

LLMsFull generates /llms-full.txt with all linked content inlined.

func (*Site) LLMsPages added in v1.0.0

func (s *Site) LLMsPages() []*content.Page

LLMsPages returns all pages that would be included in llms.txt output, respecting exclusion rules. Useful for templates or custom rendering.

func (*Site) LLMsSectionNames added in v1.0.0

func (s *Site) LLMsSectionNames() []string

LLMsSectionNames returns the section names that will appear in llms.txt, either from config or auto-derived. Useful for debugging configuration.

func (*Site) LLMsTxt added in v1.0.0

func (s *Site) LLMsTxt() string

LLMsTxt generates the /llms.txt index file following the llms.txt specification. It produces an H1 title, blockquote summary, and H2 sections with links to companion markdown files for each published page.

func (*Site) Manifest

func (s *Site) Manifest() string

Manifest generates a site.webmanifest JSON string from site configuration

func (*Site) Menu

func (s *Site) Menu(name string) []*MenuItem

Menu returns a menu by name, or nil if not found

func (*Site) MenuWithActive

func (s *Site) MenuWithActive(name, currentURL string) []*MenuItem

MenuWithActive returns a menu with the Active flag set for the current URL This returns a new slice to avoid mutating the original

func (*Site) OutputDir

func (s *Site) OutputDir() string

OutputDir returns the absolute path to the output directory This is a helper for code that needs the output directory path

func (*Site) PageByURL

func (s *Site) PageByURL(url string) *content.Page

PageByURL finds a page by its URL path

func (*Site) PagesByTag

func (s *Site) PagesByTag(tag string) []*content.Page

PagesByTag returns all published pages with a specific tag Uses the taxonomy system if available, falls back to direct tag check

func (*Site) PagesByTaxonomy

func (s *Site) PagesByTaxonomy(taxonomy, termSlug string) []*content.Page

PagesByTaxonomy returns pages for a specific taxonomy term Returns nil if taxonomy or term doesn't exist

func (*Site) PagesInSection

func (s *Site) PagesInSection(sectionName string) []*content.Page

PagesInSection returns all pages in a specific section Returns nil if section doesn't exist

func (*Site) ProcessContent

func (s *Site) ProcessContent(ctx context.Context) error

ProcessContent processes all content files and makes them available via Pages

func (*Site) RSS

func (s *Site) RSS(pages []*content.Page, title, description string) string

RSS generates an RSS 2.0 feed for the given pages

func (*Site) RegularPages

func (s *Site) RegularPages() []*content.Page

RegularPages returns all non-index, published pages across all sections

func (*Site) RegularPagesInSection

func (s *Site) RegularPagesInSection(sectionName string) []*content.Page

RegularPagesInSection returns non-index, published pages in a section

func (*Site) RobotsTxt

func (s *Site) RobotsTxt() string

RobotsTxt generates a robots.txt file with sitemap reference

func (*Site) RobotsTxtWithDisallow

func (s *Site) RobotsTxtWithDisallow(disallowPaths []string) string

RobotsTxtWithDisallow generates a robots.txt with custom disallow rules

func (*Site) SectionNames

func (s *Site) SectionNames() []string

SectionNames returns names of all sections with content

func (*Site) SetBaseDir

func (s *Site) SetBaseDir(dir string)

SetBaseDir sets the base directory for the site

func (*Site) Sitemap

func (s *Site) Sitemap() string

Sitemap generates a sitemap.xml for the site

func (*Site) Tags

func (s *Site) Tags() []*Term

Tags returns all tags as Term structs, sorted by page count descending This is a convenience method equivalent to TaxonomyTerms("tags")

func (*Site) TaxonomyTerms

func (s *Site) TaxonomyTerms(name string) []*Term

TaxonomyTerms returns all terms for a taxonomy, sorted by page count descending Returns nil if taxonomy doesn't exist

func (*Site) TaxonomyTermsByName

func (s *Site) TaxonomyTermsByName(name string) []*Term

TaxonomyTermsByName returns all terms for a taxonomy, sorted alphabetically

type SitemapURL

type SitemapURL struct {
	Loc        string `xml:"loc"`
	LastMod    string `xml:"lastmod,omitempty"`
	ChangeFreq string `xml:"changefreq,omitempty"`
	Priority   string `xml:"priority,omitempty"`
}

SitemapURL represents a single URL entry in a sitemap

type Taxonomy

type Taxonomy struct {
	// Name is the taxonomy identifier (e.g., "tags")
	Name string

	// Plural is used for URLs (usually same as Name)
	Plural string

	// Terms maps term slugs to Term structs
	Terms map[string]*Term
}

Taxonomy represents a classification system (e.g., tags, categories)

func NewTaxonomy

func NewTaxonomy(name string) *Taxonomy

NewTaxonomy creates a new taxonomy with the given name

func (*Taxonomy) AddPage

func (t *Taxonomy) AddPage(termName string, page *content.Page)

AddPage adds a page to a term, creating the term if it doesn't exist

func (*Taxonomy) AllTerms

func (t *Taxonomy) AllTerms() []*Term

AllTerms returns all terms sorted by page count (descending)

func (*Taxonomy) GetTerm

func (t *Taxonomy) GetTerm(slug string) *Term

GetTerm returns a term by slug, or nil if not found

func (*Taxonomy) SortTermPages

func (t *Taxonomy) SortTermPages()

SortTermPages sorts pages within each term by date descending

func (*Taxonomy) TermsByName

func (t *Taxonomy) TermsByName() []*Term

TermsByName returns all terms sorted alphabetically by name

type Term

type Term struct {
	// Name is the display name of the term
	Name string

	// Slug is the URL-safe version of the name
	Slug string

	// Pages contains all pages with this term
	Pages []*content.Page

	// URL is the term's URL path (e.g., /tags/go/)
	URL string

	// Taxonomy is the parent taxonomy name
	Taxonomy string
}

Term represents a single term within a taxonomy (e.g., "go" in tags)

func (*Term) PageCount

func (t *Term) PageCount() int

PageCount returns the number of pages with this term

type URLSet

type URLSet struct {
	XMLName xml.Name     `xml:"urlset"`
	Xmlns   string       `xml:"xmlns,attr"`
	URLs    []SitemapURL `xml:"url"`
}

URLSet represents a sitemap.xml document

Jump to

Keyboard shortcuts

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