html template

This commit is contained in:
xfnw 2024-03-23 12:24:29 -04:00
parent fa52cb5fe1
commit ab8fb14599
4 changed files with 37 additions and 2 deletions

7
Cargo.lock generated
View File

@ -57,6 +57,7 @@ dependencies = [
"boilerplate",
"clap",
"git2",
"html-escaper",
"orgize",
"rowan",
"serde",
@ -188,6 +189,12 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "html-escaper"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "459a0ca33ee92551e0a3bb1774f2d3bdd1c09fb6341845736662dd25e1fcb52a"
[[package]]
name = "ident_case"
version = "1.0.1"

View File

@ -9,6 +9,7 @@ edition = "2021"
boilerplate = "1.0.0"
clap = { version = "4.5.3", default-features = false, features = ["derive", "std", "help", "usage"] }
git2 = { version = "0.18.3", default-features = false }
html-escaper = "0.2.0"
orgize = "=0.10.0-alpha.7"
rowan = "0.15.15"
serde = "1.0.197"

View File

@ -1,5 +1,6 @@
use clap::Parser;
use git2::Repository;
use html_escaper::{Escape, Trusted};
use orgize::{ast::Keyword, ParseConfig};
use rowan::ast::{support, AstNode};
use std::{collections::BTreeMap, error::Error, fs, io::Write, path::PathBuf};
@ -13,6 +14,13 @@ struct Opt {
branch: String,
}
#[derive(boilerplate::Boilerplate)]
struct PageHtml<'a> {
title: String,
body: String,
commit: &'a str,
}
fn walk_callback(
repo: &Repository,
dir: &str,
@ -42,7 +50,7 @@ fn generate(
org_cfg: &ParseConfig,
_repo: &Repository,
dir_map: &BTreeMap<String, Vec<(String, Vec<u8>)>>,
_id: &str,
id: &str,
) -> Result<(), Box<dyn Error>> {
for (dir, files) in dir_map.iter() {
fs::create_dir_all(dir)?;
@ -67,7 +75,12 @@ fn generate(
}
};
Some(res.to_html().into_bytes())
let template = PageHtml {
title,
body: res.to_html(),
commit: id,
};
Some(template.to_string().into_bytes())
}
_ => None,
};

14
templates/page.html Normal file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ self.title }}</title>
</head>
<body>
<h1>{{ self.title }}</h1>
{{ Trusted(&self.body) }}
<footer>
<hr>
generated from {{ self.commit }} with <a href="https://github.com/xfnw/clam">clam</a>.
</footer>
</body>
</html>