author

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package author is the legacy authors table, kept for rollback. It is NOT the source of bylines any more: people are entities of the built-in `person` type (internal/person) and a post credits one through byline_person_id.

What remains here: the Store the person resolver uses to keep a mirror row per person (so the previous binary still renders bylines after a rollback), the slug helpers (Slugify, ValidSlug) and the deprecated /api/v1/authors handlers. Rows are never read to render a page, a feed or JSON-LD. The table and entities.author_id stay until a contract release drops them (docs/UPGRADES.md).

Index

Constants

View Source
const (
	MaxNameLen = 255
	MaxSlugLen = 128
	MaxBioLen  = 5000
)

Limits mirroring the columns.

Variables

View Source
var (
	ErrNotFound     = errors.New("author not found")
	ErrSlugConflict = errors.New("author slug already exists")
	ErrInvalid      = errors.New("invalid author")
)

Errors.

Functions

func Slugify

func Slugify(name string) string

Slugify makes a slug of a name: lower-case ASCII letters and digits, runs of anything else as one hyphen, at most MaxSlugLen. Non-ASCII letters and digits are dropped, which is the rule the public byline page has always used, so existing /author/{slug} URLs do not change.

A name with no ASCII letter or digit left (李明, Ελένη, 🙂) never gives "": accents are stripped first where Unicode allows ("Ñ" is "n"), and otherwise the slug is "author-" and eight hex digits of a hash of the lower-cased name, so the same name always lands on the same author. Only a blank name gives "".

func ValidSlug

func ValidSlug(s string) bool

ValidSlug reports whether s is a well-formed author slug.

Types

type Author

type Author struct {
	ID            uuid.UUID  `json:"id"`
	Slug          string     `json:"slug"`
	Name          string     `json:"name"`
	Bio           string     `json:"bio"`
	AvatarMediaID *uuid.UUID `json:"avatar_media_id,omitempty"`
	// AvatarURL is the public URL of the avatar media row, "" without one.
	AvatarURL string    `json:"avatar_url,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Author is a byline.

type Handlers deprecated

type Handlers struct {

	// OnChange runs after a write, for example to purge rendered pages.
	OnChange func(r *http.Request)
	// contains filtered or unexported fields
}

Handlers is the admin API of authors (/api/v1/authors).

Deprecated: authors are people now. Manage them as entities of the `person` type (Admin > People, or the entities API). This API only edits the rollback mirror: edits here do not change any byline on the site.

func NewHandlers

func NewHandlers(store *Store, logger *slog.Logger) *Handlers

NewHandlers returns the admin handlers over store.

func (*Handlers) Create

func (h *Handlers) Create(w http.ResponseWriter, r *http.Request)

Create handles POST /authors.

func (*Handlers) Delete

func (h *Handlers) Delete(w http.ResponseWriter, r *http.Request)

Delete handles DELETE /authors/{id}.

func (*Handlers) Get

func (h *Handlers) Get(w http.ResponseWriter, r *http.Request)

Get handles GET /authors/{id}.

func (*Handlers) List

func (h *Handlers) List(w http.ResponseWriter, r *http.Request)

List handles GET /authors.

func (*Handlers) Update

func (h *Handlers) Update(w http.ResponseWriter, r *http.Request)

Update handles PUT /authors/{id}.

type Input

type Input struct {
	Name          string     `json:"name"`
	Slug          string     `json:"slug,omitempty"`
	Bio           string     `json:"bio"`
	AvatarMediaID *uuid.UUID `json:"avatar_media_id,omitempty"`
}

Input is the writable part of an author. Slug defaults to the slug of Name.

type Store

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

Store is the persistence of authors.

func NewStore

func NewStore(db *database.DB) *Store

NewStore returns a store over db.

func (*Store) Create

func (s *Store) Create(ctx context.Context, in Input) (*Author, error)

Create stores a new author.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id uuid.UUID) error

Delete removes an author and its /author/{slug} page. Its entities lose the reference but keep the plain-text byline in their attributes (it is content), so saving one of them again recreates the author; clear the byline on the entity to remove it for good.

func (*Store) EnsureByName

func (s *Store) EnsureByName(ctx context.Context, name string) (uuid.UUID, error)

EnsureByName returns the id of the author whose slug is the slug of name, creating the author when there is none. Only blank or over-long names are invalid; a name without ASCII letters gets a hash slug (see Slugify).

func (*Store) ForEntities

func (s *Store) ForEntities(ctx context.Context, entityIDs []uuid.UUID) (map[uuid.UUID]*Author, error)

ForEntities returns the author of each given entity id (entities without one are absent).

func (*Store) Get

func (s *Store) Get(ctx context.Context, id uuid.UUID) (*Author, error)

Get returns an author by id.

func (*Store) GetBySlug

func (s *Store) GetBySlug(ctx context.Context, slug string) (*Author, error)

GetBySlug returns an author by slug.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]*Author, error)

List returns every author by name.

func (*Store) Name

func (s *Store) Name(ctx context.Context, id uuid.UUID) (string, error)

Name returns an author's name.

func (*Store) Update

func (s *Store) Update(ctx context.Context, id uuid.UUID, in Input) (*Author, error)

Update replaces an author's fields. A renamed author keeps its entities; the plain-text byline stored in their attributes follows the new name.

Jump to

Keyboard shortcuts

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