adding document mode
I've been thinking a lot about the treehouse and I feel like it's time to say goodbye to the tree format.
This commit is contained in:
parent
550c062327
commit
36705e7c1e
31 changed files with 940 additions and 409 deletions
|
@ -2,7 +2,7 @@ use std::{collections::HashMap, ops::ControlFlow};
|
|||
|
||||
use anyhow::{anyhow, Context};
|
||||
use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator};
|
||||
use tracing::{info_span, instrument};
|
||||
use tracing::{error, info_span, instrument};
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
|
@ -66,14 +66,19 @@ fn load_trees(config: &Config, dirs: &Dirs) -> anyhow::Result<Treehouse> {
|
|||
let mut parsed_trees = HashMap::new();
|
||||
|
||||
let mut paths = vec![];
|
||||
let mut doc_paths = vec![];
|
||||
|
||||
vfs::walk_dir_rec(&*dirs.content, VPath::ROOT, &mut |path| {
|
||||
if path.extension() == Some("tree") {
|
||||
paths.push(path.to_owned());
|
||||
match path.extension() {
|
||||
Some("tree") => paths.push(path.to_owned()),
|
||||
Some("dj") => doc_paths.push(path.to_owned()),
|
||||
_ => (),
|
||||
}
|
||||
ControlFlow::Continue(())
|
||||
});
|
||||
|
||||
// Trees
|
||||
|
||||
// NOTE: Sources are filled in later; they can be left out until a call to report_diagnostics.
|
||||
let file_ids: Vec<_> = paths
|
||||
.iter()
|
||||
|
@ -132,5 +137,18 @@ fn load_trees(config: &Config, dirs: &Dirs) -> anyhow::Result<Treehouse> {
|
|||
|
||||
report_diagnostics(&treehouse, &diagnostics)?;
|
||||
|
||||
// Docs
|
||||
|
||||
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);
|
||||
} else {
|
||||
error!("doc {path} does not exist in content directory even though it was enumerated via walk_dir_rec");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(treehouse)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue