--- /dev/null
+use std::env;
+use std::path::PathBuf;
+
+pub struct Configuration {
+ // Default Base Directories, default to XDG dirs but can be
+ pub output_directory: PathBuf,
+}
+
+impl Configuration {
+
+ pub fn new() -> Self {
+ let output_directory = Configuration::directory(
+ "PAGE_OUTPUT_DIRECTORY",
+ "XDG_CACHE_HOME",
+ ".cache",
+ "page"
+ );
+
+ Configuration {
+ output_directory,
+ }
+ }
+
+ fn directory(user_override: &str, default_value: &str, home_fallback: &str, path: &str) -> PathBuf {
+ match env::var(user_override) {
+ Ok(directory) => PathBuf::from(directory),
+ Err(_) => match env::var(default_value) {
+ Ok(directory) => PathBuf::from(directory),
+ Err(_) => match env::var("HOME") {
+ Ok(directory) => PathBuf::from(directory).join(home_fallback),
+ Err(_) => panic!("Could not find required directory, {} or {} should be set and readable.", user_override, default_value),
+ },
+ },
+ }.join(path)
+ }
+}
+
LineType::Link => {
let url = get_link_address(line);
if url.starts_with("gemini:") {
- format!("<div><a href=\"{}\">{}</a></div>\n", url, get_link_content(line))
+ format!("<p class=\"a\"><a href=\"{}\">{}</a></p>\n", url, get_link_content(line))
} else {
- format!("<div><a href=\"{}\">{}</a></div>\n", url.replace(".gmi", ".html"), get_link_content(line))
+ format!("<p class=\"a\"><a href=\"{}\">{}</a></p>\n", url.replace(".gmi", ".html"), get_link_content(line))
}
},
LineType::Heading1 => format!("<h1>{}</h1>\n", encoded_line[1..].trim()),
break;
}
- string.push_str("</div>");
+ string.push_str("</section>");
if open_heading == current_heading {
break;
}
}
heading_stack.push(current_heading);
- string.push_str(&format!("<div class=\"h{}\">", current_heading));
+ string.push_str(&format!("<section class=\"h{}\">", current_heading));
}
return string;
fn close_heading_wrapper(heading_stack: &mut Vec<u8>) -> String {
let mut string = String::new();
while let Some(_open_heading) = heading_stack.pop() {
- string.push_str("</div>");
+ string.push_str("</section>");
}
return string;
}