diff options
Diffstat (limited to 'src/metadata.rs')
-rw-r--r-- | src/metadata.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/metadata.rs b/src/metadata.rs index e3463b3..dc28ac4 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -50,6 +50,7 @@ pub struct YamlMetadata { documentclass: Option<String>, #[serde(default)] impls: BTreeMap<String, Vec<PathBuf>>, + css_embed: Option<Vec<PathBuf>>, } impl YamlMetadata { @@ -167,6 +168,7 @@ pub struct Metadata { impls: HashMap<String, DocumentImpl>, /// Extra class names which should be considered 'correct' for this document classes: Vec<String>, + css_embed: Vec<String>, } #[derive(Debug)] @@ -208,6 +210,17 @@ impl Metadata { vec![] }; + let mut css_embed = vec![]; + if let Some(filenames) = &yaml.css_embed { + for filename in filenames.iter() { + let css = std::fs::read(filename) + .map_err(|e| SubplotError::ReadFile(filename.into(), e))?; + let css = String::from_utf8(css) + .map_err(|e| SubplotError::FileUtf8(filename.into(), e))?; + css_embed.push(css); + } + } + let meta = Self { basedir: basedir.as_ref().to_path_buf(), title: yaml.title().into(), @@ -218,6 +231,7 @@ impl Metadata { bindings, impls, classes, + css_embed, }; trace!("metadata: {:#?}", meta); @@ -278,6 +292,11 @@ impl Metadata { pub fn classes(&self) -> impl Iterator<Item = &str> { self.classes.iter().map(Deref::deref) } + + /// Contents of CSS files to embed into the HTML output. + pub fn css_embed(&self) -> impl Iterator<Item = &str> { + self.css_embed.iter().map(Deref::deref) + } } impl DocumentImpl { |