Skip to main content

Module url_path

Module url_path 

Source
Expand description

URL path primitives shared by the link pipeline.

Two concerns live here because every consumer needs both and duplicating either produces silent, platform- or scheme-specific breakage:

  1. path_to_url — conversion of filesystem paths into URL paths. URL paths are always /-separated, but std::path uses the platform separator — \ on Windows. Stringifying a Path with to_string_lossy(), to_str() or display() and splicing the result into a URL therefore produces /docs\guide/ on Windows. Worse, downstream logic that splits on / (index-file collapsing, extension stripping, cache-key matching) then silently stops matching.
  2. is_external_url — the single answer to “does this URL leave the site?”, used by link transformation, link tracking and link validation.

It also holds srcset_url_spans / rewrite_srcset, the one reading of an HTML srcset value, shared by the renderer’s raw-HTML URL rewrite and QuickLook’s attachment collector so the two cannot disagree about which bytes of a srcset are a URL.

Functions§

is_external_url
Returns true when url addresses something outside this site.
is_mbr_query_route
Returns true when url addresses one of mbr’s own ?path=-driven viewer routes (/.mbr/videos/?path=…, and the pdfs / audio / images siblings), in any spelling.
path_to_url
Converts a relative filesystem path into a /-separated URL path body.
rewrite_srcset
srcset with each candidate URL replaced by what rewrite_url returns for it; None keeps that URL as authored.
serialize_as_url
Serde helper: serializes a relative path as a /-separated string.
srcset_url_spans
The byte ranges of the candidate URLs in an HTML srcset value, in order.
url_scheme
Returns the RFC 3986 scheme of url (without the trailing :), if any.