Skip to main content

Module link_transform

Module link_transform 

Source
Expand description

Link transformation for trailing-slash URL convention.

When markdown files are served with trailing-slash URLs (e.g., docs/guide.md → /docs/guide/), relative links in the markdown need to be adjusted so they resolve correctly from the browser’s perspective.

§Problem

A link [other](other.md) in docs/guide.md:

  • Filesystem: refers to docs/other.md (sibling file)
  • From URL /docs/guide/: browser resolves other.md as /docs/guide/other.md (WRONG)
  • Correct URL: /docs/other/

§Solution

Transform relative links by:

  1. Adding ../ prefix for regular markdown files (not index files)
  2. Replacing markdown extensions with trailing slash
  3. Collapsing index file references to their directory

Structs§

LinkTransformConfig
Configuration for link transformation.

Functions§

filesystem_markdown_page_probe
Builds the probe used in server and build mode: ask the path resolver — the very code a live HTTP request goes through — whether the URL resolves to a markdown file.
make_relative_url
Convert an absolute URL path to a relative URL from the given depth.
transform_link
Transform a relative link URL for the trailing-slash URL convention.

Type Aliases§

MarkdownPageProbe
Answers “does this absolute, percent-decoded site URL address a markdown page?” for an authored link target that carries no markdown extension.