seo

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 13 Imported by: 0

README

SEO plugin

plugins/seo adds a meta group with an overview, localized title and description, an optional upload image, and a live search-result preview. The fields use normal access, validation, localization, drafts, versions, REST routes, and generated types.

seo.New(seo.Config{
	Collections:       []schema.CollectionSlug{"pages", "posts"},
	Globals:           []schema.CollectionSlug{"site-settings"},
	UploadsCollection: "media",
	TabbedUI:          true,
	GenerateTitle: func(ctx seo.GenerateContext) (string, error) {
		return ctx.Document["title"].(string) + " | Example", nil
	},
	GenerateURL: func(ctx seo.GenerateContext) (string, error) {
		return "https://example.com/" + ctx.ID, nil
	},
})

Add seo.New(...) to the application's Go config and run ridu generate. Generated projects already include @riducms/plugin-seo; existing projects must install a version compatible with the Go plugin before generating. Configure the plugin in Go because it requires resource options and may use callbacks.

Generator callbacks receive the current unsaved form snapshot, resource definition, document ID, locale, actor collection, actor-aware endpoint context, and local API. Their endpoints require an authenticated actor and the corresponding collection/global access before running. Generator responses are discarded if the draft changes while a request is pending.

Fields can replace or extend the ordered default definitions. The exported Overview, MetaTitle, MetaDescription, MetaImage, and Preview constructors support direct placement. Collections and Globals select automatic field injection. Directly placed SEO fields can also use generator endpoints outside those selectors. Ridu checks the actor's resource access before invoking a generator.

Direct metadata constructors are localized by default. Without localization, use the injected defaults or fields configured with the SEO admin component.

See the SEO guide for installation, callbacks, field placement, migrations, and verification.

Documentation

Overview

Package seo contributes Payload-familiar search metadata fields and a paired admin authoring experience without moving executable generators into the schema manifest.

Index

Constants

View Source
const (
	// Key is the stable backend/admin plugin identity.
	Key = "seo"
	// AdminPluginPairingVersion changes when the Go and admin packages cease to
	// understand the same renderer configuration.
	AdminPluginPairingVersion = 1
)

Variables

This section is empty.

Functions

func MetaDescription

func MetaDescription(hasGenerator bool, options ...field.StringOption) field.Definition

MetaDescription returns the localized built-in textarea field with the SEO renderer.

func MetaImage

func MetaImage(collection schema.CollectionSlug, hasGenerator bool, options ...field.UploadOption) field.Definition

MetaImage returns the localized upload reference with the SEO renderer.

func MetaImageWithConfig

func MetaImageWithConfig(selected MetaImageConfig, options ...field.UploadOption) field.Definition

MetaImageWithConfig customizes the direct image field's presentation.

func MetaTitle

func MetaTitle(hasGenerator bool, options ...field.StringOption) field.Definition

MetaTitle returns the localized built-in text field with the SEO renderer.

func Overview

func Overview(options ...field.CommonOption) field.Definition

Overview returns the default presentation-only checks summary.

func OverviewWithConfig

func OverviewWithConfig(selected OverviewConfig, options ...field.CommonOption) field.Definition

OverviewWithConfig returns overview checks mapped to explicit field paths and guidance bounds. Zero values use the default meta paths and bounds.

func Preview

func Preview(hasGenerator bool, options ...field.CommonOption) field.Definition

Preview returns the default presentation-only search-result preview.

func PreviewWithConfig

func PreviewWithConfig(selected PreviewConfig, options ...field.CommonOption) field.Definition

PreviewWithConfig returns a search preview mapped to explicit stored paths.

Types

type Config

type Config struct {
	Collections         []schema.CollectionSlug
	Globals             []schema.CollectionSlug
	UploadsCollection   schema.CollectionSlug
	TabbedUI            bool
	Fields              FieldsOverride
	GenerateTitle       GenerateText
	GenerateDescription GenerateText
	GenerateImage       GenerateImage
	GenerateURL         GenerateText
}

Config selects resources and executable generation behavior.

type FieldsOverride

type FieldsOverride func(defaultFields []field.Definition) ([]field.Definition, error)

FieldsOverride receives the immutable default field definitions and returns the complete ordered contents of the meta group.

type GenerateContext

type GenerateContext struct {
	Context    ridu.PluginEndpointContext
	Document   map[string]any
	ID         string
	Locale     schema.LocaleCode
	Collection *ridu.Collection
	Global     *ridu.Global
}

GenerateContext is the trusted runtime input for one generator. Document is the current unsaved admin form snapshot. Collection and Global are detached authoring definitions; exactly one is non-nil.

type GenerateImage

type GenerateImage func(GenerateContext) (string, error)

GenerateImage produces the stable ID of an upload document.

type GenerateText

type GenerateText func(GenerateContext) (string, error)

GenerateText produces a title, description, or preview URL.

type MetaImageConfig

type MetaImageConfig struct {
	Collection  schema.CollectionSlug
	Generate    bool
	Label       string
	Description string
}

MetaImageConfig customizes the direct image constructor without composing duplicate-sensitive field options over the Payload-compatible defaults.

type OverviewConfig

type OverviewConfig struct {
	Label           string
	TitlePath       string
	DescriptionPath string
	ImagePath       string
	TitleMin        int
	TitleMax        int
	DescriptionMin  int
	DescriptionMax  int
}

OverviewConfig maps the presentation-only overview checks to stored fields.

type Plugin

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

Plugin is one configured SEO extension.

func New

func New(config Config) *Plugin

New returns one compiled plugin. Slices are copied so later application mutation cannot change target selection or endpoint admission.

func (*Plugin) Descriptor

func (*Plugin) Descriptor() ridu.PluginDescriptor

Descriptor exposes only deterministic build metadata. Generators remain executable Go values owned by the runtime plugin instance.

func (*Plugin) Endpoints

func (plugin *Plugin) Endpoints() []ridu.PluginEndpoint

Endpoints contributes generation calls below /api/plugins/seo/. All are declared for a stable OpenAPI surface; absent callbacks return an empty value.

func (*Plugin) Key

func (*Plugin) Key() string

Key implements ridu.Plugin.

func (*Plugin) TransformConfig

func (plugin *Plugin) TransformConfig(config ridu.Config) (ridu.Config, error)

TransformConfig injects one meta group into each selected resource.

type PreviewConfig

type PreviewConfig struct {
	Generate        bool
	Label           string
	TitlePath       string
	DescriptionPath string
}

PreviewConfig maps the search preview to stored title and description fields. Generate enables the URL callback control.

Jump to

Keyboard shortcuts

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