Skip to main content

Module link_grep

Module link_grep 

Source
Expand description

Grep-based inbound link discovery for server mode.

This module provides fast, on-demand discovery of pages that link to a given page by searching through all markdown files in the repository.

§Algorithm

The key challenge is that markdown links can be:

  • Absolute: /a/b/c/1
  • Relative to current folder: c/1, ./c/1
  • Relative with parent traversal: ../b/c/1, ../../a/b/c/1

To efficiently find all links to a target page, we:

  1. Collect all unique folder paths in the repository
  2. For each folder, compute which patterns could represent a link to the target
  3. Build an Aho-Corasick automaton per folder for fast multi-pattern matching
  4. Scan each file using the automaton for its folder
  5. Only when a match is found, extract link details with regex

Bare [[Name]] wiki links do not name a path at all: the renderer resolves them through mbr_core::wikilink_index::WikilinkIndex by title, alias, or filename stem. Those names are therefore added to the pattern set as well (gate + wiki regex only — never the inline/reference regexes, where a name is not a URL).

Structs§

InboundLinkCache
Cache for inbound link grep results.

Functions§

find_inbound_links
Find all inbound links to a target page by grep-searching markdown files.