add a tagging system to the website

This commit is contained in:
りき萌 2025-08-24 13:18:51 +02:00
parent 701da6bc4b
commit e1b6578b2a
97 changed files with 1025 additions and 979 deletions

View file

@ -1,16 +1,17 @@
use std::{collections::HashMap, ops::ControlFlow};
use anyhow::{anyhow, Context};
use anyhow::{Context, anyhow};
use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator};
use tracing::{error, info_span, instrument};
use crate::{
config::Config,
dirs::Dirs,
doc::Doc,
html::navmap::NavigationMap,
import_map::ImportMap,
parse::parse_tree_with_diagnostics,
state::{report_diagnostics, Source, Treehouse},
state::{Source, Tag, Treehouse, report_diagnostics},
tree::SemaRoots,
vfs::{self, Cd, Content, VPath, VPathBuf},
};
@ -135,20 +136,57 @@ fn load_trees(config: &Config, dirs: &Dirs) -> anyhow::Result<Treehouse> {
}
}
report_diagnostics(&treehouse, &diagnostics)?;
// Docs
for path in doc_paths {
let mut doc_file_ids = vec![];
for path in &doc_paths {
if let Some(input) =
vfs::query::<Content>(&dirs.content, &path).and_then(|c| c.string().ok())
{
let file_id = treehouse.add_file(path.clone(), Source::Other(input));
treehouse.files_by_doc_path.insert(path, file_id);
treehouse.files_by_doc_path.insert(path.clone(), file_id);
doc_file_ids.push(file_id);
} else {
error!("doc {path} does not exist in content directory even though it was enumerated via walk_dir_rec");
error!(
"doc {path} does not exist in content directory even though it was enumerated via walk_dir_rec"
);
}
}
for file_id in doc_file_ids {
let (doc, mut doc_diagnostics) = Doc::parse(&mut treehouse, file_id);
treehouse.docs.insert(file_id, doc);
diagnostics.append(&mut doc_diagnostics);
}
// Tags
for (_, file_id) in &treehouse.files_by_tree_path {
let roots = &treehouse.roots[file_id];
for tag_name in &roots.attributes.tags {
let tag = treehouse
.tags
.entry(tag_name.clone())
.or_insert_with(Tag::default);
tag.files.push(*file_id);
}
}
for (_, file_id) in &treehouse.files_by_doc_path {
let doc = &treehouse.docs[file_id];
for tag_name in &doc.attributes.tags {
let tag = treehouse
.tags
.entry(tag_name.clone())
.or_insert_with(Tag::default);
tag.files.push(*file_id);
}
}
// Diagnostics
report_diagnostics(&treehouse, &diagnostics)?;
Ok(treehouse)
}