mirror of
https://github.com/lise-henry/crowbook
synced 2024-09-22 17:31:57 +02:00
Add support for more metadata
This commit is contained in:
parent
6787941478
commit
b52cbefa90
@ -658,10 +658,13 @@ impl Book {
|
||||
"tex" => escape_tex,
|
||||
_ => panic!("get mapbuilder called with invalid escape format")
|
||||
};
|
||||
let mut mapbuilder = MapBuilder::new()
|
||||
.insert_str("author", f(self.options.get_str("author").unwrap()))
|
||||
.insert_str("title", f(&self.options.get_str("title").unwrap()))
|
||||
.insert_str("lang", self.options.get_str("lang").unwrap().to_owned());
|
||||
let mut mapbuilder = MapBuilder::new();
|
||||
for key in self.options.get_metadata() {
|
||||
if let Ok(s) = self.options.get_str(key) {
|
||||
mapbuilder = mapbuilder.insert_str(key, f(s));
|
||||
mapbuilder = mapbuilder.insert_bool(&format!("has_{}", key), true);
|
||||
}
|
||||
}
|
||||
let hash = lang::get_hash(self.options.get_str("lang").unwrap());
|
||||
for (key, value) in hash.into_iter() {
|
||||
let key = format!("loc_{}", key.as_str().unwrap());
|
||||
|
@ -17,6 +17,12 @@ lang:str:en # Language of the book
|
||||
subject:str # Subject of the book (used for EPUB metadata)
|
||||
description:str # Description of the book (used for EPUB metadata)
|
||||
cover:path # Path to the cover of the book
|
||||
|
||||
# Metadata (additional)
|
||||
license:str # License of the book
|
||||
version:str # Version of the book
|
||||
date:str # Date the book was revised
|
||||
|
||||
# Output options
|
||||
output.epub:path # Output file name for EPUB rendering
|
||||
output.html:path # Output file name for HTML rendering
|
||||
@ -99,6 +105,7 @@ pub struct BookOptions {
|
||||
valid_strings: Vec<&'static str>,
|
||||
valid_paths: Vec<&'static str>,
|
||||
valid_ints: Vec<&'static str>,
|
||||
metadata: Vec<&'static str>,
|
||||
|
||||
/// Source for errors (unnecessary copy :/)
|
||||
pub source: Source,
|
||||
@ -118,17 +125,30 @@ impl BookOptions {
|
||||
valid_ints:vec!(),
|
||||
valid_strings:vec!(),
|
||||
valid_paths:vec!(),
|
||||
metadata: vec!(),
|
||||
root: PathBuf::new(),
|
||||
source: Source::empty(),
|
||||
};
|
||||
|
||||
for (_, key, option_type, default_value) in Self::options_to_vec() {
|
||||
|
||||
// Load default options and types from OPTIONS
|
||||
let mut is_metadata = false;
|
||||
for (comment, key, option_type, default_value) in Self::options_to_vec() {
|
||||
if key.is_none() {
|
||||
if comment.contains("Metadata") || comment.contains("metadata") {
|
||||
is_metadata = true;
|
||||
} else {
|
||||
is_metadata = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let key = key.unwrap();
|
||||
match option_type.unwrap() {
|
||||
"str" => options.valid_strings.push(key),
|
||||
"str" => {
|
||||
if is_metadata {
|
||||
options.metadata.push(key);
|
||||
}
|
||||
options.valid_strings.push(key);
|
||||
},
|
||||
"bool" => options.valid_bools.push(key),
|
||||
"int" => options.valid_ints.push(key),
|
||||
"char" => options.valid_chars.push(key),
|
||||
@ -277,6 +297,11 @@ impl BookOptions {
|
||||
format!("could not parse '{}' as a valid YAML value", value)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the list of keys that are metadata
|
||||
pub fn get_metadata(&self) -> &[&'static str] {
|
||||
&self.metadata
|
||||
}
|
||||
|
||||
/// Gets an option
|
||||
pub fn get(&self, key: &str) -> Result<&BookOption> {
|
||||
|
@ -7,9 +7,9 @@ use std::io::Write;
|
||||
pub enum InfoLevel {
|
||||
/// Debug: the lowest level
|
||||
Debug = 0,
|
||||
/// Info: won't be displayed by default
|
||||
/// Warning: won't be displayed by default
|
||||
Warning,
|
||||
/// Warning: the default level
|
||||
/// Info: won't be displayed by default
|
||||
Info,
|
||||
/// Error
|
||||
Error
|
||||
|
Loading…
Reference in New Issue
Block a user