socialmeta

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Render

func Render(o Opts) string

Render returns the HTML <meta> tag block (no surrounding tags, no trailing newline). Safe to drop into a templ template via @templ.Raw or equivalent escape-bypass mechanism.

Types

type Kind

type Kind string

Kind identifies which template the meta block is being rendered into. Affects the og:title composition.

const (
	KindHome       Kind = "home"
	KindPad        Kind = "pad"
	KindTimeslider Kind = "timeslider"
)

type Locales

type Locales map[string]map[string]string

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
	// ProxyPath is the cleaned path prefix a reverse proxy serves Etherpad
	// under (utils.RequestProxyPath), "" at the root. It goes in front of
	// the path in og:url and og:image when they are built from the
	// request; a publicURL is taken as it is, as in etherpad-lite.
	ProxyPath 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.

Jump to

Keyboard shortcuts

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