clientplugins

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package clientplugins provides a declarative manifest-driven loader for client-side plugins. Instead of separate Go subpackages, all pure JS/CSS plugins are defined in manifest.yaml with inject_when rules, and their assets are embedded via go:embed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Defaults

func Defaults(slug string) map[string]any

Defaults returns the default config values for a plugin, or nil if unknown.

func Description added in v1.4.0

func Description(slug string) string

Description returns the manifest description of a plugin, or "".

func FieldNames added in v1.2.0

func FieldNames(slug string) []string

FieldNames returns the declared config field names of a plugin, sorted, or nil for a plugin the manifest does not know or that ships no defaults file.

func Fields added in v1.4.0

func Fields(slug string) []cfgutil.Field

Fields returns a plugin's typed config field specs (sorted by name), or nil for a plugin the manifest does not know or that ships no defaults file.

func Initialize

func Initialize() error

Initialize loads the embedded plugin manifest and per-plugin defaults. Safe to call multiple times; only the first call does work.

Bundling deliberately does not happen here: which plugins belong in the bundle depends on the site's plugins.enabled, and Initialize runs during config resolution (see build.KnownPluginNames), before any config exists. RegisterAll builds the bundle instead, once the enabled set is known.

func Label added in v1.4.0

func Label(slug string) string

Label returns the manifest display name of a plugin, or "".

func PluginSlugs

func PluginSlugs() []string

PluginSlugs returns the slugs of all plugins defined in the manifest.

func RegisterAll

func RegisterAll(mgr *plugin.Manager, enabled []string, configs map[string]map[string]any, assetDir string)

RegisterAll registers a single "clientplugins" meta-plugin that injects the bundled CSS/JS on every page and per-plugin config scripts gated by inject_when.

Only plugins named in enabled contribute to the bundle, so a site ships no code for plugins it has not turned on. assetDir overrides the embedded assets for 'sarde dev --theme-dev'; empty means use the embedded ones.

Types

type Manifest

type Manifest struct {
	Plugins map[string]ManifestEntry `yaml:"plugins"`
}

Manifest holds all client plugin definitions.

type ManifestEntry

type ManifestEntry struct {
	Label       string `yaml:"label"`
	Description string `yaml:"description"`
	InjectWhen  string `yaml:"inject_when"`
	Assets      struct {
		CSS string `yaml:"css"`
		JS  string `yaml:"js"`
	} `yaml:"assets"`
	Module bool `yaml:"module"`
}

ManifestEntry defines a single client-side plugin in the manifest.

Jump to

Keyboard shortcuts

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