seo

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 14 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.

Each factory returns a concrete immutable field. Refine it directly; access, hooks and editor configuration follow every placement:

title := seo.MetaTitle(true).Localized(false).Required().MaxLength(80)
image := seo.MetaImage(seo.MetaImageConfig{Collection: "media"}).Localized(false)
overview := seo.Overview(seo.OverviewConfig{})
preview := seo.Preview(seo.PreviewConfig{Generate: true})

MetaTitle, MetaDescription and MetaImage are localized by default. Use .Localized(false) when placing them in an application without localization. Overview, image and preview settings are policy structs; ordinary field refinements use the concrete fluent surface.

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) field.TextareaField

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

func MetaImage

func MetaImage(selected MetaImageConfig) field.UploadField

MetaImage returns the localized upload reference with the SEO renderer.

func MetaTitle

func MetaTitle(hasGenerator bool) field.TextField

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

func Overview

func Overview(selected OverviewConfig) field.LayoutField

Overview returns presentation-only checks mapped to explicit stored field paths. Zero values use the default meta paths and guidance bounds.

func Preview

func Preview(selected PreviewConfig) field.LayoutField

Preview returns a presentation-only 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.Fields) (field.Fields, 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 configures the upload target and image presentation.

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 validates resource selection and snapshots generator context. Field injection runs in the canonical graph phase after resource transforms.

func (*Plugin) TransformFields added in v0.2.0

func (plugin *Plugin) TransformFields(context core.FieldGraphContext, graph field.Fields) (field.Fields, error)

TransformFields attaches the SEO group through the same immutable graph used by application fields, preserving behavior on every existing node.

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