Documentation
¶
Overview ¶
Package output handles writing rendered HTML and assets to the publish directory.
Index ¶
- func Canonify(html string, opts CanonifyOptions) string
- func CleanPublishDir(publishDir string) error
- func GenerateContentAPI(outputDir string, site *content.Site, cfg *config.Config, ...) error
- func GenerateLlmsTxt(outputDir, sourceDir string, cfg *config.Config) error
- func PathToFilePath(path, publishDir string) string
- func URLToFilePath(url, publishDir string) string
- type CanonifyOptions
- type ContentItem
- type Minifier
- type Writer
- func (w *Writer) CopyStatic(srcDir string) error
- func (w *Writer) SetCanonify(opts CanonifyOptions)
- func (w *Writer) Stats() (files int, bytes int64)
- func (w *Writer) Write(relPath, content string) error
- func (w *Writer) WriteBytes(relPath string, data []byte) error
- func (w *Writer) WriteBytesPath(relPath string, data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Canonify ¶
func Canonify(html string, opts CanonifyOptions) string
Canonify rewrites root-relative URLs in href/src attributes to absolute URLs. Mirrors Hugo's canonifyURLs = true behavior.
Handles both quoted and unquoted (post-minify) attribute values. Skips protocol-relative URLs (//example.com) and absolute http(s) URLs.
Skips <code> and <pre> regions: URLs inside code blocks are raw text content (e.g., a code sample showing `<link href=/api/foo />`), not actual HTML attributes. Hugo's canonifyURLs does not rewrite inside code/pre either.
func CleanPublishDir ¶
CleanPublishDir removes the publish directory. Use cautiously - this is destructive.
func GenerateContentAPI ¶
func GenerateContentAPI(outputDir string, site *content.Site, cfg *config.Config, includeDrafts, includeFuture, includeExpired bool, now time.Time) error
GenerateContentAPI writes /api/{section}.json for each top-level section. Only pages that pass the draft/future/expired filter are included.
func GenerateLlmsTxt ¶
GenerateLlmsTxt writes /llms.txt to the output directory. If layouts/llms.txt exists, it's used as-is; otherwise a default is generated from the site config.
func PathToFilePath ¶
PathToFilePath maps a path (without trailing slash) directly. e.g., ("sitemap.xml") → publishDir/sitemap.xml e.g., ("posts/index.xml") → publishDir/posts/index.xml
func URLToFilePath ¶
URLToFilePath converts a URL path to an output file path under publishDir. Hugo convention: /foo/ → publishDir/foo/index.html
Types ¶
type CanonifyOptions ¶
type CanonifyOptions struct {
BaseURL string // e.g., "https://zhurongshuo.com/"
IsHome bool // if true, inject Hugo generator meta
}
CanonifyOptions controls how canonifyURLs rewrites paths.
type ContentItem ¶
type ContentItem struct {
Title string `json:"title"`
URL string `json:"url"`
Date string `json:"date"`
Description string `json:"description,omitempty"`
Summary string `json:"summary,omitempty"`
Plain string `json:"plain,omitempty"`
Tags []string `json:"tags,omitempty"`
}
ContentItem is a single content entry in the API output.
type Minifier ¶
type Minifier struct {
// contains filtered or unexported fields
}
Minifier wraps tdewolff/minify with the same configuration Hugo uses.
func NewMinifier ¶
func NewMinifier() *Minifier
NewMinifier creates a minifier matching Hugo's tdewolff settings:
HTML: keepWhitespace = false CSS: precision = 0 JS: precision = 0
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer writes files to the publish directory.
func NewWriterWithMinify ¶
NewWriterWithMinify creates a Writer that minifies output before writing.
func (*Writer) CopyStatic ¶
CopyStatic copies all files from srcDir into publishDir, preserving relative paths.
func (*Writer) SetCanonify ¶
func (w *Writer) SetCanonify(opts CanonifyOptions)
SetCanonify enables root-relative URL canonification with the given options.
func (*Writer) Write ¶
Write writes content to a file path under publishDir. Creates parent directories as needed. If a minifier is set, content is minified according to the file's media type before writing. If canonify is set, root-relative URLs in HTML are rewritten to absolute URLs.
func (*Writer) WriteBytes ¶
WriteBytes writes raw bytes to a file path under publishDir. Minification is applied if a minifier is set.