links

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const AmbiguousHint = "write ./name.md for a sibling page or a content-root path like docs/name.md"

AmbiguousHint is the fix advice attached to ambiguous_link findings: a bare `name.md` is never resolved (see linkrender.ClassifyDest); the author must say whether it is relative to the page or to the content root.

Variables

This section is empty.

Functions

func CheckExternalLinks(graph *LinkGraph, cfg ExternalCheckConfig) error

CheckExternalLinks probes external URLs recorded in the graph, updating broken ones to StatusExternalBroken. Results are cached to disk.

Types

type AnchorLookup

type AnchorLookup interface {
	HasHeading(permalink, headingID string) bool
}

AnchorLookup is the interface ValidateAnchors needs from PageIndex. Satisfied by *content.PageIndex without importing the content package.

type CoverageSummary

type CoverageSummary struct {
	Lanes       []LaneSummary
	TotalLanes  int
	TotalPages  int
	TotalLinks  int
	TotalBroken int
	MissedLanes []DimKey // expected lanes with no links checked
}

CoverageSummary reports which lanes were checked and aggregate stats.

func ComputeCoverage

func ComputeCoverage(graph *LinkGraph, pages []*engine.Page, expectedLanes []DimKey) CoverageSummary

ComputeCoverage analyzes the link graph and the set of rendered pages to produce a coverage summary. expectedLanes is the full set of lanes that should produce output (from EnumerateLanes); the graph provides what was actually checked.

type DimKey

type DimKey struct {
	Collection string
	Lang       string
	Version    string
}

DimKey identifies the content dimension a link was resolved in.

func EnumerateLanes

func EnumerateLanes(collections map[string]*engine.Collection, languages []string) []DimKey

EnumerateLanes computes the full set of expected lanes from collections and language configuration. Each collection × language × version combination that produces output is one lane.

type ExternalCheckConfig

type ExternalCheckConfig struct {
	Enabled     bool
	Concurrency int
	Timeout     time.Duration
	CachePath   string // absolute path to linkcache.json
	CacheTTL    time.Duration
	OnBroken    string   // "warn" | "error" | "ignore"
	Ignore      []string // URL glob patterns to skip
	Method      string   // "head-then-get" | "head" | "get"
}

ExternalCheckConfig holds the resolved configuration for external link checking.

type ExternalResult

type ExternalResult struct {
	URL        string    `json:"url"`
	StatusCode int       `json:"status_code"`
	OK         bool      `json:"ok"`
	Checked    time.Time `json:"checked"`
	Error      string    `json:"error,omitempty"`
}

ExternalResult is the probed outcome for a single URL.

type Finding

type Finding struct {
	Type   FindingType
	Ref    LinkRef
	Policy string // "error" | "warn"
}

Finding is a single reportable issue derived from a LinkRef.

type FindingType

type FindingType int

FindingType classifies what kind of issue a report finding represents.

const (
	FindingBrokenTarget FindingType = iota
	FindingBrokenAnchor
	FindingRelativeLink
	FindingLocalLink
	FindingSameSite
	FindingExternalBroken
	FindingUnverifiedInternal
	FindingAmbiguousLink
)

func (FindingType) Hint added in v1.4.0

func (ft FindingType) Hint() string

Hint returns fix advice for finding types that have one, else "".

func (FindingType) Label

func (ft FindingType) Label() string

func (FindingType) String

func (ft FindingType) String() string

type LaneSummary

type LaneSummary struct {
	Dim        DimKey
	Pages      int
	Links      int
	Broken     int
	External   int
	IsFallback bool // true if this lane only contains fallback pages
}

LaneSummary holds link-checking stats for a single rendered lane.

type LinkCheckConfig

type LinkCheckConfig struct {
	OnBroken             string
	OnBrokenAnchor       string
	OnRelativeLinks      string
	OnLocalLinks         string
	SameSitePolicy       string
	ReportFormat         string
	Exclude              []string
	OnExternalBroken     string
	OnUnverifiedInternal string
}

LinkCheckConfig holds resolved policy values for report generation. Avoids importing internal/config in this package.

type LinkGraph

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

LinkGraph records every link resolution attempt during a build for queryable post-build validation. Safe for concurrent use.

func NewLinkGraph

func NewLinkGraph() *LinkGraph

NewLinkGraph creates an empty link graph.

func (*LinkGraph) BrokenRefs

func (g *LinkGraph) BrokenRefs() []LinkRef

BrokenRefs returns only the refs with BrokenTarget or BrokenAnchor status.

func (*LinkGraph) ExternalRefs

func (g *LinkGraph) ExternalRefs() []LinkRef

ExternalRefs returns only the refs with External status.

func (*LinkGraph) Len

func (g *LinkGraph) Len() int

Len returns the number of recorded link references.

func (*LinkGraph) MarkExternalBroken

func (g *LinkGraph) MarkExternalBroken(url string)

MarkExternalBroken transitions all refs whose RawDest equals url from StatusExternal to StatusExternalBroken.

func (*LinkGraph) Record

func (g *LinkGraph) Record(ref LinkRef)

Record appends a link resolution record to the graph.

func (*LinkGraph) Refs

func (g *LinkGraph) Refs() []LinkRef

Refs returns a copy of all recorded link references.

func (*LinkGraph) UnverifiedRefs

func (g *LinkGraph) UnverifiedRefs() []LinkRef

UnverifiedRefs returns only the refs with Unverified status.

type LinkKind

type LinkKind int

LinkKind classifies a link destination for the link graph.

const (
	KindRelative    LinkKind = iota // ./ or ../
	KindContentRoot                 // leading / within collection
	KindAnchorOnly                  // #fragment with no path
	KindExternal                    // http(s)://, mailto:, etc.
	KindAmbiguous                   // bare name — rejected
)

type LinkRef

type LinkRef struct {
	FromPage   *engine.Page
	FromFile   string
	Line, Col  int
	RawDest    string
	Dim        DimKey
	Kind       LinkKind
	Resolved   string
	TargetPage *engine.Page
	Fragment   string
	Status     LinkStatus
}

LinkRef records a single link resolution attempt.

type LinkStatus

type LinkStatus int

LinkStatus classifies the outcome of a link resolution attempt.

const (
	StatusOK             LinkStatus = iota // resolved successfully
	StatusBrokenTarget                     // target page not found in index
	StatusBrokenAnchor                     // target page found but heading ID missing
	StatusExternal                         // external URL, unchecked by internal resolver
	StatusExternalBroken                   // external URL probed and returned non-2xx/3xx
	StatusUnverified                       // internal page-like link that didn't resolve in-lane (cross-lane or typo)
	StatusAmbiguous                        // bare `name.md` (no ./ or content-root prefix): never resolved by design
)

type PendingAnchorCheck

type PendingAnchorCheck struct {
	SourceFile      string
	TargetPermalink string
	Fragment        string
	RawHref         string
	FromPage        *engine.Page
	TargetPage      *engine.Page
	Dim             DimKey
	Kind            LinkKind
	Resolved        string
	// Line/Col of the link in SourceFile (1-based); 0 when unknown.
	Line, Col int
}

PendingAnchorCheck records a deferred anchor validation. It carries the full LinkRef fields needed to write a definitive graph entry after all page headings are populated.

func ValidateAnchors

func ValidateAnchors(
	graph *LinkGraph,
	pending []PendingAnchorCheck,
	index AnchorLookup,
) []PendingAnchorCheck

ValidateAnchors records a definitive LinkRef for each pending anchor check after all page headings are populated. It writes StatusOK or StatusBrokenAnchor into graph and returns the failed checks for the builder's warning machinery.

type ReportInput

type ReportInput struct {
	Graph    *LinkGraph
	Coverage CoverageSummary
	Config   LinkCheckConfig
	SiteURL  string
}

ReportInput bundles everything GenerateReport needs.

type ReportResult

type ReportResult struct {
	HasErrors bool
	Output    string
	Findings  []Finding
	Summary   string
}

ReportResult is what GenerateReport returns to the builder.

func GenerateReport

func GenerateReport(in ReportInput) ReportResult

GenerateReport applies policy filters over the link graph and returns a formatted report. The caller (builder.go) uses HasErrors to decide whether to return a build error.

Jump to

Keyboard shortcuts

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