identity

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package identity holds the site's declared author, as the one Person its structured data names.

A selfdoc site has one author, declared in selfdoc.json under "author" and required there. Every emitter that needs an identity -- the per-page article's author and publisher, the front page's standalone entity, the CV page's profile -- reads it through this package, so a site states the same Person everywhere and states it once.

What used to happen instead is why the block is required: with no author declared, the emitters minted {"@type": "Organization", "name": <project_name>}, inventing an organisation out of a directory name and publishing it as fact. That path is gone. A caller that reaches these functions without a declared author gets a refusal naming the config key.

Index

Constants

This section is empty.

Variables

View Source
var AuthorKeys = []string{"name", "url", "same_as"}

AuthorKeys is every key an "author" block may carry, mirroring the config schema.

View Source
var ErrNoDeclaredAuthor = errors.New(
	"structured data needs the declared author, and this build has " +
		"none with both 'name' and 'url'. selfdoc.json requires " +
		`"author": {"name": ..., "url": ...}; there is no inferred ` +
		"author and no organisation is minted from the project name.")

ErrNoDeclaredAuthor is the refusal every entry point returns when the build has no author with both a name and a URL. It names the config key rather than falling back to anything: there is no inferred author.

Functions

This section is empty.

Types

type Entity

type Entity []Property

Entity is a JSON-LD entity as an ordered property list.

The order is part of the output, not an implementation detail: the emitted structured data is rendered by walking the entity, and a Person reads "@context" (when it stands as its own document), then "@type", "name", "url", "sameAs", then whatever the page contributed. A Go map carries no order, so the entity is a slice.

func PersonEntity

func PersonEntity(author map[string]any, withContext bool, extra Entity) (Entity, error)

PersonEntity returns the declared author as a schema.org Person.

withContext adds "@context" for an entity emitted as its own JSON-LD document rather than nested inside one. extra carries the properties only a particular page knows -- a CV's occupation, languages and schools -- and is merged after the identity properties, each entry skipped when its value is empty. An extra whose key is one of the identity properties replaces that property where it already stands, so the property order does not change.

It returns ErrNoDeclaredAuthor when no author is declared.

func (Entity) Get

func (e Entity) Get(key string) (any, bool)

Get returns the value of key and whether the entity carries it.

func (Entity) Keys

func (e Entity) Keys() []string

Keys returns the entity's property names in order.

func (*Entity) Set

func (e *Entity) Set(key string, value any)

Set assigns key, replacing the value in place when the entity already carries that key and appending it at the end otherwise -- the behavior of assigning into a Python dict, which is what the callers of PersonEntity were written against.

type Property

type Property struct {
	Key   string
	Value any
}

Property is one property of a JSON-LD entity: its name and its value.

Jump to

Keyboard shortcuts

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