1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use mdbook::{
book::Book,
errors,
preprocess::{Preprocessor, PreprocessorContext},
Config,
};
use std::{
path::{Path, PathBuf},
result,
};
macro_rules! default {
($idt:ident, $e1:expr) => { (CssFile::$idt, $e1) };
($idt:ident, $e1:expr, $e2:expr) => { (CssFile::$idt, Item($e1), Value($e2)) };
($($e1:expr, $idt:ident);*) => {
$(pub static $idt: &[u8] = include_bytes!($e1);)*
pub static ACE_DEFAULT: &[(&str, &[u8])] = &[$(($e1, $idt),)*];
};
}
pub mod ace;
pub mod theme;
#[derive(Debug)]
pub enum Error {
StrNotFound,
FileNotFound,
FileNotCreated,
FileNotWritten,
DirNotCreated,
DirNotRemoved,
DirNotRead,
AceNotFound,
MdbookNotParsed,
DeserializedFailed,
}
pub type Result<T> = std::result::Result<T, Error>;
pub struct PreTheme;
pub fn theme_dir(root: &Path, config: &Config) -> PathBuf {
let theme_dir_ = config
.get("output.html.theme")
.and_then(|v| v.as_str())
.unwrap_or("theme");
root.join(theme_dir_)
}
impl Preprocessor for PreTheme {
fn name(&self) -> &str {
"theme"
}
fn run(&self, ctx: &PreprocessorContext, book: Book) -> result::Result<Book, errors::Error> {
let dir = theme_dir(&ctx.root, &ctx.config);
if let Some(theme) = ctx.config.get_preprocessor(self.name()) {
theme::config::run(theme, dir);
}
Ok(book)
}
fn supports_renderer(&self, renderer: &str) -> bool {
renderer == "html"
}
}