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.
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" // 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" )
Click to show internal directories.
Click to hide internal directories.