pub struct ContentGraph { /* private fields */ }Expand description
An in-memory index of all content files, headings, and block IDs.
Created via ContentGraphBuilder::build. All lookups are
case-insensitive (NFC-normalized, lowercased).
Implementations§
Source§impl ContentGraph
impl ContentGraph
Sourcepub fn resolve_path(&self, reference: &str, from_path: &str) -> Option<String>
pub fn resolve_path(&self, reference: &str, from_path: &str) -> Option<String>
Single source of truth for target resolution in moss.
Every link syntax — wikilinks [[x]], standard markdown links
[t](x), image refs , embeds ![[x]], frontmatter refs —
MUST resolve through this function. See the resolve pipeline in
crate::resolve::resolve_content and the prose overview in
moss/docs/link-resolution.md for the per-syntax call sites.
Downstream code (the compiler’s URL-prettifier, for instance)
receives already-resolved hrefs and MUST NOT reimplement any
part of this chain. Adding a parallel resolver was the root
cause of the [文字](文字.md) regression on sites using folder
notes.
Resolution chain (first match wins):
- Exact normalized path
- Exact +
.md - Filename match (case-insensitive, without extension)
- Filename +
.mdmatch - Folder note:
reference/index.mdorreference/<reference>.md
Ambiguity tiebreakers, applied in order:
candidates whose extension matches the reference’s extension win first
(e.g. ![[scale-compare.png]] prefers a .png sibling over a .html
sibling — only applies when the reference carries an extension);
candidates in the same language tree as the source are preferred next;
then longest common directory prefix with from_path; then alphabetical
by normalized path (so results are independent of registration order
when all earlier keys tie).
Sourcepub fn has_heading(&self, path: &str, anchor: &str) -> bool
pub fn has_heading(&self, path: &str, anchor: &str) -> bool
Check whether the file at path has a heading with the given anchor.
Sourcepub fn has_block(&self, path: &str, block_id: &str) -> bool
pub fn has_block(&self, path: &str, block_id: &str) -> bool
Check whether the file at path has a block with the given block_id.
Sourcepub fn get_slug(&self, path: &str) -> Option<&str>
pub fn get_slug(&self, path: &str) -> Option<&str>
Return the slug for the given path, if registered.
Sourcepub fn asset_contains(&self, p: &str) -> bool
pub fn asset_contains(&self, p: &str) -> bool
Return true iff p is present in the graph with exactly this casing.
Sourcepub fn asset_contains_ci(&self, p: &str) -> Option<String>
pub fn asset_contains_ci(&self, p: &str) -> Option<String>
Case-insensitive membership: return the first canonical real-case path
whose lowercased form equals p.to_lowercase(), or None.
Sourcepub fn asset_find_by_suffix(&self, suffix: &str) -> Vec<String>
pub fn asset_find_by_suffix(&self, suffix: &str) -> Vec<String>
Return all real-case paths whose lowercased form ends with /<suffix>
(or equals suffix exactly). Results are sorted for determinism.
Sourcepub fn from_paths(paths: &[&str]) -> ContentGraph
pub fn from_paths(paths: &[&str]) -> ContentGraph
Build a graph from a bare list of file paths (no slugs).
Each file is registered with an empty slug. Useful for tests and for lightweight index construction in integration scenarios where only asset lookup (not slug routing) is needed.
Trait Implementations§
Source§impl Clone for ContentGraph
impl Clone for ContentGraph
Source§fn clone(&self) -> ContentGraph
fn clone(&self) -> ContentGraph
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more