2021-07-12 20:47:49 +00:00
|
|
|
use siru::prelude::*;
|
|
|
|
use std::{convert::TryInto, path::PathBuf, sync::Arc, time::Duration};
|
|
|
|
|
|
|
|
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
|
|
|
|
|
|
|
mod assets;
|
|
|
|
mod main_page;
|
2022-03-05 14:26:10 +00:00
|
|
|
mod webring;
|
2021-07-12 20:47:49 +00:00
|
|
|
|
|
|
|
pub struct BuildContext {
|
|
|
|
source_dir: PathBuf,
|
|
|
|
output_dir: PathBuf,
|
|
|
|
write_pipeline: WritePipeline,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SiruFS for BuildContext {
|
|
|
|
fn get_source_dir(&self) -> &PathBuf {
|
|
|
|
&self.source_dir
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_output_dir(&self) -> &PathBuf {
|
|
|
|
&self.output_dir
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_write_pipeline(&self) -> &WritePipeline {
|
|
|
|
&self.write_pipeline
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn build() {
|
|
|
|
let ctx = BuildContext {
|
|
|
|
source_dir: "src".try_into().unwrap(),
|
|
|
|
output_dir: "dist".try_into().unwrap(),
|
|
|
|
write_pipeline: WritePipeline::new(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let ctx = Arc::new(ctx);
|
|
|
|
|
2022-03-05 14:26:10 +00:00
|
|
|
[
|
|
|
|
main_page::main_page,
|
|
|
|
assets::copy_assets,
|
|
|
|
webring::copy_webring,
|
|
|
|
]
|
|
|
|
.iter()
|
|
|
|
.map(|f| {
|
|
|
|
let ctx = Arc::clone(&ctx);
|
|
|
|
std::thread::spawn(move || f(&ctx).unwrap())
|
|
|
|
})
|
|
|
|
.for_each(|t| t.join().unwrap());
|
2021-07-12 20:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2021-07-13 02:32:52 +00:00
|
|
|
build();
|
2021-07-12 20:47:49 +00:00
|
|
|
|
2021-07-13 02:32:52 +00:00
|
|
|
if matches!(std::env::args().nth(1).as_deref(), Some("watch")) {
|
|
|
|
use notify::*;
|
2021-07-12 20:47:49 +00:00
|
|
|
|
2021-07-13 02:32:52 +00:00
|
|
|
let (tx, rx) = std::sync::mpsc::channel();
|
2021-07-12 20:47:49 +00:00
|
|
|
|
2021-07-13 02:32:52 +00:00
|
|
|
let mut watcher = watcher(tx, Duration::from_millis(100)).unwrap();
|
|
|
|
watcher.watch("./src", RecursiveMode::Recursive).unwrap();
|
2021-07-12 20:47:49 +00:00
|
|
|
|
2021-07-13 02:32:52 +00:00
|
|
|
loop {
|
|
|
|
match rx.recv() {
|
|
|
|
Ok(_) => build(),
|
|
|
|
Err(_) => break,
|
|
|
|
}
|
2021-07-12 20:47:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|