pub struct ContentGraph { /* private fields */ }Expand description
An in-memory index of all content files.
Created via ContentGraphBuilder::build. All lookups are
case-insensitive (NFC-normalized, lowercased).
Implementations§
Source§impl ContentGraph
impl ContentGraph
Sourcepub fn with_output_overrides(self, overrides: HashMap<String, String>) -> Self
pub fn with_output_overrides(self, overrides: HashMap<String, String>) -> Self
Install the build’s source-directory → URL-slug overrides, making this graph the authority on emitted URLs as well as on resolution.
The host calls this once, right after the overrides are computed
(build_page_map in src-tauri), and every emitter downstream reads the
answer off the same graph it already holds. Sites that don’t map any
directory still benefit: base slugification (MIRROR/ → mirror/) runs
with an empty map.
Sourcepub fn pinned_url(&self, root_rel: &str) -> String
pub fn pinned_url(&self, root_rel: &str) -> String
The one URL a resolved reference may be emitted as.
root_rel is a source path this graph resolved (via
Self::resolve_path or the asset engine). The result is the pinned,
root-absolute, case-canonical URL the site serves that file at — see
crate::resolve::output_url::pinned_url for the properties this
guarantees.
Never re-derive an emitted URL from a folder name, a referencing
page’s depth, or a case-insensitive retry: those are the four-times-
recurring bug class this method exists to end (moss#903 bug 3). A
reference that does not resolve gets a Diagnostic, not a guessed path.
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/reference/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 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