Documentation
¶
Overview ¶
Package socialmeta builds the Open Graph + Twitter Card <meta> tag block emitted on the homepage, pad page, and timeslider so URLs shared in chat apps (WhatsApp, Signal, Slack, ...) unfurl with a preview.
Ported from upstream etherpad-lite (PR #7635, src/node/utils/socialMeta.ts).
Security boundary: pad names from the URL are user-controlled. All values are HTML-escaped before interpolation to prevent reflected XSS via crafted pad IDs. og:url and og:image are built from settings.publicURL when set (operator-trusted); otherwise from the request's protocol + Host with strict Host validation so a crafted Host header cannot appear in og:url.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Kind ¶
type Kind string
Kind identifies which template the meta block is being rendered into. Affects the og:title composition.
type Locales ¶
Locales maps a language tag (e.g. "en", "de", "de-AT") to its translation table for that language. socialmeta only reads the socialDescriptionKey entry; the rest of the table is ignored.
type Opts ¶
type Opts struct {
Req RequestInfo
Settings Settings
AvailableLangs map[string]struct{}
Locales Locales
Kind Kind
PadName string // ignored for KindHome
}
Opts collects everything needed to render the meta block.
type RequestInfo ¶
type RequestInfo struct {
// Scheme is "http" or "https". Anything else is normalised to "http".
Scheme string
// Host is the raw Host header (or X-Forwarded-Host if the router has
// already resolved it). Will be strictly validated.
Host string
// Path is the request pathname (no query string).
Path string
// AcceptLanguage is the raw Accept-Language header for language
// negotiation. May be empty.
AcceptLanguage string
}
RequestInfo bundles the per-request facts the renderer needs. The package avoids importing fiber/http directly so callers can adapt from any router.
func FromHTTPRequest ¶
func FromHTTPRequest(r *http.Request) RequestInfo
FromHTTPRequest builds a RequestInfo from a net/http request. Fiber callers can build one directly from fiber.Ctx.
type Settings ¶
type Settings struct {
Title string
Favicon string
PublicURL string
// DescriptionOverride: when non-nil and stringifies to non-empty,
// used verbatim for og:description / twitter:description regardless
// of negotiated language. Operators set this via settings.json
// (socialMeta.description) to fix the case where preview crawlers
// don't send Accept-Language and hit the English fallback.
//
// Type is `any` because viper/mapstructure may surface a string,
// number, or boolean depending on whether the value came from a
// literal or env-var coercion in settings.json. The resolver
// stringifies and treats empty/whitespace as unset. Upstream
// #7691 / #7692.
DescriptionOverride any
}
Settings is the narrow shape socialmeta actually reads from the global Settings struct. Keeps the package decoupled from the full Settings surface.