module

Hwaro::Content::Processors::InternalLinkResolver

Constants

ANY_LINK_ATTR_REGEX = /\b(href|src)="([^"]*)"/

Matches any href/src attribute value (relative or absolute).

INTERNAL_LINK_REGEX = /href="@\/([^"#]*)(?:#([^"]*))?"/

Matches href="@/path" and href="@/path#anchor"

ROOT_RELATIVE_ATTR_REGEX = /\b(href|src)="(\/(?:[^\/"][^"]*)?)"/

Matches a plain root-relative href/src value (e.g. href="/posts/"). \/[^\/"] excludes protocol-relative //host URLs; the alternation also allows a bare / (the homepage link).

SCHEME_PREFIX_REGEX = /\A[a-zA-Z][a-zA-Z0-9+.\-]*:/

A URI scheme prefix (e.g. https:, mailto:, tel:, data:).

Instance methods

resolve(html : String, pages_by_path : Hash(String, Models::Page), source_path : String, base_url : String = "", misses : Array(Tuple(String, String)) | Nil = nil) : String

Resolve internal @/ links in HTML to actual page URLs.

  • html — rendered HTML string
  • pages_by_path — map from content path (e.g. "blog/post.md") to Page
  • source_path — path of the page being rendered (for warning messages)
  • base_url — site base_url, used to prepend the path component (e.g. "/noir") so links work when the site is served from a subpath. When empty or root, no prefix is added and behavior matches the previous output.
  • misses — optional accumulator for unresolved links. Each entry is {target, reason} with reason "page not found" or "empty link". Callers running under [links] broken_internal = "error" collect them to fail the build after the render fan-out; warnings are still logged either way. nil keeps warn-only behavior.
Source