From: Ruben Beltran del Rio Date: Wed, 17 Jul 2024 17:00:41 +0000 (+0200) Subject: Use sections instead of divs X-Git-Url: https://git.r.bdr.sh/rbdr/page/commitdiff_plain/45fbf824248215a737d5d0b52920b43b68941ad3?ds=inline Use sections instead of divs --- diff --git a/Cargo.lock b/Cargo.lock index f8ef2e2..bafb58c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "page" -version = "1.3.1" +version = "1.3.2" diff --git a/Cargo.toml b/Cargo.toml index ebec913..5c0f2f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "page" -version = "1.3.1" +version = "1.3.2" edition = "2021" license = "AGPL-3.0-or-later" description = "Command line tool to generate a static website and gemini capsule from a directory with gemtext." diff --git a/src/configuration.rs b/src/configuration.rs new file mode 100644 index 0000000..a09d780 --- /dev/null +++ b/src/configuration.rs @@ -0,0 +1,37 @@ +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) + } +} + diff --git a/src/gemini_parser.rs b/src/gemini_parser.rs index a7c752e..496dc0d 100644 --- a/src/gemini_parser.rs +++ b/src/gemini_parser.rs @@ -89,9 +89,9 @@ fn get_full_line_content(line_type: &LineType, line: &str) -> String { LineType::Link => { let url = get_link_address(line); if url.starts_with("gemini:") { - format!("
{}
\n", url, get_link_content(line)) + format!("

{}

\n", url, get_link_content(line)) } else { - format!("
{}
\n", url.replace(".gmi", ".html"), get_link_content(line)) + format!("

{}

\n", url.replace(".gmi", ".html"), get_link_content(line)) } }, LineType::Heading1 => format!("

{}

\n", encoded_line[1..].trim()), @@ -119,14 +119,14 @@ fn get_heading_wrapper(heading_stack: &mut Vec, line_type: &LineType) -> Str break; } - string.push_str(""); + string.push_str(""); if open_heading == current_heading { break; } } heading_stack.push(current_heading); - string.push_str(&format!("
", current_heading)); + string.push_str(&format!("
", current_heading)); } return string; @@ -135,7 +135,7 @@ fn get_heading_wrapper(heading_stack: &mut Vec, line_type: &LineType) -> Str fn close_heading_wrapper(heading_stack: &mut Vec) -> String { let mut string = String::new(); while let Some(_open_heading) = heading_stack.pop() { - string.push_str("
"); + string.push_str(""); } return string; }