plugin

package
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package plugin defines the gohan plugin interface and built-in plugin registry.

Plugins are compiled into the gohan binary and enabled/disabled via config.yaml:

plugins:
  amazon_books:
    enabled: true
    tag: "your-associate-tag-22"

Each plugin receives a ProcessedArticle and its own config section, and returns arbitrary data that the theme template can access via .PluginData.<plugin_name>.

SitePlugins operate on the full site rather than individual articles. They generate VirtualPages — pages that have no corresponding Markdown source file (e.g. a bookshelf page aggregated from all articles).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Plugin

type Plugin interface {
	// Name returns the unique identifier of the plugin.
	// This key is used in config.yaml under plugins.<name>
	// and as the key in ProcessedArticle.PluginData.
	Name() string

	// Enabled reports whether the plugin is active for the given config section.
	// cfg is the map under plugins.<name> in config.yaml.
	Enabled(cfg map[string]interface{}) bool

	// TemplateData returns data to inject into the template context for the
	// given article. The returned map is stored at .PluginData.<name> in
	// the template.
	TemplateData(article *model.ProcessedArticle, cfg map[string]interface{}) (map[string]interface{}, error)
}

Plugin is the interface that all gohan per-article plugins must implement.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds the set of built-in plugins.

func DefaultRegistry

func DefaultRegistry() *Registry

DefaultRegistry returns a Registry pre-loaded with all built-in plugins.

func (*Registry) Enrich

func (r *Registry) Enrich(site *model.Site) error

Enrich runs all enabled plugins over every article in site, populating article.PluginData with each plugin's output. Call this after processing articles and before generating HTML.

func (*Registry) EnrichVirtual added in v1.0.13

func (r *Registry) EnrichVirtual(site *model.Site) error

EnrichVirtual runs all enabled SitePlugins over the full site, collecting VirtualPages and appending them to site.VirtualPages. Call this after Enrich and before generating HTML.

type SitePlugin added in v1.0.13

type SitePlugin interface {
	// Name returns the unique identifier of the plugin.
	// This key is used in config.yaml under plugins.<name>.
	Name() string

	// Enabled reports whether the plugin is active for the given config section.
	Enabled(cfg map[string]interface{}) bool

	// VirtualPages inspects the full site and returns zero or more VirtualPages
	// to be rendered by the HTML generator.
	VirtualPages(site *model.Site, cfg map[string]interface{}) ([]*model.VirtualPage, error)
}

SitePlugin is the interface for plugins that operate on the full site and generate VirtualPages — pages with no corresponding Markdown source file.

SitePlugins run after all articles have been processed and per-article plugins have been enriched. The VirtualPages they return are rendered by the HTML generator using the template named by VirtualPage.Template.

Example uses: a bookshelf page aggregating book front-matter from all articles, a reading-list page, or any cross-article summary page.

Directories

Path Synopsis
Package amazonbooks is a gohan built-in plugin that generates Amazon book cards for article templates.
Package amazonbooks is a gohan built-in plugin that generates Amazon book cards for article templates.
Package bookshelf is a gohan built-in SitePlugin that generates a bookshelf page by aggregating book entries from every article's front-matter.
Package bookshelf is a gohan built-in SitePlugin that generates a bookshelf page by aggregating book entries from every article's front-matter.

Jump to

Keyboard shortcuts

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