Skip to content

Commit e8d5526

Browse files
committed
构建 CI/CD 实现自动化静态网站部署
每次 Push 或 PR 到 main 分支都触发。详情见README.md
1 parent ff963d4 commit e8d5526

File tree

4 files changed

+207
-16
lines changed

4 files changed

+207
-16
lines changed

.github/workflows/deploy.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Deploy MkDocs
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-and-deploy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check out the repo
14+
uses: actions/checkout@main
15+
16+
- name: Setup Python
17+
uses: actions/setup-python@main
18+
with:
19+
python-version: '3.x'
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install mkdocs mkdocs-material
25+
26+
- name: Update dir
27+
run: python ./update_dir.py
28+
29+
- name: Deploy docs to GitHub Pages
30+
uses: mhausenblas/mkdocs-deploy-gh-pages@master
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
![avatar](https://raw.githubusercontent.com/Royfor12/CQUT-Course-Guide-Sharing-Scheme/main/image/cqut_logo.png)
1+
![avatar](https://cdn.jsdmirror.com/gh/Royfor12/CQUT-Course-Guide-Sharing-Scheme/image/cqut_logo.png)
22

33
# 💡 课程攻略共享计划
44

5-
[![](https://img.shields.io/github/watchers/Royfor12/CQUT-electronic-information-engineering.svg?style=flat)](https://github.com/Royfor12/CQUT-Course-Guide-Sharing-Scheme/watchers)
6-
[![](https://img.shields.io/github/stars/Royfor12/CQUT-electronic-information-engineering.svg?style=flat)](https://github.com/Royfor12/CQUT-Course-Guide-Sharing-Scheme/stargazers)
7-
[![](https://img.shields.io/github/forks/Royfor12/CQUT-electronic-information-engineering.svg?style=flat)](https://github.com/Royfor12/CQUT-Course-Guide-Sharing-Scheme/network/members)
8-
[![](https://img.shields.io/github/issues-pr-closed-raw/Royfor12/CQUT-Course-Guide-Sharing-Scheme.svg?style=flat)](https://github.com/Royfor12/CQUT-electronic-information-engineering/issues)
5+
[![](https://img.shields.io/github/watchers/Royfor12/CQUT-Course-Guide-Sharing-Scheme.svg?style=flat)](https://github.com/Royfor12/CQUT-Course-Guide-Sharing-Scheme/watchers)
6+
[![](https://img.shields.io/github/stars/Royfor12/CQUT-Course-Guide-Sharing-Scheme.svg?style=flat)](https://github.com/Royfor12/CQUT-Course-Guide-Sharing-Scheme/stargazers)
7+
[![](https://img.shields.io/github/forks/Royfor12/CQUT-Course-Guide-Sharing-Scheme.svg?style=flat)](https://github.com/Royfor12/CQUT-Course-Guide-Sharing-Scheme/forks)
8+
[![](https://img.shields.io/github/issues-pr-closed-raw/Royfor12/CQUT-Course-Guide-Sharing-Scheme.svg?style=flat)](https://github.com/Royfor12/CQUT-Course-Guide-Sharing-Scheme/pulls)
99
![](https://img.shields.io/github/repo-size/Royfor12/CQUT-Course-Guide-Sharing-Scheme.svg?style=flat)
10-
![Platform](https://img.shields.io/badge/platform-windows%20|%20linux%20|%20macos-green.svg)
10+
[![jsdelivr](https://img.shields.io/badge/CDN-jsdelivr-brightgreen?logo=jsdelivr&logoSize=auto)](https://www.jsdelivr.com/)
1111

1212
## ❗ 写在最前
1313

14-
如果你打开本网页不知如何操作或检索所需的资源,请先点击[GitHub使用指南](https://www.bilibili.com/video/BV1hS4y1S7wL)
14+
如果你打开本网页不知如何操作或检索所需的资源,请先点击[GitHub使用指南](https://www.bilibili.com/video/BV1hS4y1S7wL)
1515
旧版备份[2025/1/7](https://pan.baidu.com/s/1_YFOqR_eSd8bXokEGMCrbg?pwd=hq33)提取码:hq33
1616

1717
## ⚡ 前言
1818

19-
网络冲浪🏄时发现了:浙江大学的课程攻略共享计划与上海交通大学生存手册,深受震撼。\
19+
网络冲浪🏄时发现了:浙江大学的课程攻略共享计划与上海交通大学生存手册,深受震撼。
2020
故此也想建立一个重庆理工大学课程攻略计划,本仓库的内容包括重庆理工大学的各类课程复习资料。本仓库为非营利、永久免费的开源项目,仓库之目的即推动知识传播、提高资源质量、减少获取成本、提倡无纸化资料、促进教育公平,让西唯兵学子在备考、复习之时不必再苦寻资料。
2121

22-
我们同在重庆理工大学,以相同的身份,学习相同的课程,师从相同的教授。教授们往往为了省事,所以几年的课程资料、期末试题可能变化不大。学习这些资料,阅读学长学姐留下的复习攻略,可能会减轻信息不对称对你造成的影响,让你在复习时更有针对性。面对年复一年、无数学子独立摸索、重复劳动的现状,我不禁感到惋惜与不平。\
23-
再加之本人有数字仓鼠🐹症。
24-
因此,我希望建立一个项目,将这些隐匿的、不确定性的、口耳相传的知识资源整合起来,使之变得公开透明、易于获取,并且能够由大家共同维护、持续丰富。
22+
我们同在重庆理工大学,以相同的身份,学习相同的课程,师从相同的教授。教授们往往为了省事,所以几年的课程资料、期末试题可能变化不大。学习这些资料,阅读学长学姐留下的复习攻略,可能会减轻信息不对称对你造成的影响,让你在复习时更有针对性。面对年复一年、无数学子独立摸索、重复劳动的现状,我不禁感到惋惜与不平。
23+
再加之本人有数字仓鼠🐹症。
24+
因此,我希望建立一个项目,将这些隐匿的、不确定性的、口耳相传的知识资源整合起来,使之变得公开透明、易于获取,并且能够由大家共同维护、持续丰富。
2525
借用浙大的课程攻略中的一句话:**我希望只要是前人走过的弯路,后人就不必再走。这是我的信念,也是我建立这个项目的原因。**
2626

2727
## 📣 特性
@@ -39,6 +39,12 @@
3939

4040
目前涵盖的科目还很少,欢迎各位前来PR!
4141

42+
### 🎉 新界面
43+
44+
本仓库已实现 GitHub Actions 工作流全自动部署。
45+
在 Push 或 PR 后会触发自动构建新的静态网页并部署到 **https://Royfor12.github.io/CQUT-Course-Guide-Sharing-Scheme**
46+
该网页界面友好,在左侧导航栏中可以查找并单独下载指定文件。
47+
4248
## 🦧 平台
4349

4450
以下摘录自浙江大学课程攻略共享计划
@@ -51,10 +57,9 @@
5157
5258
## ⏬ 下载
5359

54-
我们在这里介绍两种下载文件的方式:
55-
5660
1. 你当然可以克隆或者下载整个项目,但因为整个项目较大,可能对于一部分人不太方便。这里对于使用Chrome和Firefox的用户,我们推荐一个[Chrome插件](https://chrome.google.com/webstore/detail/gitzip-for-github/ffabmkklhbepgcgfonabamgnfafbdlkn?hl=en)[Firefox插件](https://addons.mozilla.org/en-US/firefox/addon/gitzip/)**GitZip**。该插件可以让我们只下载项目中我们感兴趣的那些文件夹,也就是我们所感兴趣的课程的资料。同时对Opera用户来说,大部分的Chrome插件都可以通过一款名为[Install Chrome Extensions](https://addons.opera.com/zh-cn/extensions/details/install-chrome-extensions/)的Opera插件安装使用,GitZip也不例外。而对于使用其他浏览器的朋友来说,很遗憾,这个插件暂时只能在这三款浏览器中使用。
57-
2. 或者复制该文件夹的网址,粘贴入[DownGit](https://minhaskamal.github.io/DownGit/#/home)中,选择**download**即可。
61+
2. 或者复制想要打包下载文件夹的网址,粘贴入[DownGit](https://minhaskamal.github.io/DownGit/#/home)中,选择**download**即可。
62+
3. 访问 **https://Royfor12.github.io/CQUT-Course-Guide-Sharing-Scheme** 。文件下载加速CDN由 [![jsdelivr](https://img.shields.io/badge/CDN-jsdelivr-brightgreen?logo=jsdelivr&logoSize=auto)](https://www.jsdelivr.com/) 及其镜像站提供。
5863

5964
注:对于第一种方法而言,它需要使用者拥有github账号,并且该插件需要使用者的授权;而第二种方法虽然一次只能下载一个文件夹,但它并不需要使用者拥有github账号。
6065

@@ -166,7 +171,7 @@ Issue、PR、纠错、补充、上传攻略,完全欢迎!
166171

167172
## 📔待办事项
168173
- [ ] 制定使用指南
169-
- [ ] 设计一个网页便于检索与预览
174+
- [x] 设计一个网页便于检索与预览
170175

171176
## 🍻赞助
172177
Buy me coffee.
@@ -179,4 +184,4 @@ Buy me coffee.
179184

180185
## ✨Stars
181186

182-
[![Star History Chart](https://api.star-history.com/svg?repos=Royfor12/CQUT-Course-Guide-Sharing-Scheme&type=Date)](https://github.com/Royfor12/CQUT-Course-Guide-Sharing-Scheme&Date)
187+
[![Star History Chart](https://api.star-history.com/svg?repos=Royfor12/CQUT-Course-Guide-Sharing-Scheme&type=Date)](https://star-history.com/#Royfor12/CQUT-Course-Guide-Sharing-Scheme&Date)

mkdocs.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
site_name: 重庆理工大学课程攻略共享计划
2+
site_author: H·Sofie, Royfor12
3+
site_description: 使用MKDocs构建的静态网页
4+
site_url: https://Royfor12.github.io/CQUT-Course-Guide-Sharing-Scheme
5+
repo_url: https://github.com/Royfor12/CQUT-Course-Guide-Sharing-Scheme
6+
7+
theme:
8+
name: material
9+
language: zh
10+
font:
11+
text: Noto Sans Simplified Chinese
12+
features:
13+
- navigation.instant # 即时加载
14+
- navigation.instant.prefetch # 即时预取
15+
- navigation.instant.progress # 加载进度指示器
16+
- navigation.instant.preview # 即时预览
17+
- navigation.sections # 导航栏分组
18+
- navigation.path # 标题导航路径
19+
- navigation.top # 返回顶部按钮
20+
- toc.follow # 目录锚点跟随
21+
- search.highlight # 搜索高亮显示
22+
- content.footnote.tooltips # 脚注内联
23+
24+
plugins:
25+
- search:
26+
lang: zh
27+
28+
markdown_extensions:
29+
- abbr
30+
- admonition
31+
- pymdownx.details
32+
- attr_list
33+
- def_list
34+
- footnotes
35+
- md_in_html
36+
- tables
37+
- pymdownx.betterem
38+
- pymdownx.caret
39+
- pymdownx.mark
40+
- pymdownx.tilde
41+
- pymdownx.tasklist:
42+
custom_checkbox: true

update_dir.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import os
5+
import shutil
6+
from urllib.parse import quote
7+
8+
# 从 GitHub Actions 环境变量里获取仓库所有者和仓库名、分支名
9+
repo_full = os.environ.get("GITHUB_REPOSITORY", "defaultOwner/defaultRepo")
10+
branch = os.environ.get("GITHUB_REF_NAME", "main")
11+
12+
# 文本文件走 blob 链接(在线查看),二进制文件走 cdn 链接(便于直接下载)
13+
BLOB_URL_PREFIX = f"https://github.com/{repo_full}/blob/{branch}/"
14+
BIN_URL_PREFIX = f"https://cdn.jsdmirror.com/gh/{repo_full}/"
15+
16+
# 顶层排除目录
17+
EXCLUDE_TOP_DIRS = {'.git', 'docs', '.vscode', '.circleci', 'site', 'image'}
18+
19+
# 视为 README 的文件名
20+
README_CANDIDATES = {'README.md', 'readme.md', 'index.md'}
21+
22+
# 生成 blob 链接
23+
BLOB_EXTS = {'md', 'txt', 'c', 'cpp', 'py'}
24+
25+
def process_directory(base_dir: str, rel_path: str):
26+
"""
27+
将 base_dir(绝对路径) 对应的目录内容,递归生成到 docs/rel_path 目录下的 index.md 中。
28+
1. 若有 README_CANDIDATES 中任意文件,则将其内容原样写入。
29+
2. 新起一行后,输出大标题 "# 文件列表"。
30+
3. 列出当前目录所有文件的链接(md/txt -> blob,其它 -> cdn)。
31+
4. 对各子文件夹,递归调用 process_directory,生成各自的 docs/rel_path/subfolder/index.md。
32+
"""
33+
34+
# 在 docs/ 下创建与原目录相同层级的文件夹
35+
docs_folder = os.path.join("docs", rel_path)
36+
if not os.path.exists(docs_folder):
37+
os.makedirs(docs_folder)
38+
39+
items = sorted(os.listdir(base_dir))
40+
41+
# 尝试找到任意一个 README
42+
readme_content = ""
43+
for candidate in README_CANDIDATES:
44+
if candidate in items:
45+
readme_path = os.path.join(base_dir, candidate)
46+
with open(readme_path, "r", encoding="utf-8") as rf:
47+
readme_content = rf.read()
48+
break # 找到一个就可以退出
49+
50+
# 收集文件链接列表
51+
file_links = []
52+
subdirs = []
53+
for item in items:
54+
full_item_path = os.path.join(base_dir, item)
55+
if os.path.isfile(full_item_path):
56+
# 若是 README,则已处理过;否则纳入链接
57+
if item not in README_CANDIDATES:
58+
ext = item.split(".")[-1].lower() if "." in item else ""
59+
# 判断用 blob 还是 cdn 加速
60+
if ext in BLOB_EXTS:
61+
file_url = BLOB_URL_PREFIX + quote(f"{rel_path}/{item}")
62+
else:
63+
file_url = BIN_URL_PREFIX + quote(f"{rel_path}/{item}")
64+
file_links.append((item, file_url))
65+
else:
66+
# 是子目录
67+
subdirs.append(item)
68+
69+
# 写出当前目录的 index.md
70+
index_md_path = os.path.join(docs_folder, "index.md")
71+
with open(index_md_path, "w", encoding="utf-8") as wf:
72+
# 1) 写 README 内容(若有)
73+
if readme_content.strip():
74+
wf.write(readme_content.strip())
75+
wf.write("\n\n---\n\n") # 加点空行,避免直接跟标题混在一起
76+
77+
# 2) 输出大标题“# 文件列表”
78+
wf.write("# 文件列表\n")
79+
80+
# 3) 列出当前目录内的文件链接
81+
for fname, url in file_links:
82+
wf.write(f"- [{fname}]({url})\n")
83+
wf.write("\n")
84+
85+
# 4) 递归处理子目录
86+
for subdir in subdirs:
87+
sub_rel_path = os.path.join(rel_path, subdir)
88+
full_subdir_path = os.path.join(base_dir, subdir)
89+
process_directory(full_subdir_path, sub_rel_path)
90+
91+
92+
if __name__ == "__main__":
93+
94+
# 确保 docs 目录存在
95+
if not os.path.exists("docs"):
96+
os.mkdir("docs")
97+
98+
# 排除 EXCLUDE_TOP_DIRS
99+
top_dirs = []
100+
for d in sorted(os.listdir(".")):
101+
if os.path.isdir(d) and d not in EXCLUDE_TOP_DIRS:
102+
top_dirs.append(d)
103+
104+
for d in top_dirs:
105+
# 绝对路径
106+
abs_path = os.path.abspath(d)
107+
# rel_path 就是顶层目录的名字 d
108+
process_directory(abs_path, d)
109+
110+
# 若仓库根目录下存在 README.md,则复制到 docs/index.md 当主页
111+
if os.path.exists("README.md"):
112+
shutil.copyfile("README.md", "docs/index.md")

0 commit comments

Comments
 (0)