Documentation
¶
Overview ¶
Package web holds Akari's public server-rendered pages and their view helpers.
Package web holds Akari's public server-rendered pages and their view helpers.
Package web holds Akari's public server-rendered pages and their view helpers.
Index ¶
- Constants
- Variables
- func BasePath(ctx context.Context) string
- func FmtCost(usd float64) string
- func FmtPercent(f float64) string
- func FmtTokens(n int64) string
- func FmtTokensCompact(n int64) string
- func Href(ctx context.Context, path string) templ.SafeURL
- func IsGrade(v string) bool
- func IsLocalKind(kind string) bool
- func IsOutcome(v string) bool
- func ParseRange(key string) string
- func ProjectLabel(kind, name, key string) string
- func ProjectTitle(p store.ProjectSummary) string
- func PublicOverviewOGPath(username string) string
- func PublicOverviewPath(username string) string
- func PublicPath(publicID string) string
- func PublicProjectOGPath(id int64) string
- func PublicProjectPath(id int64) string
- func PublicSessionOGPath(publicID string) string
- func RangeBounds(key string) bool
- func RangeSince(key string, now time.Time) time.Time
- func SelectedUserIDs(raw []string, users []store.User) []int64
- func SessionPageTitle(d store.SessionDetail) string
- func SessionProjectLabel(d store.SessionDetail) string
- func StaticURL(ctx context.Context, path string) templ.SafeURL
- func TrendBucket(key string) string
- func WithBasePath(ctx context.Context, prefix string) context.Context
- type DateRange
- type OGMeta
Constants ¶
const DefaultRange = "year"
DefaultRange is the window the overview opens on: a trailing year, wide enough to read seasonality and longer trends on the activity grid without jumping to all of history.
const DefaultSessionLimit = 100
DefaultSessionLimit is the global feed's page size, the fixed slice each request reads. "Show more" does not grow this: the client passes a keyset cursor and appends the next page of the same size, so depth is unbounded and the page cost stays flat.
const UnscoredKey = "unscored"
UnscoredKey is the sentinel a drill-through link and the Grade filter carry for the unscored grade bucket, since the empty string reads as "no grade filter".
Variables ¶
var DateRanges = []DateRange{
{Key: "7d", Label: "7 days", Days: 7},
{Key: "30d", Label: "30 days", Days: 30},
{Key: "90d", Label: "90 days", Days: 90},
{Key: "year", Label: "Year", Days: 365},
{Key: "all", Label: "All", Days: 0},
}
DateRanges are the windows the overview offers, narrowest first. The selector renders them in this order, and ParseRange validates against their keys.
var Static embed.FS
Static holds the embedded public assets served under /static/.
Functions ¶
func BasePath ¶ added in v0.6.5
BasePath is the current render's external path prefix, or "" when the deployment serves from the origin root.
func FmtCost ¶
FmtCost renders a USD cost. Sub-cent costs still show enough precision to be meaningful.
func FmtPercent ¶
FmtPercent renders a 0..1 fraction as a whole-number percent, for the cache hit rate. A real but tiny rate (under 1%) rounds up to 1% rather than 0%, so a scope that did hit the cache never reads as a total miss; a true zero stays 0%.
func FmtTokensCompact ¶
FmtTokensCompact renders a token count to a short magnitude (2.1B, 1.7M, 63.0k, 412), for the feed's inline figure where the exact value lives in the hover card. The thousands-separated FmtTokens stays the form for places that show the full number. Keep these buckets aligned with the React formatter so a figure reads the same on either surface.
func Href ¶ added in v0.6.5
Href externalizes a rooted path for the current render: the base path plus the path. Every literal href, form action, and hx-get a template emits must pass through here, because the browser resolves them against the external URL space, not the server's stripped internal one. The prefix is validated at the trust boundary (config.NormalizePathPrefix), so the concatenation is safe to mark as a SafeURL.
func IsGrade ¶ added in v0.2.2
IsGrade reports whether v is a grade the session list can filter by: a letter A..F or the unscored sentinel. The handler uses it to reject a tampered ?grade= value.
func IsLocalKind ¶
IsLocalKind reports whether a project kind is one of the non-remote kinds (standalone or orphaned), which are grouped and labeled apart from git-remote projects in the UI.
func IsOutcome ¶ added in v0.2.2
IsOutcome reports whether v is a filterable outcome, so the handler can reject a tampered ?outcome= value.
func ParseRange ¶
ParseRange normalizes a range query value to a known key, falling back to the default for anything empty or unrecognized.
func ProjectLabel ¶ added in v0.3.0
ProjectLabel is the folder-name-or-remote-key choice SessionProjectLabel makes, taking the three fields directly so the session OG card (which reads a store.SessionCard, not a full SessionDetail) resolves its heading through the same rule the page's <h1> uses.
func ProjectTitle ¶
func ProjectTitle(p store.ProjectSummary) string
ProjectTitle is the heading shown for a project. A remote project shows its canonical remote key; a standalone or orphaned project shows its folder name, since its synthetic key ("local:machine:path") is an internal detail.
func PublicOverviewOGPath ¶ added in v0.3.0
PublicOverviewOGPath is the path of the Open Graph preview card for a user's published overview, the /u/<username>/og.png the page advertises as og:image and the route serves the rendered PNG from. It is PublicOverviewPath with the card suffix, so the page tag and the route stay one definition rather than two string literals that could drift.
func PublicOverviewPath ¶
PublicOverviewPath is the plain-string path of a user's public usage overview, rooted at /u/<username>. The username is path-escaped so an unusual character cannot break the URL or escape the segment.
func PublicPath ¶
PublicPath is the plain-string public URL, shown to the owner as the shareable link to copy.
func PublicProjectOGPath ¶ added in v0.3.0
PublicProjectOGPath is the path of the Open Graph preview card for a project's published overview, the /p/<id>/og.png the page advertises as og:image and the route serves the rendered PNG from. Built off PublicProjectPath so the tag and the route share one definition.
func PublicProjectPath ¶ added in v0.2.5
PublicProjectPath is the plain-string path of a project's public usage overview, rooted at /p/<id>.
func PublicSessionOGPath ¶ added in v0.3.0
PublicSessionOGPath is the path of the Open Graph preview card for a published session, the /s/<public_id>/og.png the page advertises as og:image and the route serves the rendered PNG from. Built off PublicPath so the tag and the route share one definition.
func RangeBounds ¶ added in v0.2.2
RangeBounds reports whether a range key names a bounded trailing window (a known key with a positive day span). It is false for "all", the empty string, and any unknown value, which the sessions feed treats as all-history: those add no ?range param, keeping the bare feed unbounded. It is the whitelist the feed's range param passes through (like IsOutcome / IsGrade for their params), so a stale or hand-edited ?range never bounds the list to a made-up window.
func RangeSince ¶
RangeSince converts a range key to the lower time bound to pass to the store, measured back from now. The "all" window (zero Days) returns the zero time, which the store reads as "no bound".
func SelectedUserIDs ¶
SelectedUserIDs parses the overview's repeated ?user= ids against the known accounts, keeping only ids that name a real user and returning them in the users-list order. A tampered, stale, or non-numeric id silently drops out, and the stable order keeps the collapsed chips from reshuffling between requests.
func SessionPageTitle ¶ added in v0.2.6
func SessionPageTitle(d store.SessionDetail) string
SessionPageTitle is the browser-tab title for a session view: the session's own summary when it has one (the same line the page's <h1> shows), else a stable "<project> session" label. The public session shell and its OG card both use it, so a shared link and the in-app tab read the same rather than one saying "Session #42" and the other the project name.
func SessionProjectLabel ¶
func SessionProjectLabel(d store.SessionDetail) string
SessionProjectLabel is the project name shown in a session header: the folder name for a local session, the remote key otherwise. It keeps the synthetic "local:machine:path" key out of the heading.
func StaticURL ¶ added in v0.5.6
StaticURL fingerprints an embedded asset so a newly deployed binary cannot reuse client code cached from an older HTML/data contract. The asset bytes are immutable for the process lifetime, so build the lookup once and keep templates to a map read. The render context carries the deployment's external path prefix (see BasePath), which lands in front of the rooted asset path.
func TrendBucket ¶ added in v0.3.0
TrendBucket picks the time-bucket unit the Insights trend charts aggregate a range into: daily for the short windows (7d/30d) where a day still carries enough sessions to read, weekly for the long windows (90d/year/all) where daily points would be noise. The choice is the same for every chart in a view, so all the trend series share one bucket grid and the range selector windows them together. An unknown key falls back to the default range's unit, so a stale ?range still renders a sane grid.
func WithBasePath ¶ added in v0.6.5
WithBasePath returns a context carrying the external path prefix akari is served under for this request ("" for a root deployment), for the httpapi render path to attach before a component renders.
Types ¶
type DateRange ¶
DateRange is one option in the trailing-window selector. Days is the width of the window; a zero Days means all of history (no lower bound).
type OGMeta ¶
type OGMeta struct {
Title string
Description string
// Image is the absolute URL of the preview card. Open Graph requires an absolute
// URL here, so the handler builds it from the request origin; empty omits it.
Image string
// URL is the absolute canonical URL of the page; empty omits og:url.
URL string
}
OGMeta carries the Open Graph and Twitter card metadata a public page emits so a shared link unfurls with a title, description, and preview image. The zero value emits only the basic title tags; Image (an absolute URL) switches the Twitter card to the large-image form and adds og:image. Description and URL are optional.