summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-10-30 18:45:13 +0200
committerLars Wirzenius <liw@liw.fi>2023-10-30 19:08:10 +0200
commit5a84e1bde773bdc782c1db5a633ef8765f220253 (patch)
tree93b283272bcc4854cbd96592dd381d09f77cac77 /src
parent7252cf5c1e0288b1bbb54908999fc7524d12bf1e (diff)
downloadsubplot-5a84e1bde773bdc782c1db5a633ef8765f220253.tar.gz
feat: allow .subplot to list CSS files to embed in HTML output
This is in the meta data field "css_embed". Signed-off-by: Lars Wirzenius <liw@liw.fi> Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r--src/doc.rs3
-rw-r--r--src/metadata.rs19
2 files changed, 22 insertions, 0 deletions
diff --git a/src/doc.rs b/src/doc.rs
index f3f9641..83b5ec2 100644
--- a/src/doc.rs
+++ b/src/doc.rs
@@ -155,6 +155,9 @@ impl Document {
let mut css = Element::new(ElementTag::Style);
css.push_child(Content::Text(CSS.into()));
+ for css_file in self.meta.css_embed() {
+ css.push_child(Content::Text(css_file.into()));
+ }
head.push_child(Content::Elt(css));
self.meta.set_date(date.into());
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 {