Help us shape the future of Go! Take the 2026 Go Developer Survey

seo

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package seo renders SEO meta tags, sitemap.xml and robots.txt.

contract.go holds the frozen wave-0 contract (types and interfaces only). The implementation arrives in wave 1.

Index

Constants

View Source
const (
	SettingSiteTitle          = "site.title"
	SettingSiteTagline        = "site.tagline"
	SettingSiteBaseURL        = "site.base_url"
	SettingTitleTemplate      = "seo.title_template"
	SettingDefaultDescription = "seo.default_description"
	SettingDefaultOGImage     = "seo.default_og_image"
	SettingRobotsTxt          = "seo.robots_txt"

	// DefaultTitleTemplate formats page titles; {title} and {site} are
	// replaced.
	DefaultTitleTemplate = "{title} – {site}"
)

Settings keys read by the service (site.* are owned by the admin module).

View Source
const FilterSitemapEntry = "seo.sitemap_entry"

FilterSitemapEntry runs for every sitemap entry with a *SitemapEntry whose Loc is the fallback path (menus.ContentPath / TermPath / ArchivePath). Filters may rewrite Loc (a site path or absolute URL) or clear it to drop the entry, and must return the *SitemapEntry. The theme module subscribes and sets Loc to the theme permalink.

Variables

This section is empty.

Functions

func DefaultRobots

func DefaultRobots(base string) string

DefaultRobots is the robots.txt used when seo.robots_txt is unset.

func ValidateSetting

func ValidateSetting(key, value string) (string, error)

ValidateSetting validates and normalises one Settings → SEO value exactly as the admin screen does: SettingTitleTemplate (blank → default; must contain {title}, max 200 runes), SettingDefaultDescription (max 500 runes), SettingDefaultOGImage (blank or an absolute http(s) URL) and SettingRobotsTxt (CRLF → LF, max 10 KB, no NUL). It returns the value to store or a *SettingError; other keys get code "seo.error.key".

Types

type Meta

type Meta struct {
	Title         string          `json:"title"`
	Description   string          `json:"description"`
	Canonical     string          `json:"canonical"`
	Robots        string          `json:"robots"`
	OGTitle       string          `json:"og_title"`
	OGDescription string          `json:"og_description"`
	OGImage       string          `json:"og_image"`
	TwitterCard   string          `json:"twitter_card"`
	Schema        json.RawMessage `json:"schema,omitempty"`
}

func FromMap

func FromMap(m map[string]any) Meta

FromMap reads a content item's SEO map; unknown keys and non-string values are ignored; "schema" may be any JSON value.

func (Meta) ToMap

func (m Meta) ToMap() map[string]any

ToMap is the inverse of FromMap; empty fields are omitted.

type Module

type Module struct{}

Module is the seo kernel.Module. It owns no tables (settings only) and mounts no public routes: the site/theme module serves /sitemap.xml and /robots.txt through the Service.

func New

func New() *Module

New returns the seo module.

func (*Module) Catalogs

func (*Module) Catalogs() fs.FS

Catalogs implements kernel.CatalogProvider.

func (*Module) Migrations

func (*Module) Migrations() fs.FS

Migrations implements kernel.Module.

func (*Module) Name

func (*Module) Name() string

Name implements kernel.Module.

func (*Module) Register

func (*Module) Register(d *kernel.Deps) error

Register publishes kernel.ServiceSEO and the Settings → SEO screen.

type Service

type Service interface {
	Render(ctx context.Context, m Meta, fallback Meta) template.HTML
	Sitemap(ctx context.Context) ([]byte, error)
	// Entries is the sitemap as data (absolute Locs), for admin screens.
	Entries(ctx context.Context) ([]SitemapEntry, error)
	Robots(ctx context.Context) string
}

type SettingError

type SettingError struct{ Key, Code string }

SettingError is a rejected SEO setting value; Code is an i18n key.

func (*SettingError) Error

func (e *SettingError) Error() string

type SitemapEntry

type SitemapEntry struct {
	Loc     string
	LastMod string
	Item    *content.Item
	Term    *taxonomy.Term
	Type    *content.Type
}

SitemapEntry is one <url>; Item, Term or Type says what it points to.

Jump to

Keyboard shortcuts

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