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

themekit

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package themekit is the shared catalog theme contract: validation helpers for ship-with and custom themes. The theme doctor CLI and token helpers can grow here without pulling theme markup into internal/.

Catalog themes under themes/ must pass ValidateDir with CatalogOptions. Child themes that inherit from default may omit files the parent already provides; ValidateDir walks the parent chain.

Index

Constants

View Source
const PlatformLangPrefix = "core."

PlatformLangPrefix marks keys that resolve from core/module catalogs (e.g. {{t "core.app.name"}}), not theme lang files.

Variables

View Source
var CatalogSlugs = []string{"default", "business", "magazine", "portfolio", "docs"}

CatalogSlugs are the five themes GoRun ships in themes/.

View Source
var IdentityTokens = []string{
	"--accent",
	"--gp-accent",
	"--green",
	"--bg",
	"--ink",
	"--on-accent",
	"--gp-on-accent",
	"--font",
	"--font-ui",
	"--font-heading",
	"--radius",
}

IdentityTokens are CSS custom properties site identity can drive. Catalog themes declare defaults under DataThemeSelector(slug).

View Source
var RequiredLocales = []string{"en", "ar"}

RequiredLocales are lang/<locale>.json files every catalog theme must own (parent merge is not enough for the ship-with quality bar).

View Source
var RequiredSupports = []string{"rtl", "identity"}

RequiredSupports must appear in theme.json "supports".

View Source
var RequiredTemplates = []string{
	"index.html",
	"page.html",
	"single.html",
	"archive.html",
	"taxonomy.html",
	"search.html",
	"404.html",
	"500.html",
	"page-builder.html",
	"page-contact.html",
	"form-result.html",
}

RequiredTemplates must resolve for a catalog theme (own file or inherited).

Functions

func AnyFailed

func AnyFailed(results []Result) bool

AnyFailed reports whether any result is not OK.

func AssetPath

func AssetPath(slug, rel string) string

AssetPath builds the public URL path for a theme asset (no cache buster). Templates use {{asset "…"}} at render time; this helper is for tooling.

func DataThemeSelector

func DataThemeSelector(slug string) string

DataThemeSelector returns the zero-specificity selector catalog themes use for token defaults.

func ExtractTKeys

func ExtractTKeys(dir string) ([]string, error)

ExtractTKeys returns unique {{t "…"}} keys referenced in HTML under dir (templates/, parts/, components/).

func FormatResult

func FormatResult(res Result) string

FormatResult writes a human-readable doctor line for one Result.

func MergeLang

func MergeLang(chainDirs []string, locale string) (map[string]string, error)

MergeLang merges lang/<locale>.json along chain (child first; child wins).

func MissingLangKeys

func MissingLangKeys(used []string, catalog map[string]string) []string

MissingLangKeys returns used keys absent from catalog, skipping platform keys.

func SettingKey

func SettingKey(slug, field string) string

SettingKey returns the settings store key for a theme setting field.

Types

type Issue

type Issue struct {
	Path    string `json:"path,omitempty"`
	Code    string `json:"code"`
	Message string `json:"message"`
}

Issue is one contract failure.

func LangKeyWarnings

func LangKeyWarnings(dir string, roots []string) ([]Issue, error)

LangKeyWarnings scans the theme's own HTML for {{t}} keys missing from the merged en (then ar) catalogs along the parent chain. These are soft checks for `gorun theme doctor` and do not affect ValidateDir / catalog CI.

func (Issue) String

func (i Issue) String() string

type Options

type Options struct {
	// RequireLocales requires lang/<locale>.json on the theme itself.
	RequireLocales []string
	// RequireSupports lists theme.json supports values.
	RequireSupports []string
	// RequireTemplates lists templates that must resolve via inheritance.
	RequireTemplates []string
	// RequireScreenshot requires screenshot.png at the theme root.
	RequireScreenshot bool
	// RequireHome requires front-page.html or home.html (resolved).
	RequireHome bool
	// ForbidScriptHosts fails when theme HTML/CSS references these substrings
	// (public CSP: no third-party script CDNs). Empty skips the check.
	ForbidScriptHosts []string
	// RequireTokenSelector requires the theme's primary stylesheet to declare
	// tokens under :where(html[data-theme="<slug>"]).
	RequireTokenSelector bool
}

Options configure ValidateDir. CatalogOptions is the ship-with bar.

func CatalogOptions

func CatalogOptions() Options

CatalogOptions is the shared ship-with contract.

func OptionsForSlug

func OptionsForSlug(slug string) Options

OptionsForSlug returns CatalogOptions for ship-with themes and a lighter activation-oriented check for custom themes (index.html must resolve).

type Result

type Result struct {
	Slug   string  `json:"slug"`
	OK     bool    `json:"ok"`
	Issues []Issue `json:"issues,omitempty"`
}

Result is the outcome of ValidateDir.

func DoctorRoots

func DoctorRoots(roots []string) []Result

DoctorRoots validates every theme.json directory under roots (first root wins per slug). Catalog slugs use CatalogOptions; others use OptionsForSlug.

func DoctorTheme

func DoctorTheme(dir string, roots []string) Result

DoctorTheme validates one theme directory using OptionsForSlug(slug).

func ValidateCatalogRoot

func ValidateCatalogRoot(root string) []Result

ValidateCatalogRoot validates every CatalogSlug under root.

func ValidateDir

func ValidateDir(dir string, roots []string, opts Options) Result

ValidateDir checks one theme directory against opts. roots are searched for parents (same order as GORUN_THEMES). slug is the directory basename when empty.

Jump to

Keyboard shortcuts

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