diff options
| author | Ben Bridle <bridle.benjamin@gmail.com> | 2026-02-06 14:55:05 +1300 |
|---|---|---|
| committer | Ben Bridle <bridle.benjamin@gmail.com> | 2026-02-06 14:55:05 +1300 |
| commit | 8c2ac6d92f6a4579591f748eebcbca2b9913d92d (patch) | |
| tree | b93f4fed5676f292e5070d11e2817655516fb355 /src/main.rs | |
| parent | dc985df5fe8c748e05181a8f5062eba3f9a2b64a (diff) | |
| download | toaster-8c2ac6d92f6a4579591f748eebcbca2b9913d92d.zip | |
Move string utilities to separate module
This makes things tidier.
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 24 |
1 files changed, 2 insertions, 22 deletions
diff --git a/src/main.rs b/src/main.rs index 33fe16d..32b0ab9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,10 @@ mod collect_files; mod generate_html; +mod string_utils; pub use collect_files::*; pub use generate_html::*; +pub use string_utils::*; use markdown::*; use vagabond::*; @@ -165,25 +167,3 @@ pub fn write_file(text: &str, destination: &PathBuf, ext: &str, last_modified: O } } } - -// Turn a string into a tidy URL slug. -pub fn make_url_safe(text: &str) -> String { - text.to_ascii_lowercase().chars().filter_map(|c| - if c.is_alphanumeric() || "-_~.+/#".contains(c) { Some(c) } - else if c == ' ' { Some('-') } - else { None } ) - .collect() -} - -// Prevent link hrefs from breaking out of quotations. -pub fn url_encode(text: &str) -> String { - let mut output = String::new(); - for c in text.chars() { - match c { - '"' => output.push_str("%22"), - '\'' => output.push_str("%27"), - _ => output.push(c), - } - } - return output; -} |
