Skip to content

Update history_3.md #228

Update history_3.md

Update history_3.md #228

Workflow file for this run

name: Auto Build Docs
on:
push:
paths:
- 'docs/**'
- '.github/workflows/docs-auto.yml'
schedule:
- cron: '0 2 * * *' # 每天凌晨2点
workflow_dispatch:
permissions:
contents: write
jobs:
build-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Generate Sidebar
run: |
# 创建自动生成脚本
cat > gen-sidebar.py << 'EOF'
import os
import json
from datetime import datetime
docs_dir = 'docs'
sidebar_file = os.path.join(docs_dir, '_sidebar.md')
# 获取所有.md文件
md_files = []
for file in os.listdir(docs_dir):
if file.endswith('.md') and not file.startswith('_'):
md_files.append(file)
# 分类文件
categories = {
'首页': [],
'目录': [],
'团队': [],
'历史': [],
'其他': []
}
for file in sorted(md_files):
if file == 'README.md':
categories['首页'].append({'name': '🏠 文档首页', 'file': file})
elif file == 'Directory.md':
categories['目录'].append({'name': '📖 目录总览', 'file': file})
elif file == 'about.md':
categories['团队'].append({'name': '🎨 管理团队介绍', 'file': file})
elif file.startswith('history'):
# 提取页码
if file == 'history.md':
page_num = 1
name = '历史记载 第1页'
else:
# 提取 history_2.md 中的数字
try:
page_num = int(file.replace('history_', '').replace('.md', ''))
name = f'历史记载 第{page_num}页'
except:
page_num = 999
name = file.replace('.md', '')
categories['历史'].append({
'name': name,
'file': file,
'page_num': page_num
})
else:
categories['其他'].append({'name': f'📄 {file.replace(".md", "")}', 'file': file})
# 对历史文档按页码排序
categories['历史'].sort(key=lambda x: x['page_num'])
# 生成侧边栏内容
content = f"""<!--
自动生成的侧边栏

Check failure on line 83 in .github/workflows/docs-build.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/docs-build.yml

Invalid workflow file

You have an error in your yaml syntax on line 83
生成时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
不要手动修改此文件,修改会被覆盖
-->
"""
# 首页
for item in categories['首页']:
content += f"- [{item['name']}]({item['file']})\n\n"
# 目录
if categories['目录']:
content += "## 📖 目录\n"
for item in categories['目录']:
content += f"- [{item['name']}]({item['file']})\n"
content += "\n"
# 团队
if categories['团队']:
content += "## 🎨 管理团队\n"
for item in categories['团队']:
content += f"- [{item['name']}]({item['file']})\n"
content += "\n"
# 历史
if categories['历史']:
content += "## 📜 历史记载\n\n"
for item in categories['历史']:
content += f"- [{item['name']}]({item['file']})\n"
content += "\n"
# 其他
if categories['其他']:
content += "## 📄 其他文档\n"
for item in categories['其他']:
content += f"- [{item['name']}]({item['file']})\n"
content += "\n"
# 外部链接
content += """## 🔗 快速链接
- [返回主页](../index.html)
- [GitHub仓库](https://github.com/ColorFulCraft/CFCHistory)
- [加入QQ群](https://qm.qq.com/q/L8kNa8IJqu)
"""
# 写入文件
with open(sidebar_file, 'w', encoding='utf-8') as f:
f.write(content)
print(f"✅ 生成侧边栏完成,共 {len(md_files)} 个文档")
print(f"📁 历史文档: {len(categories['历史'])} 页")
# 生成统计数据
stats = {
'generated_at': datetime.now().isoformat(),
'total_files': len(md_files),
'history_pages': len(categories['历史']),
'categories': {k: len(v) for k, v in categories.items()}
}
with open(os.path.join(docs_dir, '_stats.json'), 'w', encoding='utf-8') as f:
json.dump(stats, f, ensure_ascii=False, indent=2)
EOF
python gen-sidebar.py
- name: Create .nojekyll
run: touch .nojekyll
- name: Commit changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add docs/_sidebar.md docs/_stats.json .nojekyll
git diff --cached --quiet || git commit -m "🤖 自动更新文档侧边栏 [skip ci]"
git push