render

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package render turns stored records into the two human views — the kage-shape HTML site (render/html) and the yomi-shape Markdown archive (render/md). Both derive from the same view model built here (TP3), so they always agree on what a tweet says: the linkified text, the media list with relative local paths, the quoted card, the poll. The view model is pure — records and a path context in, a view struct out — so the renderers carry golden tests with no network and no clock (spec §14).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BioHTML

func BioHTML(text string) template.HTML

BioHTML linkifies a profile description the same inert way as a tweet body. It is exported because the HTML renderer builds the profile header outside the tweet view model.

func FormatCount

func FormatCount(n int) string

FormatCount renders an engagement count compactly (1.2K, 3.4M), the way X shows it, for the metric row.

func LinkifyMarkdown

func LinkifyMarkdown(text string) string

LinkifyMarkdown turns the same surface features into Markdown links for the Markdown renderer. URLs become autolinks; mentions/hashtags/cashtags link to x.com. The text is left otherwise verbatim so it reads naturally and greps. It runs over raw text and uses the same boundary rule as the HTML path.

Types

type Context

type Context struct {
	InArchive map[string]bool   // tweet id -> present
	MediaPath map[string]string // source URL -> repo-relative local path
	// FromPage is the repo-relative path of the page being rendered, so media
	// and cross-tweet links can be rewritten relative to it (spec §6.4).
	FromPage string
}

Context carries what the view model needs to resolve references: the set of tweet ids that are in the archive (so an in-archive link is relative and an outside link stays absolute), and a lookup from a media source URL to its localised repo-relative path (empty when the item is not on disk).

func NewContext

func NewContext(tweets []*x.Tweet, assets []repo.Asset) *Context

NewContext builds a render context from a record set and a media result. The caller sets FromPage per page before rendering.

func (*Context) Build

func (c *Context) Build(t *x.Tweet) TweetView

Build constructs a TweetView for one tweet under the given context. The body is linkified two ways: HTMLBody for the HTML renderer (escaped, anchor tags) and TextBody for Markdown (left raw; the md renderer links entities itself).

func (*Context) MediaSrc

func (c *Context) MediaSrc(srcURL, page string) (string, bool)

MediaSrc resolves a source URL to a path relative to page when the asset is localised, else reports false so the caller can fall back to the remote URL. It is the exported entry the renderers use for profile avatars and banners, which are not part of a tweet's media list.

type MediaView

type MediaView struct {
	Type     string // photo|video|gif
	Src      string // relative local path when localised, else the remote URL
	Local    bool
	AltText  string
	Width    int
	Height   int
	Poster   string // relative/remote preview image for video
	Unavail  bool   // true when the media could not be localised
	Duration int
}

MediaView is one renderable media item with its resolved local (or remote) source and a flag for whether it is on disk.

type PollOptionView

type PollOptionView struct {
	Label   string
	Votes   int
	Percent int
}

PollOptionView is one poll choice with a percentage for the result bar.

type TweetView

type TweetView struct {
	ID          string
	URL         string // canonical x.com permalink (the source)
	Permalink   string // page-relative link to this tweet's own local page
	AuthorName  string
	Handle      string
	Verified    bool
	AvatarSrc   string
	AvatarLocal bool
	CreatedAt   time.Time
	Stamp       string        // formatted timestamp
	HTMLBody    template.HTML // text with entities linkified, HTML-escaped (for the html renderer)
	TextBody    string        // raw text (for the markdown renderer)
	Media       []MediaView
	Poll        []PollOptionView
	PollStatus  string
	Metrics     x.Metrics
	IsReply     bool
	ReplyToUser string
	ReplyToID   string
	ReplyToRel  string // relative link to the parent when in-archive, else absolute, else ""
	IsRetweet   bool
	IsQuote     bool
	Quoted      *TweetView
	Lang        string
	Source      string
}

TweetView is the shared, presentation-agnostic view of one tweet.

Directories

Path Synopsis
Package html renders the kage-shape static site from stored records: an inert, self-contained set of pages that look like X and open with the network unplugged (spec §9).
Package html renders the kage-shape static site from stored records: an inert, self-contained set of pages that look like X and open with the network unplugged (spec §9).
Package md renders the yomi-shape Markdown archive: a plain-text mirror of the repository that reads naturally, greps, and diffs (spec §10).
Package md renders the yomi-shape Markdown archive: a plain-text mirror of the repository that reads naturally, greps, and diffs (spec §10).

Jump to

Keyboard shortcuts

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