鏇存柊鏂囨。

This commit is contained in:
renjianbo
2026-01-13 11:22:33 +08:00
parent 506c2f55b4
commit 014ef65606
3 changed files with 95 additions and 39 deletions

View File

@@ -120,6 +120,61 @@ def categorize_file(file_path):
# 如果目录名在映射中,使用映射的名称,否则使用目录名
return category_map.get(first_dir, first_dir)
def remove_deleted_files_from_nav(nav, existing_files=None, docs_dir='docs'):
"""从导航配置中删除已不存在的文件"""
deleted_files = []
def clean_item(item):
"""递归清理导航项,删除不存在的文件"""
if isinstance(item, dict):
# 处理字典类型(分类)
cleaned_dict = {}
for key, value in item.items():
if isinstance(value, list):
# 递归处理列表
cleaned_list = []
for subitem in value:
cleaned = clean_item(subitem)
if cleaned is not None:
cleaned_list.append(cleaned)
# 如果列表不为空,保留分类
if cleaned_list:
cleaned_dict[key] = cleaned_list
elif isinstance(value, str):
# 检查文件是否存在
file_path = os.path.join(docs_dir, value.replace('/', os.sep))
if os.path.exists(file_path) or value == 'index.md':
cleaned_dict[key] = value
else:
deleted_files.append(value)
else:
# 其他类型,保留
cleaned_dict[key] = value
# 如果字典为空返回None表示删除
return cleaned_dict if cleaned_dict else None
elif isinstance(item, str):
# 检查文件是否存在
file_path = os.path.join(docs_dir, item.replace('/', os.sep))
if os.path.exists(file_path) or item == 'index.md':
return item
else:
deleted_files.append(item)
return None
else:
# 其他类型,保留
return item
# 处理导航列表
new_nav = []
for item in nav:
cleaned = clean_item(item)
if cleaned is not None:
new_nav.append(cleaned)
return new_nav, deleted_files
def add_files_to_nav(nav, missing_files):
"""将缺失的文件添加到导航配置中"""
# 创建分类字典
@@ -154,7 +209,7 @@ def add_files_to_nav(nav, missing_files):
return nav
def main():
print("开始自动docs目录下的文件添加到mkdocs.yml...")
print("开始自动同步docs目录mkdocs.yml导航配置...")
print("=" * 60)
# 1. 加载当前导航配置
@@ -171,39 +226,65 @@ def main():
nav_files = get_nav_files(nav)
print(f" 导航中已有 {len(nav_files)} 个文件")
# 4. 找出缺失的文件
# 4. 检查并删除已删除的文件
print("4. 检查已删除的文件...")
updated_nav, deleted_files = remove_deleted_files_from_nav(nav, all_md_files)
if deleted_files:
print(f" 发现 {len(deleted_files)} 个文件已删除:")
for i, file_path in enumerate(deleted_files, 1):
print(f" {i:2d}. {file_path}")
nav = updated_nav
# 重新获取导航文件列表(已更新)
nav_files = get_nav_files(nav)
else:
print(" ✓ 没有发现已删除的文件")
# 5. 找出缺失的文件(需要添加到导航的)
missing_files = []
for md_file in all_md_files:
# 将路径统一为Unix风格进行比较
if md_file not in nav_files and md_file != 'index.md':
missing_files.append(md_file)
if not missing_files:
print("✓ 所有文件已在导航中,无需更新")
# 6. 汇总变更
has_changes = len(deleted_files) > 0 or len(missing_files) > 0
if not has_changes:
print("\n✓ 导航配置已是最新,无需更新")
return
print(f"4. 发现 {len(missing_files)} 个文件不在导航中:")
# 显示变更摘要
print("\n5. 变更摘要:")
if deleted_files:
print(f" 将删除 {len(deleted_files)} 个已不存在的文件")
if missing_files:
print(f" 将添加 {len(missing_files)} 个新文件:")
for i, file_path in enumerate(missing_files, 1):
print(f" {i:2d}. {file_path}")
# 5. 确认是否继续
print("\n5. 是否继续添加这些文件到mkdocs.yml")
# 7. 确认是否继续
print("\n6. 是否继续更新mkdocs.yml")
response = input(" 输入 'y' 继续,其他键取消: ")
if response.lower() != 'y':
print("操作已取消")
return
# 6. 添加文件到导航
print("\n6. 正在更新mkdocs.yml...")
updated_nav = add_files_to_nav(nav, missing_files)
# 8. 添加文件到导航
print("\n7. 正在更新mkdocs.yml...")
if missing_files:
updated_nav = add_files_to_nav(updated_nav, missing_files)
# 7. 保存配置
# 9. 保存配置
save_mkdocs_nav(updated_nav)
print("\n" + "=" * 60)
print("完成mkdocs.yml已更新")
print(f"总计添加了 {len(missing_files)} 个文件到导航中")
if deleted_files:
print(f"删除了 {len(deleted_files)} 个已不存在的文件")
if missing_files:
print(f"添加了 {len(missing_files)} 个新文件到导航中")
if __name__ == '__main__':
main()

View File

@@ -62,39 +62,17 @@ nav:
- 学习笔记/Java学习.md
- 学习笔记/前端学习.md
- 学习笔记/DevOps学习.md
- 学习笔记/gerrit上传代码详细指南.md
- 学习笔记/gerrit分支规范.md
- 学习笔记/生成并配置SSH密钥、克隆仓库.md
- 学习笔记/git设置用户名和邮箱.md
- 学习笔记/git同步远程分支总结.md
- 学习笔记/提交代码时候的钩子.md
- 学习笔记/MkDocs 是什么.md
- 学习笔记/个人全自动研发体系.md
- 学习笔记/效率提升.md
- 学习笔记/重要.md
- 学习笔记/honor工作资料.md
- Obsidian笔记:
- Obsidian/2026-01-05 个人文档管理.md
- Obsidian/高频命令.md
- Obsidian/欢迎.md
- Obsidian/重要笔记.md
- Obsidian/资源网站.md
- Obsidian/创业/我是一名从事android 应用的开发者写过多款应用写过微信小程序写过h5,也做过3年的framework开发写过python后台。我想创业不知道可以具体怎么来做.md
- Obsidian/生活/教育/9个国家级免费学习平台.md
- Obsidian/adb调试命令/常用linux命令.md
- Obsidian/adb调试命令/adb常用命令.md
- Obsidian/dify/使用dify可以生成一个专项事务助手吗比如公司正规化事务助手.md
- Obsidian/dify/作为安卓高级开发工程师,除了项目管理,你完全可以在技术专项、团队效能和个人成长三大领域构建更懂你的专属助手.md
- Obsidian/git/Git add . 后如何撤销.md
- Obsidian/git/git常用命令.md
- Obsidian/saars开发/互联网saar系统是什么可以解决哪些场景需求的问题.md
- Obsidian/saars开发/数据库配置.md
- Obsidian/saars开发/aitsc维护命令.md
- Obsidian/saars开发/营养师/健康营养师分析数据.md
- Obsidian/saars开发/营养师/营养师分析数据.md
- renjiabo:
- renjiabo/test.md
- renjiabo/hello.md
- Obsidian笔记体系:
- Obsidian笔记体系/Areas/01-系统启动流程/Bootloader到Init.md
- Obsidian笔记体系/Areas/01-系统启动流程/Launcher启动流程.md

View File

@@ -1,3 +0,0 @@
# Activity生命周期测试
这是一个测试文件。