publicpages

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: AGPL-3.0 Imports: 67 Imported by: 0

Documentation

Overview

Package publicpages serves the pages subscribers see (spec 5.12, 7.12), server-rendered with html/template under the layout of internal/publicurl:

/p/{workspace}/subscribe[/{form}]      hosted subscribe page (GET, POST)
/p/{workspace}/confirm/{token}         double opt-in confirmation
/p/{workspace}/preferences[/{token}]   preference center (or ask for a link)
/p/{workspace}/unsubscribe/{token}     unsubscribe page; POST is RFC 8058 one-click
/p/{workspace}/view/{token}            an email in the browser
/p/{workspace}/archive[/{issue}[/{lang}]] public archive, archive.rss, sitemap.xml
/p/{workspace}/forms/{id}.js           embed script, /session and /submit
/p/_/…                                 stylesheet, fonts, scripts

A workspace's verified custom domain serves the same pages at its root (news.acme.io/subscribe). The pages work without JavaScript and cookies, load no third-party code (Cloudflare Turnstile only on a challenge page), run under a strict CSP without inline scripts or styles, and carry full metadata; every page reached through a signed link is noindex.

Index

Constants

View Source
const FlashCookie = "rc_flash"

FlashCookie carries a one-time toast to the next page of the site.

View Source
const TokenEvent linktoken.Kind = 194

TokenEvent signs a registrant's calendar file (the joining link is in it).

Variables

This section is empty.

Functions

func FacePath

func FacePath(faces, key int, hex string) string

FacePath is a face image's path under /p/_/ with its colour ("0f766e").

func RegisterAPI

func RegisterAPI(h huma.API, p *Handler)

RegisterAPI adds the preview operation.

func RegisterSellAPI

func RegisterSellAPI(h huma.API, p *Handler)

RegisterSellAPI adds the page builder's canvas and preview operations.

Types

type Browser

type Browser interface {
	BrowserHTML(ctx context.Context, ws *store.Workspace, campaignID, messageID uuid.UUID, html string) string
	BrowserLinks(ctx context.Context, ws *store.Workspace, campaignID uuid.UUID) map[string]string
}

Browser gives emails shown in the browser (view online, the archive) their version of conditional content and their poll and survey links (design expansion, X11). A message's reader gets their version; the archive's matches no condition.

type Handler

type Handler struct {
	Pool     *pgxpool.Pool
	Q        *store.Queries
	Forms    *forms.Service
	Audience *audience.Service
	Tokens   *linktoken.Signer
	URLs     publicurl.Builder
	Log      *slog.Logger
	// SPA answers root paths on hosts that aren't a custom domain.
	SPA http.Handler
	// LandingURL is where "Sent with ReputeCast" points.
	LandingURL string
	// Notifications is transactional mail's Optional categories (nil:
	// the preference center has no such section).
	Notifications Notifications
	Now           func() time.Time
	// Website serves the publication website's pages (site.go); nil: the
	// archive alone.
	Website *website.Service
	// Polls answers the poll and survey pages (nil: they answer 404).
	Polls *polls.Service
	// Browser gives emails shown in the browser their version of
	// conditional content and their poll links (nil: as stored).
	Browser Browser
	// Earn serves the upgrade page, its welcome page and the billing
	// links, and the paid parts of the preference center (nil: none).
	Earn *earn.Service
	// Pages and Products serve landing and sales pages, the shop, checkout
	// and downloads (design expansion phase 7, sell*.go; nil: none).
	Pages    *pagesvc.Service
	Products *products.Service
	// Offers serves the hosted cancel page with its retention offer (X17;
	// nil: the cancel link opens the portal's cancel step).
	Offers *offers.Service
	// Gifts serves the gift page, the page after paying and the redeem
	// page (X17; nil: none).
	Gifts *gifts.Service
	// Sponsors serves shared sponsor reports at /r/{token} (X17; nil: none).
	Sponsors *sponsors.Service
	// TextTerms writes the text message terms page (nil: it answers 404).
	TextTerms TextTerms
	// Recipients add the per-reader variables of blocks (Grow's Referral
	// block) to view online; nil adds none.
	Recipients func() []liquid.RecipientData
	// Referrals and Recommendations serve Grow's pages (grow.go); nil
	// leaves them out.
	Referrals       func() *referrals.Service
	Recommendations func() *recommendations.Service
	// TextPrefs adds the preference center's Texts switches (nil: none).
	TextPrefs TextPrefs
	// Push adds web push to the pages (design expansion, X22): the prompt
	// on the publication website's pages and "Turn off notifications in
	// this browser" on the preference center (nil: neither).
	Push PushPages
	// contains filtered or unexported fields
}

func (*Handler) ApprovalPreview

func (h *Handler) ApprovalPreview(ctx context.Context, ws *store.Workspace, postID uuid.UUID) (string, error)

ApprovalPreview is the approval review's web preview: the post whole, as a reader holding its tier reads it.

func (*Handler) Canvas

func (h *Handler) Canvas(ctx context.Context, ws *store.Workspace) (PageCanvas, error)

Canvas is the frame the page builder draws the blocks in.

func (*Handler) EarnRender

func (h *Handler) EarnRender(ctx context.Context, ws *store.Workspace, page string, data any) (string, error)

EarnRender renders an Earn page for the app (the upgrade page editor's preview): inert, with the instance's assets.

func (*Handler) GrowPreview

func (h *Handler) GrowPreview(ctx context.Context, ws *store.Workspace, page, program string) (PublicPagePreview, error)

GrowPreview renders one of Grow's public pages for the app.

func (*Handler) HomePreview

HomePreview renders the home page as a visitor sees it, with unsaved Home & navigation settings (the tab's live preview). Nothing is saved.

func (*Handler) Init

func (h *Handler) Init() error

Init parses the templates; Routes calls it.

func (*Handler) PagePreview

func (h *Handler) PagePreview(ctx context.Context, ws *store.Workspace, pageID uuid.UUID, in PagePreviewInput) (PublicPagePreview, error)

PagePreview renders a whole page in the site's frame, inert.

func (*Handler) PollPreview

PollPreview renders an answer page for a poll's settings: Sam answered the first answer, as a contact.

func (*Handler) PostPreview

func (h *Handler) PostPreview(ctx context.Context, ws *store.Workspace, id uuid.UUID, as, tier string) (PublicPagePreview, error)

PostPreview renders a post's page as one kind of reader, in the workspace's default language.

func (*Handler) Preview

func (h *Handler) Preview(ctx context.Context, ws *store.Workspace, page, form, draft, contact, language string) (PublicPagePreview, error)

Preview renders one public page for the app.

func (*Handler) ProductPreview

func (h *Handler) ProductPreview(ctx context.Context, ws *store.Workspace, id uuid.UUID) (PublicPagePreview, error)

ProductPreview renders a product's default page, its draft included.

func (*Handler) RenderBlocks

func (h *Handler) RenderBlocks(ctx context.Context, ws *store.Workspace, pageID uuid.UUID, in PageRenderInput) (PageRendered, error)

RenderBlocks draws a page's live blocks for the builder: inert, with drafts and placeholders shown.

func (*Handler) Routes

func (h *Handler) Routes(r chi.Router)

Routes mounts the public pages, their assets and the custom-domain root.

func (*Handler) SurveyPreview

SurveyPreview renders a survey's page as the builder has it.

type NotificationCategory

type NotificationCategory struct {
	ID          uuid.UUID
	Name        string
	Description string
	On          bool
	OptedOutAt  *time.Time
}

NotificationCategory is one Optional category.

type NotificationMessage

type NotificationMessage struct {
	Email        string
	CategoryID   *uuid.UUID
	CategoryName string
	Optional     bool
	Product      string
}

NotificationMessage is a transactional message's recipient and category.

type NotificationSet

type NotificationSet struct {
	Product    string
	Categories []NotificationCategory
}

NotificationSet is the "Notifications from …" section for an address.

type Notifications

type Notifications interface {
	// Message is the transactional message a link came with; ok is false
	// for other mail.
	Message(ctx context.Context, ws *store.Workspace, messageID uuid.UUID) (msg NotificationMessage, ok bool, err error)
	// For lists the Optional categories and whether email gets each.
	For(ctx context.Context, ws *store.Workspace, email string) (NotificationSet, error)
	// Save turns the categories the page showed on (those in on) or off.
	Save(ctx context.Context, tx pgx.Tx, ws *store.Workspace, email string, on, shown []uuid.UUID, messageID *uuid.UUID) error
	// TurnOff and TurnOn change one category; source is unsubscribe_link
	// or one_click.
	TurnOff(ctx context.Context, tx pgx.Tx, ws *store.Workspace, email string, category uuid.UUID, source string, messageID uuid.UUID) error
	TurnOn(ctx context.Context, tx pgx.Tx, ws *store.Workspace, email string, category uuid.UUID) error
	// Reason keeps the answer to "Why did you turn it off?".
	Reason(ctx context.Context, ws *store.Workspace, email string, category uuid.UUID, reason string) error
}

Notifications are transactional mail's Optional categories ("Reminders", "Product updates"): the preference center's "Notifications from Acme Cloud" section, and the unsubscribe link of a category, which turns off just that category. Recipients of transactional mail don't have to be contacts, so these pages also work for an address alone.

type PageCanvas

type PageCanvas struct {
	// Styles are the site's stylesheets, in order (site, pages, theme).
	Styles []string `json:"styles"`
	// Header and Footer are the site's frame, inert ("Site header · theme").
	Header string `json:"header"`
	// FocusHeader is the header of a page that hides the navigation.
	FocusHeader string `json:"focusHeader"`
	Footer      string `json:"footer"`
	// Lang and Dir are the page's language.
	Lang string `json:"lang"`
	Dir  string `json:"dir"`
}

PageCanvas is what the page builder's canvas loads around the blocks.

type PagePreviewInput

type PagePreviewInput struct {
	HTML       string `json:"html,omitempty" maxLength:"2097152"`
	HideHeader *bool  `json:"hideHeader,omitempty"`
	Name       string `json:"name,omitempty" maxLength:"120"`
	// Live previews what readers see now (the published version).
	Live bool `json:"live,omitempty"`
}

PagePreviewInput previews a page: its saved draft, or the HTML and settings being edited.

type PageRenderInput

type PageRenderInput struct {
	Blocks []string `json:"blocks,omitempty" maxItems:"100"`
	HTML   string   `json:"html,omitempty" maxLength:"2097152"`
}

PageRenderInput are live blocks to draw (the custom elements' HTML, <rc-product …></rc-product>), or a whole page.

type PageRendered

type PageRendered struct {
	Blocks []string `json:"blocks"`
	HTML   string   `json:"html,omitempty"`
}

PageRendered is the drawn blocks, in the order asked, or the page.

type PollPagePreviewInput

type PollPagePreviewInput struct {
	Config   string `json:"config" maxLength:"20000" doc:"The Poll block's settings, as its rc-poll attribute holds them"`
	Campaign string `json:"campaign,omitempty" maxLength:"200"`
}

PollPagePreviewInput is a poll's settings (rc-poll) and its email's name.

type PrefTexts

type PrefTexts struct {
	// Phone is the number, masked; Label the switches' word ("Texts"); Note
	// the line under the lists; Save the account page's button.
	Phone, Label, Note, Save string
	On                       map[uuid.UUID]bool
	// Locked: the number replied STOP, so the switches stay off.
	Locked bool
}

PrefTexts is a contact's Texts switches.

type ProductPreviewPath

type ProductPreviewPath struct {
	api.WorkspaceInput
	Product string `path:"product" format:"uuid"`
}

ProductPreviewPath is a product to preview (exported for Huma).

type PublicPagePreview

type PublicPagePreview struct {
	// HTML is the page as subscribers see it; links and buttons are inert.
	HTML string `json:"html"`
	// URL is where the page lives (the custom domain once verified); empty
	// for pages only signed links open (confirmation, unsubscribe).
	URL string `json:"url"`
	// Contact is whose page it is: the subscriber who confirmed last, or an example address.
	Contact string `json:"contact"`
}

PublicPagePreview is a public page rendered for the app.

type PushPages

type PushPages interface {
	// SiteScripts are the scripts a page on host loads (none when the site
	// isn't a push site).
	SiteScripts(ctx context.Context, ws *store.Workspace, host string) []string
	// TurnOff is the preference center's button, in the page's language
	// (nil when the site isn't a push site).
	TurnOff(ctx context.Context, ws *store.Workspace, host string, l i18n.Lang) *PushTurnOff
}

PushPages is what internal/push gives the pages.

type PushTurnOff

type PushTurnOff struct {
	Label string
	Done  string
	None  string
}

PushTurnOff is the preference center's "Turn off notifications in this browser": its label, and what it says once done or when this browser gets nothing.

type SurveyPagePreviewInput

type SurveyPagePreviewInput struct {
	Name        string                 `json:"name" maxLength:"200"`
	Description string                 `json:"description,omitempty" maxLength:"1000"`
	Slug        string                 `json:"slug,omitempty" maxLength:"60"`
	Questions   []polls.SurveyQuestion `json:"questions" maxItems:"20"`
	Settings    polls.SurveySettings   `json:"settings"`
}

SurveyPagePreviewInput is a survey as the builder has it (unsaved edits included).

type TermsLink struct {
	Text   string
	Href   string
	NoWrap bool
}

TermsLink is words in a section's text and where they link. NoWrap keeps them on one line (a phone number).

type TermsPage

type TermsPage struct {
	// Lang is the language the terms are written in.
	Lang string
	// Title is "Text message terms"; Version "Version 1 · in effect since
	// 1 Oct 2026".
	Title   string
	Version string
	Intro   string
	// Sections are the terms, heading by heading.
	Sections []TermsSection
	// Closing is the box at the end: "Changed your mind?" and how to stop.
	ClosingHeading string
	ClosingText    string
	// ManageLabel links the preference center; BackLabel and BackURL the
	// page where people give SMS consent (empty: no link).
	ManageLabel string
	BackLabel   string
	BackURL     string
	// Footer is the address and how versions work.
	Footer string
}

TermsPage is the page with every word written.

type TermsSection

type TermsSection struct {
	Heading string
	Text    string
	Links   []TermsLink
}

TermsSection is a heading and its text. Links turn their words in the text into links (a phone number, an email address, "privacy policy").

type TextPrefs

type TextPrefs interface {
	// Prefs is the contact's switches and their words; false when the
	// workspace doesn't text or the contact has no number.
	Prefs(ctx context.Context, ws *store.Workspace, contactID uuid.UUID, lang string) (PrefTexts, bool)
	// SavePrefs records the switches of the lists shown, with the request's
	// evidence, in the caller's transaction; it returns the lists whose
	// opt-in confirmation Confirm texts after the commit.
	SavePrefs(ctx context.Context, tx pgx.Tx, ws *store.Workspace, contactID uuid.UUID, shown, on []uuid.UUID, source, ip, userAgent string) ([]uuid.UUID, error)
	Confirm(ctx context.Context, ws *store.Workspace, contactID uuid.UUID, lists []uuid.UUID)
}

TextPrefs is the preference center's texts: a Texts switch per list and the number they go to. Nil when texting isn't wired (the app sets it).

type TextTerms

type TextTerms interface {
	TextTermsPage(ctx context.Context, ws *store.Workspace) (TermsPage, bool)
}

TextTerms writes the terms page. Nil, or a workspace that doesn't text, answers 404.

type WebsitePostPreviewInput

type WebsitePostPreviewInput struct {
	As   string `` /* 169-byte string literal not displayed */
	Tier string `json:"tier,omitempty" maxLength:"64" doc:"A paid member's tier (the highest by default)"`
}

WebsitePostPreviewInput says whom to preview a post for.

type WebsitePostPreviewPath

type WebsitePostPreviewPath struct {
	api.WorkspaceInput
	Post string `path:"post" format:"uuid" doc:"The post's id"`
}

WebsitePostPreviewPath is a post to preview (exported: Huma reads embedded path structs only when their type is exported).

Jump to

Keyboard shortcuts

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