pages

package
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package pages holds the privacy-friendly analytics view for static sites.

Package pages holds the build log and dependency cache rules for git-connected Pages builds.

Package pages converts existing static hosting config files into the _redirects and _headers formats. It is pure local text conversion.

Package pages holds Pages logic that does not belong to a single HTTP route.

Package pages holds the named performance presets for static sites.

Index

Constants

View Source
const (
	EventSuccess = "success"
	EventFailure = "failure"
)

Event names accepted by the notify event filter.

View Source
const SourcePrefix = "preset:"

SourcePrefix labels preset header blocks so they can be replaced and ranked.

View Source
const TruncatedNotice = "[earlier build output truncated to fit the log size limit]"

TruncatedNotice is the marker line shown when older output was dropped to fit the cap.

Variables

View Source
var Ranges = map[string]time.Duration{"24h": 24 * time.Hour, "7d": 7 * 24 * time.Hour, "30d": 30 * 24 * time.Hour}

Ranges are the windows the endpoint serves.

Functions

func Apply

func Apply(rs *spec.StaticRuleset, id string, l spec.StaticLimits) error

Apply replaces any earlier preset blocks in rs with the preset's, ranked after every other block. A header name the user sets anywhere is left to the user. An empty id only removes the preset.

func CacheDir

func CacheDir(root, site string) (string, error)

CacheDir returns the per-site cache directory under root. The site name is validated so one site can never address another site's cache.

func CacheKey

func CacheKey(lockfiles ...[]byte) string

CacheKey derives a cache key from lockfile contents, so a changed lockfile starts a fresh cache.

func EvictOldest

func EvictOldest(siteDir, keep string, limit int64) error

EvictOldest removes the oldest key directories of one site until its cache fits limit bytes. The key just used is spared so a build never deletes the cache it is about to read.

func LogExpired

func LogExpired(finished, now time.Time, retention time.Duration) bool

LogExpired reports whether a finished deploy's log is past its retention. A zero retention keeps logs forever.

func ParseEvents

func ParseEvents(events []string) (onSuccess, onFailure bool, err error)

ParseEvents turns event names into filter flags; at least one is required.

func RangeFits

func RangeFits(span time.Duration, retentionDays int) bool

RangeFits reports whether a range is inside the retention in days.

func RefHost

func RefHost(raw string) string

RefHost reduces a referrer to a lowercase host, or "" when none is usable. Paths, queries and credentials are dropped so nothing identifying is kept.

func Window

func Window[T any](items []T, size func(T) int, limit int64) ([]T, bool)

Window keeps the newest items whose summed size fits limit bytes. Failures show at the end of a build, so the tail is the part worth keeping. It reports whether anything was dropped.

Types

type Analytics

type Analytics struct {
	Site          string        `json:"site"`
	Range         string        `json:"range"`
	Since         time.Time     `json:"since"`
	GeneratedAt   time.Time     `json:"generated_at"`
	RetentionDays int           `json:"retention_days"`
	Requests      int           `json:"requests"`
	TopPages      []Count       `json:"top_pages"`
	TopReferrers  []Count       `json:"top_referrers"`
	Status        []StatusCount `json:"status"`
	Partial       bool          `json:"partial"`
}

Analytics is the body of GET /api/v1/static-sites/{name}/analytics. It holds no client address, cookie, country or query string.

type Count

type Count struct {
	Label string `json:"label"`
	Count int    `json:"count"`
}

Count is a label with how many requests it covers.

func MergeReferrers

func MergeReferrers(in []Count, n int) []Count

MergeReferrers folds referrer labels to hosts, merges duplicates and keeps the top n.

type HeaderBlock

type HeaderBlock struct {
	Path    string
	Headers [][2]string
}

HeaderBlock is one path pattern with its response headers.

type HeaderRule

type HeaderRule struct {
	Path string            `json:"path"`
	Set  map[string]string `json:"set"`
}

HeaderRule is one path pattern with the headers the preset sets on it.

type ImportResult

type ImportResult struct {
	Redirects   []string
	Headers     []HeaderBlock
	Unsupported []string
	Sources     []string
}

ImportResult is the converted config plus a report of what was skipped.

func ImportDir

func ImportDir(dir string) (*ImportResult, error)

ImportDir inspects the root of dir, detects config files by shape and converts them. Nothing is written.

func (*ImportResult) Render

func (r *ImportResult) Render() (redirects, headers string)

Render returns the _redirects and _headers file bodies.

type NotifyConfig

type NotifyConfig struct {
	Enabled   bool `json:"enabled"`
	OnSuccess bool `json:"on_success"`
	OnFailure bool `json:"on_failure"`
}

NotifyConfig is one site's deploy notification switch and event filter.

func DefaultNotifyConfig

func DefaultNotifyConfig() NotifyConfig

DefaultNotifyConfig is what a site without a stored row behaves like.

func (NotifyConfig) Allows

func (c NotifyConfig) Allows(succeeded bool) bool

Allows reports whether a deploy outcome should be sent.

func (NotifyConfig) Events

func (c NotifyConfig) Events() []string

Events lists the enabled event names in a stable order.

type NotifyStore

type NotifyStore struct {
	// contains filtered or unexported fields
}

NotifyStore persists NotifyConfig per resource ID.

func NewNotifyStore

func NewNotifyStore(db SQLExecer) *NotifyStore

NewNotifyStore wraps db, which must hold the pages_notify_settings table.

func (*NotifyStore) AllowDeployOutcome

func (s *NotifyStore) AllowDeployOutcome(ctx context.Context, resourceID string, succeeded bool) bool

AllowDeployOutcome lets the deploy dispatcher skip filtered events; a read error fails open.

func (*NotifyStore) Delete

func (s *NotifyStore) Delete(ctx context.Context, resourceID string) error

Delete drops the row so the site returns to the default.

func (*NotifyStore) Get

func (s *NotifyStore) Get(ctx context.Context, resourceID string) (NotifyConfig, bool, error)

Get returns the stored config and whether a row exists.

func (*NotifyStore) Put

func (s *NotifyStore) Put(ctx context.Context, resourceID string, c NotifyConfig) error

Put creates or replaces the config.

type Preset

type Preset struct {
	ID          string            `json:"id"`
	Name        string            `json:"name"`
	Description string            `json:"description"`
	Compression []string          `json:"compression"`
	Headers     []HeaderRule      `json:"headers"`
	Security    map[string]string `json:"security"`
}

Preset is one named bundle of cache, compression and security header choices.

func All

func All() ([]Preset, error)

All returns the embedded presets in file order.

func Get

func Get(id string) (Preset, bool)

Get returns the preset with the given id.

type SQLExecer

type SQLExecer interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

SQLExecer is the slice of *sql.DB the store needs; the alerting DB satisfies it.

type StatusCount

type StatusCount struct {
	Code  int `json:"code"`
	Count int `json:"count"`
}

StatusCount is one exact response code with its request count.

func StatusBreakdown

func StatusBreakdown(codes []int) []StatusCount

StatusBreakdown counts exact response codes, most frequent first.

Jump to

Keyboard shortcuts

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