Skip to main content

moss_core/resolve/
folder_class.rs

1//! Directory-shaped resolution capability (injected; pure core).
2//! Build impl is backed by the content graph + html_files; the editor impl by
3//! the last build's folder-index URL set plus a vault walk. Separate from
4//! AssetIndex because the backing data and the query shape (is_dir /
5//! markdown-index / static-index) differ.
6
7pub trait FolderIndex {
8    /// Does a directory exist at this root-relative path?
9    fn is_dir(&self, root_rel: &str) -> bool;
10    /// Does this folder resolve a markdown index (→ FolderListing)?
11    /// Build: a doc whose url_path is this folder's index URL (covers
12    /// content-folder promotion). Editor: the last build's folder-index URL
13    /// set, reconstructed from `ArticleMap.pages` ∪ the scanned directory set
14    /// (see ADR-040) — NOT an `index.md` stat.
15    fn dir_has_markdown_index(&self, root_rel: &str) -> bool;
16    /// Does this folder have a static index.html/.htm (and no markdown index)?
17    /// Returns the index filename (→ FolderIndexIframe).
18    fn dir_has_static_index(&self, root_rel: &str) -> Option<String>;
19}
20
21#[cfg(test)]
22pub(crate) struct FakeFolderIndex {
23    pub dirs: std::collections::HashSet<String>,
24    pub md_index: std::collections::HashSet<String>,
25    pub static_index: std::collections::HashMap<String, String>,
26}
27
28#[cfg(test)]
29impl FakeFolderIndex {
30    pub fn new() -> Self {
31        FakeFolderIndex {
32            dirs: Default::default(),
33            md_index: Default::default(),
34            static_index: Default::default(),
35        }
36    }
37}
38
39#[cfg(test)]
40impl FolderIndex for FakeFolderIndex {
41    fn is_dir(&self, p: &str) -> bool {
42        self.dirs.contains(p)
43    }
44    fn dir_has_markdown_index(&self, p: &str) -> bool {
45        self.md_index.contains(p)
46    }
47    fn dir_has_static_index(&self, p: &str) -> Option<String> {
48        self.static_index.get(p).cloned()
49    }
50}