static

package
v0.0.0-...-b173eb0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package static reads and transforms static files.

Index

Constants

View Source
const (
	BundleFile = "bundle.js" // generated file containing bundled JS

	IndexFile = "index.html" // file that initially loads JS

)

Variables

This section is empty.

Functions

func GetFile

func GetFile(p string, staticFS fs.FS, minify bool, templateVars map[TemplateVar]any) ([]byte, error)

GetFile returns the contents of the file at the specified path (without a leading slash) within staticDir.

Files are transformed in various ways:

  • If minify is true, the returned file is minified.
  • If IndexFile is requested, scriptPlaceholder is replaced by BundleFile if minification is performed or by the JS version of bundleEntryPoint otherwise. *Placeholder are replaced by the corresponding template variables.
  • If BundleFile is requested, bundleEntryPoint and all of its dependencies are returned as a single ES module. The code is minified regardless of whether minification was requested.
  • If a nonexistent .js file is requested, its .ts counterpart is transpiled and returned.

func InlineData

func InlineData(r io.Reader, dir string, staticFS fs.FS) ([]byte, error)

InlineData reads from r and updates const variable declarations requesting inlined data from files in staticFS, e.g. "const HTML_DATA = 'inline(foo.html)'". The inlined data is minified.

Types

type TemplateVar

type TemplateVar string

TemplateVar identifies a template variable that can be passed to GetFile.

const (
	// BuildHash corresponds to an optional string containing a commit hash.
	BuildHash TemplateVar = "buildHash"
	// BuildTime corresponds to an optional string containing a build timestamp
	// formatted by invoking UTC().Format(time.RFC3339) on a time.Time.
	BuildTime TemplateVar = "buildTime"
	// Share corresponds to an optional string containing the base server URL that should
	// be used in share URLs, e.g. "https://example.org". This is passed by nup-headless
	// so that the URLs will refer to the upstream App Engine server instead.
	ShareServer TemplateVar = "shareServer"
	// RemotePlayer corresponds to a bool describing whether the web interface should use
	// the RemotePlayer class (communicating with nup-headless) rather than LocalPlayer
	// (using local <audio> elements).
	RemotePlayer TemplateVar = "remotePlayer"
)

Jump to

Keyboard shortcuts

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