summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/collect_files.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/collect_files.rs b/src/collect_files.rs
index 49f5cc0..9c7ac24 100644
--- a/src/collect_files.rs
+++ b/src/collect_files.rs
@@ -2,9 +2,12 @@ use crate::*;
use vagabond::*;
+use std::collections::HashMap;
+
pub struct Website {
pub name: String,
+ pub config: HashMap<String, String>,
pub pages: Vec<Page>,
pub static_files: Vec<StaticItem>,
pub static_dirs: Vec<StaticItem>,
@@ -56,6 +59,7 @@ impl Website {
Ok(entry) => entry.name,
Err(err) => error!("Couldn't open {:?}: {:?}", &path, err),
},
+ config: HashMap::new(),
};
new.collect_entry(path, path);
return new;
@@ -91,6 +95,25 @@ impl Website {
self.collect_entry(&child.original_path, prefix);
}
}
+ } else if parents.is_empty() && entry.name.to_lowercase() == "toaster.conf" {
+ // Parse the config file.
+ let config = std::fs::read_to_string(&source_path).unwrap();
+ let mut key = None;
+ let mut value = String::new();
+ for line in config.lines() {
+ if line.starts_with(" ") {
+ value.push_str(line.trim());
+ value.push('\n');
+ } else {
+ if let Some(key) = key {
+ self.config.insert(key, std::mem::take(&mut value));
+ }
+ key = Some(line.trim().to_lowercase().to_string());
+ }
+ }
+ if let Some(key) = key {
+ self.config.insert(key, std::mem::take(&mut value));
+ }
} else {
match extension.as_str() {
"md" => {
@@ -230,5 +253,9 @@ impl Website {
}
return None;
}
+
+ pub fn get_config(&self, key: &str) -> String {
+ self.config.get(key).map(String::to_owned).unwrap_or_else(String::new)
+ }
}