Skip to main content

ContentGraph

Struct ContentGraph 

Source
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

Source

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.

Source

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.

Source

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 ![](x), 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):

  1. Exact normalized path
  2. Exact + .md
  3. Filename match (case-insensitive, without extension)
  4. Filename + .md match
  5. Folder note: reference/index.md or reference/<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).

Source

pub fn get_slug(&self, path: &str) -> Option<&str>

Return the slug for the given path, if registered.

Source

pub fn all_files(&self) -> &[String]

All file paths in insertion order.

Source

pub fn asset_contains(&self, p: &str) -> bool

Return true iff p is present in the graph with exactly this casing.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> ContentGraph

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContentGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.