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
- Variables
- func Slugify(name string) string
- func ValidSlug(s string) bool
- type Author
- type Handlersdeprecated
- func (h *Handlers) Create(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) Delete(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) Get(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) List(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) Update(w http.ResponseWriter, r *http.Request)
- type Input
- type Store
- func (s *Store) Create(ctx context.Context, in Input) (*Author, error)
- func (s *Store) Delete(ctx context.Context, id uuid.UUID) error
- func (s *Store) EnsureByName(ctx context.Context, name string) (uuid.UUID, error)
- func (s *Store) ForEntities(ctx context.Context, entityIDs []uuid.UUID) (map[uuid.UUID]*Author, error)
- func (s *Store) Get(ctx context.Context, id uuid.UUID) (*Author, error)
- func (s *Store) GetBySlug(ctx context.Context, slug string) (*Author, error)
- func (s *Store) List(ctx context.Context) ([]*Author, error)
- func (s *Store) Name(ctx context.Context, id uuid.UUID) (string, error)
- func (s *Store) Update(ctx context.Context, id uuid.UUID, in Input) (*Author, error)
Constants ¶
const ( MaxNameLen = 255 MaxSlugLen = 128 MaxBioLen = 5000 )
Limits mirroring the columns.
Variables ¶
var ( ErrNotFound = errors.New("author not found") ErrSlugConflict = errors.New("author slug already exists") ErrInvalid = errors.New("invalid author") )
Errors.
Functions ¶
func Slugify ¶
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 "".
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 ¶
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}.
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 (*Store) Delete ¶
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 ¶
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).