");
}
- let raw_block_content = &source[branch.content.clone()];
+ let raw_block_content = &source.input()[branch.content.clone()];
let mut unindented_block_content = String::with_capacity(raw_block_content.len());
for line in raw_block_content.lines() {
// Bit of a jank way to remove at most branch.indent_level spaces from the front.
@@ -93,7 +93,11 @@ pub fn branch_to_html(
.get(linked)
.map(|&branch_id| {
(
- format!("#{}", treehouse.tree.branch(branch_id).html_id).into(),
+ format!(
+ "/b?{}",
+ treehouse.tree.branch(branch_id).attributes.id
+ )
+ .into(),
"".into(),
)
}),
@@ -144,8 +148,8 @@ pub fn branch_to_html(
write!(
s,
- "
",
- EscapeAttribute(&branch.html_id)
+ "
",
+ EscapeAttribute(&branch.attributes.id)
)
.unwrap();
}
diff --git a/crates/treehouse/src/main.rs b/crates/treehouse/src/main.rs
index f73736f..4d58165 100644
--- a/crates/treehouse/src/main.rs
+++ b/crates/treehouse/src/main.rs
@@ -3,10 +3,11 @@ use std::path::Path;
use clap::Parser;
use cli::{
fix::{fix_all_cli, fix_file_cli},
- generate::{self, regenerate_or_report_error},
+ generate::regenerate_or_report_error,
+ serve::serve,
Command, Paths, ProgramArgs,
};
-use log::{error, info};
+use log::{error, info, warn};
mod cli;
mod config;
@@ -30,14 +31,17 @@ async fn fallible_main() -> anyhow::Result<()> {
};
match args.command {
- Command::Generate(regenerate_args) => {
+ Command::Generate(_generate_args) => {
info!("regenerating using directories: {paths:#?}");
-
- regenerate_or_report_error(&paths);
-
- if let Some(port) = regenerate_args.serve {
- generate::web_server(port).await?;
- }
+ regenerate_or_report_error(&paths)?;
+ warn!("`generate` is for debugging only and the files cannot be fully served using a static file server; use `treehouse serve` if you wish to start a treehouse server");
+ }
+ Command::Serve {
+ generate: _,
+ serve: serve_args,
+ } => {
+ let treehouse = regenerate_or_report_error(&paths)?;
+ serve(treehouse, &paths, serve_args.port).await?;
}
Command::Fix(fix_args) => fix_file_cli(fix_args)?,
diff --git a/crates/treehouse/src/state.rs b/crates/treehouse/src/state.rs
index 94bad04..4ec4e27 100644
--- a/crates/treehouse/src/state.rs
+++ b/crates/treehouse/src/state.rs
@@ -10,7 +10,28 @@ use ulid::Ulid;
use crate::tree::{SemaBranchId, SemaRoots, SemaTree};
-pub type Files = SimpleFiles
;
+#[derive(Debug, Clone)]
+pub enum Source {
+ Tree { input: String, tree_path: String },
+ Other(String),
+}
+
+impl Source {
+ pub fn input(&self) -> &str {
+ match &self {
+ Source::Tree { input, .. } => input,
+ Source::Other(source) => source,
+ }
+ }
+}
+
+impl AsRef for Source {
+ fn as_ref(&self) -> &str {
+ self.input()
+ }
+}
+
+pub type Files = SimpleFiles;
pub type FileId = >::FileId;
/// Treehouse compilation context.
@@ -22,19 +43,9 @@ pub struct Treehouse {
pub branches_by_named_id: HashMap,
pub roots: HashMap,
- // Bit of a hack because I don't wanna write my own `Files`.
- tree_paths: Vec
@@ -70,7 +77,7 @@