~zenomat/tinywiki

6a4ce1517c0124769377dedd916b3165b1250cbb — zeno 1 year, 2 months ago cb04288 rust
construct directory tree in outdir
1 files changed, 20 insertions(+), 9 deletions(-)

M tinywiki_rs/src/main.rs
M tinywiki_rs/src/main.rs => tinywiki_rs/src/main.rs +20 -9
@@ 1,10 1,6 @@
/*
 * TODO:
 * - build folder strucutre in output dir
 */

pub mod build_tree;

use std::fs::File;
use std::ops::Index;
use std::path::PathBuf;
use std::process::exit;


@@ 36,7 32,11 @@ fn build_file(state: &State, file: PathBuf) {
    let mut pandoc = pandoc::new();
    pandoc.set_show_cmdline(true);
    let mut outputfile = PathBuf::from(&state.cli_options.outdir);
    outputfile.push(file.file_name().unwrap());
    let relpath = file.strip_prefix(&state.cli_options.workdir).unwrap();
    let mut path_to_root = PathBuf::new();
    outputfile.push(relpath);
    fs::create_dir_all(outputfile.parent().unwrap()).unwrap();
    File::create(&outputfile).unwrap();
    if !(outputfile.set_extension("html")) {
        todo!("Implement case, that file extension change failed")
    }


@@ 44,6 44,7 @@ fn build_file(state: &State, file: PathBuf) {
    pandoc.add_input(&file);
    pandoc.set_output(OutputKind::File(outputfile));
    pandoc.add_option(pandoc::PandocOption::Standalone);
    pandoc.add_option(pandoc::PandocOption::Template(PathBuf::from("/home/zeno/.local/share/tinywiki/template.html")));
    match &state.cli_options.basepath {
        Some(path) => {
            pandoc.add_option(pandoc::PandocOption::Css(


@@ 51,16 52,17 @@ fn build_file(state: &State, file: PathBuf) {
            ));
        }
        None => {
            let mut path_to_root = PathBuf::new();
            let file_ancestor_iter = file.parent().unwrap().ancestors();
            let mut tmp = state.cli_options.outdir.clone();
            tmp.pop();
            for ancestor in file_ancestor_iter {
                println!("{:#?}, {:#?}", ancestor, tmp);
                if ancestor == tmp {
                    break;
                }
                path_to_root.push("..");
                path_to_root.push("../");
            }
            if path_to_root.to_str().unwrap() == "" {
                path_to_root.push("./");
            }
            let css_path = path_to_root
                .join(state.settings.css_path.clone())


@@ 70,6 72,7 @@ fn build_file(state: &State, file: PathBuf) {
            pandoc.add_option(pandoc::PandocOption::Css(css_path));
        }
    }
    pandoc.add_option(pandoc::PandocOption::Var("home".to_string(), Some(path_to_root.to_str().unwrap().to_string() + "index.html")));
    match pandoc.execute() {
        Ok(_val) => {}
        Err(e) => {


@@ 126,11 129,19 @@ fn setup_out_dir(state: &State) {
    let mut asset_dir: PathBuf = state.cli_options.outdir.clone();
    asset_dir.push("assets/");
    fs::create_dir_all(&asset_dir).unwrap();
    File::create(asset_dir.to_str().unwrap().to_owned() + "template.html").unwrap();
    fs::copy("/home/zeno/code/tinywiki/template.html", asset_dir.to_str().unwrap().to_owned() + "template.html").unwrap();
    asset_dir.push("css/");
    fs::create_dir_all(&asset_dir).unwrap();
    File::create(asset_dir.to_str().unwrap().to_owned() + "style.css").unwrap();
    File::create(asset_dir.to_str().unwrap().to_owned() + "katex.min.css").unwrap();
    fs::copy("/home/zeno/code/tinywiki/style.css", asset_dir.to_str().unwrap().to_owned() + "style.css").unwrap();
    fs::copy("/home/zeno/.local/share/tinywiki/katex.min.css", asset_dir.to_str().unwrap().to_owned() + "katex.min.css").unwrap();
    asset_dir.pop();
    asset_dir.push("js/");
    fs::create_dir_all(&asset_dir).unwrap();
    File::create(asset_dir.to_str().unwrap().to_owned() + "katex.min.js").unwrap();
    fs::copy("/home/zeno/.local/share/tinywiki/katex.min.js", asset_dir.to_str().unwrap().to_owned() + "katex.min.js").unwrap();
}

fn cleanup_out_dir(state: &State) {