This commit is contained in:
KitsuneCafe 2024-02-15 02:11:28 -05:00
parent 3bdc75c59c
commit 4ad7bf5786
6 changed files with 104 additions and 86 deletions

107
Cargo.lock generated
View file

@ -155,9 +155,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "chrono" name = "chrono"
version = "0.4.33" version = "0.4.34"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b"
dependencies = [ dependencies = [
"android-tzdata", "android-tzdata",
"iana-time-zone", "iana-time-zone",
@ -167,9 +167,9 @@ dependencies = [
[[package]] [[package]]
name = "chrono-tz" name = "chrono-tz"
version = "0.8.5" version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91d7b79e99bfaa0d47da0687c43aa3b7381938a62ad3a6498599039321f660b7" checksum = "d59ae0466b83e838b81a54256c39d5d7c20b9d7daa10510a242d9b75abd5936e"
dependencies = [ dependencies = [
"chrono", "chrono",
"chrono-tz-build", "chrono-tz-build",
@ -189,9 +189,9 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.4.18" version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" checksum = "80c21025abd42669a92efc996ef13cfb2c5c627858421ea58d5c3b331a6c134f"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
"clap_derive", "clap_derive",
@ -199,9 +199,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_builder" name = "clap_builder"
version = "4.4.18" version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" checksum = "458bf1f341769dfcf849846f65dffdf9146daa56bcd2a47cb4e1de9915567c99"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
@ -211,9 +211,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "4.4.7" version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
@ -223,9 +223,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_lex" name = "clap_lex"
version = "0.6.0" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
[[package]] [[package]]
name = "colorchoice" name = "colorchoice"
@ -250,9 +250,9 @@ dependencies = [
[[package]] [[package]]
name = "crc32fast" name = "crc32fast"
version = "1.3.2" version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
] ]
@ -385,7 +385,7 @@ dependencies = [
"bstr", "bstr",
"log", "log",
"regex-automata", "regex-automata",
"regex-syntax 0.8.2", "regex-syntax",
] ]
[[package]] [[package]]
@ -461,9 +461,9 @@ dependencies = [
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.2.2" version = "2.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177"
dependencies = [ dependencies = [
"equivalent", "equivalent",
"hashbrown", "hashbrown",
@ -477,9 +477,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.67" version = "0.3.68"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee"
dependencies = [ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
@ -546,9 +546,9 @@ checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.17" version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
dependencies = [ dependencies = [
"autocfg", "autocfg",
] ]
@ -681,9 +681,9 @@ dependencies = [
[[package]] [[package]]
name = "pkg-config" name = "pkg-config"
version = "0.3.29" version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
[[package]] [[package]]
name = "plist" name = "plist"
@ -789,7 +789,7 @@ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
"regex-automata", "regex-automata",
"regex-syntax 0.8.2", "regex-syntax",
] ]
[[package]] [[package]]
@ -800,15 +800,9 @@ checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
"regex-syntax 0.8.2", "regex-syntax",
] ]
[[package]]
name = "regex-syntax"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.8.2" version = "0.8.2"
@ -978,9 +972,9 @@ dependencies = [
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.10.0" version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01"
[[package]] [[package]]
name = "syn" name = "syn"
@ -995,9 +989,9 @@ dependencies = [
[[package]] [[package]]
name = "syntect" name = "syntect"
version = "5.1.0" version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e02b4b303bf8d08bfeb0445cba5068a3d306b6baece1d5582171a9bf49188f91" checksum = "874dcfa363995604333cf947ae9f751ca3af4522c60886774c4963943b4746b1"
dependencies = [ dependencies = [
"bincode", "bincode",
"bitflags 1.3.2", "bitflags 1.3.2",
@ -1006,8 +1000,9 @@ dependencies = [
"once_cell", "once_cell",
"onig", "onig",
"plist", "plist",
"regex-syntax 0.7.5", "regex-syntax",
"serde", "serde",
"serde_derive",
"serde_json", "serde_json",
"thiserror", "thiserror",
"walkdir", "walkdir",
@ -1038,18 +1033,18 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.56" version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "1.0.56" version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1089,9 +1084,9 @@ dependencies = [
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.8.9" version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6a4b9e8023eb94392d3dca65d717c53abc5dad49c07cb65bb8fcd87115fa325" checksum = "9a9aad4a3066010876e8dcf5a8a06e70a558751117a145c6ce2b82c2e2054290"
dependencies = [ dependencies = [
"serde", "serde",
"serde_spanned", "serde_spanned",
@ -1110,9 +1105,9 @@ dependencies = [
[[package]] [[package]]
name = "toml_edit" name = "toml_edit"
version = "0.21.1" version = "0.22.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" checksum = "99e68c159e8f5ba8a28c4eb7b0c0c190d77bb479047ca713270048145a9ad28a"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"serde", "serde",
@ -1240,9 +1235,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.90" version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"wasm-bindgen-macro", "wasm-bindgen-macro",
@ -1250,9 +1245,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-backend" name = "wasm-bindgen-backend"
version = "0.2.90" version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"log", "log",
@ -1265,9 +1260,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.90" version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@ -1275,9 +1270,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.90" version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1288,9 +1283,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.90" version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838"
[[package]] [[package]]
name = "winapi" name = "winapi"
@ -1400,9 +1395,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
[[package]] [[package]]
name = "winnow" name = "winnow"
version = "0.5.37" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7cad8365489051ae9f054164e459304af2e7e9bb407c958076c8bf4aef52da5" checksum = "d90f4e0f530c4c69f62b80d839e9ef3855edc9cba471a160c4d692deed62b401"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]

View file

@ -14,6 +14,6 @@ roxy_core = { git = "https://fem.mint.lgbt/kitsunecafe/roxy-core.git" }
clap = { version = "4.4.17", features = ["derive"] } clap = { version = "4.4.17", features = ["derive"] }
toml = "0.8.8" toml = "0.8.8"
tera = "1.19.1" tera = "1.19.1"
serde = "1.0.195" serde = { version = "1.0.195", features = ["derive"]}
slugify = "0.1.0" slugify = "0.1.0"

View file

@ -1,6 +1,7 @@
use serde::Deserialize;
use std::str::FromStr; use std::str::FromStr;
use serde::Deserialize;
use crate::DEFAULT_THEME; use crate::DEFAULT_THEME;
pub(crate) trait Merge { pub(crate) trait Merge {

View file

@ -1,4 +1,3 @@
use roxy_core::error::Error;
use slugify::slugify; use slugify::slugify;
use std::{ use std::{
ffi::OsStr, ffi::OsStr,
@ -66,13 +65,12 @@ impl<'a, P: AsRef<Path> + 'a> FilePath<'a, P> {
} }
} }
pub fn to_output<P2: AsRef<Path>>(&self, value: &'a P2) -> Result<PathBuf, Error> { pub fn to_output<P2: AsRef<Path>>(&self, value: &'a P2) -> Option<PathBuf> {
value let value = value.as_ref();
.as_ref() let path = value.strip_prefix(&self.root_dir).unwrap_or_else(|_| value);
.strip_prefix(&self.root_dir)
.map(|p| self.as_slug(p).expect("could not slugify path")) self.as_slug(path)
.map(|path| self.output.as_ref().join(path)) .map(|path| self.output.as_ref().join(path))
.map_err(Error::from)
} }
pub fn strip_root<P2: AsRef<Path>>(&self, value: &'a P2) -> Result<&Path, StripPrefixError> { pub fn strip_root<P2: AsRef<Path>>(&self, value: &'a P2) -> Result<&Path, StripPrefixError> {

View file

@ -31,6 +31,8 @@ use toml::Table;
use glob::glob; use glob::glob;
use roxy_core::roxy::{Parser, Roxy}; use roxy_core::roxy::{Parser, Roxy};
use crate::{iter_ext::{MapFoldExt, Head}, result_ext::FilterExt};
const DEFAULT_THEME: &'static str = "base16-ocean.dark"; const DEFAULT_THEME: &'static str = "base16-ocean.dark";
const CONTENT_EXT: [&'static str; 4] = ["md", "tera", "html", "htm"]; const CONTENT_EXT: [&'static str; 4] = ["md", "tera", "html", "htm"];
@ -64,25 +66,22 @@ fn get_files<P: AsRef<Path> + std::fmt::Debug>(path: &P) -> Result<Vec<PathBuf>,
} }
fn try_find_file(path: &Path) -> Option<PathBuf> { fn try_find_file(path: &Path) -> Option<PathBuf> {
if let Some(file_name) = path.file_name() { let file_name = path.file_name()?;
let mut path = path;
let mut result = None;
while let Some(parent) = path.parent() { let paths = path
let file = parent.with_file_name(file_name); .with_file_name("")
.components()
.map_fold(PathBuf::new(), |acc, path| acc.join(path))
.collect::<Vec<PathBuf>>();
if file.is_file() { paths
result = Some(file); .iter()
break; .rev()
} .skip(1)
.filter_map(|p| p.with_file_name(file_name).canonicalize().ok())
path = parent; .take(1)
} .head()
.map(|x| x.0)
result
} else {
None
}
} }
fn load_config(path: &Path) -> Config { fn load_config(path: &Path) -> Config {
@ -134,9 +133,9 @@ fn copy_static<T: AsRef<Path>>(
file_path: &FilePath<T>, file_path: &FilePath<T>,
) -> Result<(), Error> { ) -> Result<(), Error> {
for file in files { for file in files {
let output = file_path.to_output(file)?; let output = file_path.to_output(file).unwrap();
fs::create_dir_all(output.parent().unwrap())?; fs::create_dir_all(output.parent().unwrap())?;
fs::copy(file, file_path.to_output(file)?)?; fs::copy(file, output)?;
} }
Ok(()) Ok(())
@ -169,14 +168,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let syntax_set = SyntaxSet::load_defaults_newlines(); let syntax_set = SyntaxSet::load_defaults_newlines();
let theme_set = if let Some(dir) = config.syntect.theme_dir { let theme_set = if let Some(dir) = config.syntect.theme_dir {
ThemeSet::load_from_folder(dir)? let path = file_path.input.join(dir);
try_find_file(path.as_path())
.and_then(|p| ThemeSet::load_from_folder(p).ok())
.unwrap_or_else(|| ThemeSet::load_defaults())
} else { } else {
ThemeSet::load_defaults() ThemeSet::load_defaults()
}; };
for file in content { for file in content {
let file_name = file.with_extension("html"); let file_name = file.with_extension("html");
let output_path = file_path.to_output(&file_name)?; let output_path = file_path.to_output(&file_name).unwrap();
let mut parser = Parser::new(); let mut parser = Parser::new();
let mut preformatter = MarkdownTeraPreformatter::new(); let mut preformatter = MarkdownTeraPreformatter::new();

View file

@ -2,6 +2,28 @@ pub(crate) trait ResultExt<T, E>: Sized {
fn then_err_into<U, E2: From<E>>(self, op: impl FnOnce(T) -> Result<U, E2>) -> Result<U, E2>; fn then_err_into<U, E2: From<E>>(self, op: impl FnOnce(T) -> Result<U, E2>) -> Result<U, E2>;
} }
pub(crate) trait FilterExt<T> {
fn filter(self, op: impl FnOnce(&T) -> bool) -> Self;
}
impl<T, E> FilterExt<T> for Result<T, E> {
fn filter(self, op: impl FnOnce(&T) -> bool) -> Self {
match self {
Ok(x) if op(&x) => Ok(x),
e => e,
}
}
}
impl<T> FilterExt<T> for Option<T> {
fn filter(self, op: impl FnOnce(&T) -> bool) -> Self {
match self {
Some(x) if op(&x) => Some(x),
v => v,
}
}
}
impl<T, E> ResultExt<T, E> for Result<T, E> { impl<T, E> ResultExt<T, E> for Result<T, E> {
fn then_err_into<U, E2: From<E>>(self, op: impl FnOnce(T) -> Result<U, E2>) -> Result<U, E2> { fn then_err_into<U, E2: From<E>>(self, op: impl FnOnce(T) -> Result<U, E2>) -> Result<U, E2> {
op(self?) op(self?)