-
-
Notifications
You must be signed in to change notification settings - Fork 0
160 lines (133 loc) · 5.08 KB
/
Copy pathdocs-build.yml
File metadata and controls
160 lines (133 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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"""<!--
自动生成的侧边栏
生成时间: {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