使用Doxygen生成技術文件,並託管到GitHub Page。
Settings
使用以下指令生成Doxygen的設定檔
現在應該會有一個名為Doxyfile的文件,修改以下設定。
1
2
3
4
5
6
7
8
|
PROJECT_NAME = "MyProject"
OUTPUT_DIRECTORY = docs
INPUT = README.md ./src
RECURSIVE = YES
USE_MDFILE_AS_MAINPAGE = README.md
GENERATE_LATEX = NO
OPTIMIZE_OUTPUT_FOR_C = YES
IMAGE_PATH = docs/img
|
Add theme
由於doxygen預設的主題又老又醜,我們可以給他套上主題。
使用指令安裝Doxygen Awesome v2.3.3
1
2
3
|
git submodule add https://github.com/jothepro/doxygen-awesome-css.git
cd doxygen-awesome-css
git checkout v2.3.3
|
修改Doxyfile
1
2
3
|
GENERATE_TREEVIEW = YES
HTML_EXTRA_STYLESHEET = doxygen-awesome-css/doxygen-awesome.css
HTML_COLORSTYLE = LIGHT # required with Doxygen >= 1.9.5
|
Generate
檔案架構
1
2
3
4
5
6
7
8
9
10
11
|
MyProject/
├── .gitignore
├── .gitmodules
├── Doxyfile
├── LICENSE.md
├── README.md
├── docs/
│ ├── index.html # 頁面跳轉
│ ├── imgs
│ └── html/
└─ src/
|
- Doxygen輸出的HTML會位於
docs/html/ 下
docs/img 放文檔用到的圖片
src/ 資料夾放程式檔案
生成HTML檔案
輸入指令來產生HTML檔案
新增index.html
由於Doxygen輸出的位置在``docs/html下,因此我們需要寫一個檔案讓網頁從docs/跳轉到docs/html/`。
新增 docs/index.html:
1
2
3
4
5
6
7
8
9
10
11
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="REFRESH" content="0;URL=./html/index.html">
<title>Redirecting...</title>
</head>
<body>
<p>Redirecting, if you are not redirected, please <a href="./html/index.html">click here</a>.</p>
</body>
</html>
|
Workflow
如果覺得手動編譯網頁並上傳很麻煩的話,可以用GitHub Actions。
由於我們的網頁將從Work flow產生,因此在.gitignore排除用於網頁跳轉以外的文件。
1
2
|
docs/*
!docs/index.html
|
範例 .github/workflows/deploy.yml
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
|
# Build docs with doxygen and deploy on pages
name: Deploy Doxygen site to Pages
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
# Allow only one deployment at a time, skipping run queues between running and latest queues
# However, do not cancel ongoing runs as we want to allow these production deployments to complete
concurrency:
group: pages
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
# Download and install Doxygen
- uses: ssciwr/doxygen-install@v1
with:
version: "1.12.0"
- name: Build HTML
run: doxygen
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./docs/html
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
|