external

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: 14 Imported by: 0

Documentation

Overview

Package external loads declarative disk-based plugins from {project}/plugins/{slug}/. Each plugin ships a plugin.yaml manifest describing conditional asset injection, output copying, and optional template contributions (partials, components, shortcodes). No code execution is involved: the engine synthesizes hook functions from the manifest and registers them with the regular plugin manager.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirectiveDirs added in v1.2.0

func DirectiveDirs(projectDir string) []string

DirectiveDirs returns the directives/ directories of every plugin present under {projectDir}/plugins, regardless of enablement or licensing. It is the lightweight discovery used by CLI tools that do not resolve full config; LoadAll applies the disabled-list and license gating for builds.

func DiscoverDirs

func DiscoverDirs(projectDir string) []string

DiscoverDirs returns the absolute paths of plugin directories containing a plugin.yaml, in sorted (directory listing) order. Dot-directories are skipped.

func DiscoverSlugs

func DiscoverSlugs(projectDir string) []string

DiscoverSlugs returns the names of directories under {projectDir}/plugins that contain a plugin.yaml. It is deliberately cheap (no YAML parsing) so it can run before config resolution to extend the known plugin name list.

func LoadAll

func LoadAll(mgr *plugin.Manager, projectDir string, cfg *config.SiteConfig, reserved []string) (templateDirs, directiveDirs []string, warnings []engine.ValidationWarning)

LoadAll discovers, validates, and registers every external plugin found under {projectDir}/plugins. External plugins are enabled by presence on disk; slugs listed in plugins.disabled are skipped. reserved holds plugin names already taken by built-in, subpackage, and client-side plugins.

Each plugin is handled independently: a malformed manifest, a reserved slug, or a failed premium license check produces a warning and skips only that plugin. Returns the templates/ directories of active plugins (for the template overlay chain), their directives/ directories (for the generic directive overlay chain), and the accumulated warnings.

func LoadDefaults

func LoadDefaults(dir string) (map[string]any, error)

LoadDefaults resolves a plugin's shipped default config: blueprint.yaml field defaults overlaid by the flat key/value map in config.yaml. Either file may be absent. User overrides from sarde.yaml plugins.config.{slug} are applied later, at hook time, by the plugin manager.

func Remove

func Remove(projectDir, slug string) error

Remove deletes {projectDir}/plugins/{slug}.

func ValidSlug

func ValidSlug(s string) bool

ValidSlug reports whether s is a safe single-path-element plugin slug.

Types

type BlueprintField

type BlueprintField = cfgutil.Field

BlueprintField describes one configurable field declared in blueprint.yaml. It is the shared blueprint field shape, so `sarde plugins` and the desktop app see external and built-in plugins identically.

func LoadBlueprint

func LoadBlueprint(dir string) ([]BlueprintField, error)

LoadBlueprint parses {dir}/blueprint.yaml into field metadata sorted by name. A missing file yields (nil, nil).

type InjectConfig

type InjectConfig struct {
	When          string   `yaml:"when"`
	Layout        string   `yaml:"layout"`
	Collection    string   `yaml:"collection"`
	Styles        []string `yaml:"styles"`
	Scripts       []string `yaml:"scripts"`
	ModuleScripts []string `yaml:"module_scripts"`
}

InjectConfig declares conditional per-page asset injection.

func (*InjectConfig) HasAssets

func (i *InjectConfig) HasAssets() bool

HasAssets reports whether the inject block references any asset files.

type Manifest

type Manifest struct {
	Name        string       `yaml:"name"`
	Slug        string       `yaml:"slug"`
	Version     string       `yaml:"version"`
	Description string       `yaml:"description"`
	Author      string       `yaml:"author"`
	Homepage    string       `yaml:"homepage"`
	Premium     bool         `yaml:"premium"`
	PurchaseURL string       `yaml:"purchase_url"`
	Inject      InjectConfig `yaml:"inject"`
	Output      OutputConfig `yaml:"output"`
}

Manifest is the parsed plugin.yaml of one external plugin.

func Install

func Install(projectDir, source string, reserved []string) (*Manifest, error)

Install fetches a plugin from source (local zip, local directory, GitHub repository, or zip/tar.gz URL), validates its manifest in a staging directory, and moves it into {projectDir}/plugins/{slug}/. The destination directory name always equals the manifest slug; there is no name override because license lookup and enable/disable both key off the slug. reserved holds built-in plugin names that external slugs may not use.

func LoadManifest

func LoadManifest(dir string) (*Manifest, error)

LoadManifest reads and parses {dir}/plugin.yaml. Unknown fields are rejected so manifest typos surface as errors instead of silent no-ops.

func (*Manifest) EffectivePrefix

func (m *Manifest) EffectivePrefix() string

EffectivePrefix returns the dist-relative output prefix, always without a leading slash and with a trailing slash. Defaults to assets/vendor/{slug}/ with underscores kebab-ized: identifiers are snake_case, URLs are kebab-case, and underscores never appear in an emitted URL.

func (*Manifest) IncludeFilter

func (m *Manifest) IncludeFilter() func(rel string) bool

IncludeFilter returns a filter for WriteFSTreeFiltered based on output.include, or nil when the whole assets/ tree should be copied. Entries ending in "/" match directory prefixes; other entries match the exact file or a directory of that name.

func (*Manifest) Validate

func (m *Manifest) Validate(dirName string) error

Validate checks required fields, the slug/directory-name match, inject rule consistency, and rejects path escapes in asset and output paths.

type OutputConfig

type OutputConfig struct {
	Prefix  string   `yaml:"prefix"`
	Include []string `yaml:"include"`
}

OutputConfig declares which files under assets/ are copied to dist and where.

Jump to

Keyboard shortcuts

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