aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-06 23:25:26 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-06 23:25:26 +0800
commit7aa1c1ccfdcbaf90805072751d9d0ae0a77cca6c (patch)
treecc2a5e9bbdbcb67c3a35564d90c5363c21da079e
parent81635b93c597b10282cb14e0873f5e3d22395186 (diff)
Add .name file support for custom sidebar directory display names
-rw-r--r--dev_tools/src/bin/docsify-sidebar-gen.rs19
-rw-r--r--docs/_zh_CN/_sidebar.md2
-rw-r--r--docs/_zh_CN/pages/other/.name1
3 files changed, 20 insertions, 2 deletions
diff --git a/dev_tools/src/bin/docsify-sidebar-gen.rs b/dev_tools/src/bin/docsify-sidebar-gen.rs
index ccd2641..319b2da 100644
--- a/dev_tools/src/bin/docsify-sidebar-gen.rs
+++ b/dev_tools/src/bin/docsify-sidebar-gen.rs
@@ -73,7 +73,9 @@ fn build_sidebar_content(base_dir: &Path, pages_dir: &Path, sidebar_head: &str)
let dir_name = entry.file_name().to_string_lossy().to_string();
let entries = collect_markdown_files(&path, base_dir);
if !entries.is_empty() {
- sub_dirs.insert(dir_name, entries);
+ // Check for .name file to override directory display name
+ let display_name = get_directory_display_name(&path, &dir_name);
+ sub_dirs.insert(display_name, entries);
}
} else if path.extension().is_some_and(|ext| ext == "md") {
let title = extract_title(&path);
@@ -167,6 +169,21 @@ fn extract_title(path: &Path) -> String {
)
}
+/// Read `.name` file inside a directory to get its display name for the sidebar.
+/// Falls back to the directory name itself if no `.name` file exists.
+fn get_directory_display_name(dir_path: &std::path::Path, fallback: &str) -> String {
+ let name_file = dir_path.join(".name");
+ if name_file.exists() && name_file.is_file() {
+ std::fs::read_to_string(&name_file)
+ .ok()
+ .map(|s| s.trim().to_string())
+ .filter(|s| !s.is_empty())
+ .unwrap_or_else(|| fallback.to_string())
+ } else {
+ fallback.to_string()
+ }
+}
+
fn find_git_repo() -> Option<std::path::PathBuf> {
let mut current_dir = std::env::current_dir().ok()?;
diff --git a/docs/_zh_CN/_sidebar.md b/docs/_zh_CN/_sidebar.md
index 5d0ebe1..12e7f94 100644
--- a/docs/_zh_CN/_sidebar.md
+++ b/docs/_zh_CN/_sidebar.md
@@ -1,5 +1,5 @@
- [Welcome!](README)
* [介绍](pages/1-intro)
* [初次上手!](pages/2-step1)
-* other
+* 其他
* [命名规范](pages/other/naming_rule)
diff --git a/docs/_zh_CN/pages/other/.name b/docs/_zh_CN/pages/other/.name
new file mode 100644
index 0000000..6ab5ab1
--- /dev/null
+++ b/docs/_zh_CN/pages/other/.name
@@ -0,0 +1 @@
+其他