htmlrewrite

package
v0.0.0-...-e7b02af Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package htmlrewrite provides transforms applied while generating HTML pages and their resources. Document transforms rewrite parsed HTML in place.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFontPreloads

func AddFontPreloads(node *html.Node, outDir, pageDir string, mode MissingResourceMode) error

AddFontPreloads appends a <link rel="preload"> element to the end of the document's <head> for every woff2 font used by the document's local stylesheets. pageDir is the document's directory relative to the site root, used to resolve relative stylesheet URLs. mode controls missing stylesheets.

func AddResourceVersions

func AddResourceVersions(node *html.Node, outDir, pageDir string, mode MissingResourceMode) error

AddResourceVersions appends a content hash query to every local resource URL. mode controls missing resources.

func Minify

func Minify(node *html.Node) error

Minify minifies the document, including CSS in style elements and JavaScript in script elements.

func MinifyCSS

func MinifyCSS(out io.Writer, in io.Reader) error

MinifyCSS writes the minified form of the CSS read from in to out.

func MinifyJS

func MinifyJS(out io.Writer, in io.Reader) error

MinifyJS writes the minified form of the JavaScript read from in to out.

func RewritePageLinks(node *html.Node, keepHTMLExtension bool)

RewritePageLinks adjusts every hyperlink to a local page so that it matches the URL that page is served at.

Types

type MissingResourceMode

type MissingResourceMode int

MissingResourceMode controls how missing local resources are handled.

const (
	ErrorOnMissingResource MissingResourceMode = iota
	IgnoreMissingResource
)

Jump to

Keyboard shortcuts

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