zensical:docs - add comment on title handling

Signed-off-by: Martin Donath <martin.donath@squidfunk.com>
This commit is contained in:
Martin Donath
2025-11-11 19:07:17 +01:00
committed by GitHub
parent 98d4bdd822
commit dcd6f7648d
+7 -2
View File
@@ -410,6 +410,8 @@ pub(crate) fn to_title(component: &str) -> String {
let title = component.trim_end_matches(".md").replace(['-', '_'], " ");
let first = title.chars().next().unwrap_or_default();
// Only uppercase first character if it's an ASCII character, and keep
// other languages like Chinese as-is
if title.to_lowercase() == title && first.is_ascii_alphabetic() {
first.to_uppercase().to_string() + &title[1..]
} else {
@@ -417,6 +419,10 @@ pub(crate) fn to_title(component: &str) -> String {
}
}
// ----------------------------------------------------------------------------
// Tests
// ----------------------------------------------------------------------------
#[cfg(test)]
mod tests {
use super::*;
@@ -424,8 +430,7 @@ mod tests {
/// https://github.com/zensical/zensical/issues/66
#[test]
fn test_to_title() {
assert_eq!(to_title("编译器笔记"), "编译器笔记");
assert_eq!(to_title("hello-world"), "Hello world");
assert_eq!(to_title("hello_world"), "Hello world");
assert_eq!(to_title("编译器笔记"), "编译器笔记");
}
}