singlepage

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2022 License: MIT Imports: 20 Imported by: 0

README

Inline CSS, JavaScript, and images in a HTML file to distribute a stand-alone HTML document without external dependencies.

You can download binaries from the releases page, or compile from source with go install zgo.at/singlepage/cmd/singlepage@latest, which will put a binary in ~/go/bin/.

Run it with as singlepage file.html > bundled.html or cat file.html | singlepage > bundled.html. There are a bunch of options; use singlepage -help to see the full documentation.

Use the zgo.at/singlepage package if you want to integrate this in a Go program. Also see the API docs: https://godocs.io/zgo.at/singlepage

It uses tdewolff/minify for minification, so please report bugs or other questions there.

Why would I want to use this?

There are a few reasons:

  • Sometimes distributing a single HTML document is easier; for example for rendered HTML documentation.

  • It makes pages slightly faster to load if your CSS/JS assets are small(-ish); especially on slower connections.

  • As a slightly less practical and more ideological point, I liked the web before it became this jumbled mess of obnoxious JavaScript and excessive CSS, and I like the concept of self-contained HTML documents.

Documentation

Index

Constants

View Source
const (
	HTML zint.Bitflag16 = 1 << (iota - 1)
	CSS
	JS
	Image
	Font
)

Variables

View Source
var Everything = Options{
	Local:  CSS | JS | Image,
	Remote: CSS | JS | Image,
	Minify: CSS | JS | Image,
}

Everything is an Options struct with everything enabled.

Functions

func Bundle

func Bundle(html []byte, opts Options) (string, error)

Bundle the resources in a HTML document according to the given options.

Types

type LookupError

type LookupError struct {
	Path string
	Err  error
}

LookupError is used when we can't look up a resource. This may be a non-fatal error.

func (*LookupError) Error

func (e *LookupError) Error() string

type Options

type Options struct {
	Root   string
	Strict bool
	Quiet  bool
	Local  zint.Bitflag16
	Remote zint.Bitflag16
	Minify zint.Bitflag16
}

Options for Bundle().

func NewOptions

func NewOptions(root string, strict, quiet bool) Options

NewOptions creates a new Options instance.

func (*Options) Commandline

func (opts *Options) Commandline(local, remote, minify []string) error

Commandline modifies the Options from the format accepted in the commandline tool's flags.

type ParseError

type ParseError struct {
	Path string
	Err  error
}

ParseError indicates there was a parsing failure. This may be a non-fatal error.

func (*ParseError) Error

func (e *ParseError) Error() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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