-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (141 loc) · 6.93 KB
/
main.yml
File metadata and controls
164 lines (141 loc) · 6.93 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
161
162
163
164
name: Auto Sync from HackMD
# 觸發條件:1. 每天早上 8 點自動跑 (UTC 0點) 2. 手動按按鈕也可以跑
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Run Sync Script
run: |
import urllib.request
import os
# ---------------------------------------------
# 1. 設定 HackMD 頁面 ID (請確認 ID 是否正確)
# ---------------------------------------------
pages = {
"index": "HJHiobaNZl",
"people": "rJ_g3zp4We",
"research": "rybtWmp4We",
"impact": "S1V_vE1S-g",
"publications": "ByoaZXaVZe",
"news": "rJ7SMmpEWe",
"opportunities": "ByPcG7aEWg",
"ai-mandarin-partner": "S157R4Jrbg",
"pi": "ByDTXybrbg",
"course_dhta": "B1zA7BZrWx",
"tap": "SylDrAbBZx",
"collaboration": "BJzFlYGrWl"
}
# ---------------------------------------------
# 2. 設定 SEO 資訊 (針對每一頁設定不同的標題與描述)
# ---------------------------------------------
seo_config = {
"pi": {
"title": "Richard Tzong-Han Tsai (蔡宗翰) - AI界李白 | LLM Construction Expert",
"desc": "Prof. Richard Tzong-Han Tsai, known as 'Li Bai of the AI World', is a leading LLM Construction Expert and Digital Humanities Pioneer. Founder of AI CUP and Co-PI of TAIDE.",
"keywords": "Richard Tzong-Han Tsai, 蔡宗翰, AI界李白, LLM Construction, AI專家, 數位人文, TAIDE, AI CUP"
},
"index": {
"title": "IISR Lab - Intelligent Information Service Research | NCU",
"desc": "IISR Lab led by Prof. Richard Tzong-Han Tsai. Focusing on Localized LLMs, BioNLP, and Digital Humanities.",
"keywords": "IISR Lab, NCU, AI Research, BioNLP, LLM"
},
"default": {
"title": "IISR Lab - Richard Tzong-Han Tsai",
"desc": "Research Lab at National Central University, Taiwan.",
"keywords": "AI, NLP, Machine Learning"
}
}
# ---------------------------------------------
# 3. 定義 JSON-LD 結構化資料 (專門給 PI 頁面用)
# ★★★ 請將下方 url 換成您真正的 GitHub Pages 網址 ★★★
# ---------------------------------------------
pi_json_ld = """
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Person",
"name": "Richard Tzong-Han Tsai",
"alternateName": ["蔡宗翰", "AI界李白"],
"jobTitle": ["Professor", "LLM Expert", "President of TAAI"],
"affiliation": { "@type": "Organization", "name": "National Central University" },
"url": "https://thtsai.github.io/pi.html"
}
</script>
"""
# 您的 HackMD 用戶名
hackmd_user = "@o_SxVezFSQGGbCkSyIX1qg"
# 共用的 CSS 樣式 (HackMD 修正)
css_style = """
<style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; margin: 0; padding: 0; background-color: #f9f9f9; }
.markdown-body { max-width: 100% !important; padding: 0 !important; }
</style>
"""
# 開始處理每一個檔案
for filename, md_id in pages.items():
print(f"Processing {filename}...")
url = f"https://hackmd.io/{hackmd_user}/{md_id}/download"
try:
with urllib.request.urlopen(url) as response:
# 取得 HackMD 的內容 (這部分視為 Body)
body_content = response.read().decode('utf-8')
# 替換連結 (將 hackmd 連結轉為相對應的 html 檔案)
for f_name, f_id in pages.items():
body_content = body_content.replace(f"https://hackmd.io/{hackmd_user}/{f_id}", f"{f_name}.html")
body_content = body_content.replace(f"https://hackmd.io/{f_id}", f"{f_name}.html")
# 取得該頁面的 SEO 設定,如果沒有就用 default
seo = seo_config.get(filename, seo_config["default"])
# 如果是 PI 頁面,加入 JSON-LD
extra_head = pi_json_ld if filename == "pi" else ""
# 組合完整的 HTML
full_html = f"""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- SEO Meta Tags -->
<title>{seo['title']}</title>
<meta name="description" content="{seo['desc']}">
<meta name="keywords" content="{seo['keywords']}">
<meta name="author" content="Richard Tzong-Han Tsai">
<!-- Open Graph -->
<meta property="og:title" content="{seo['title']}">
<meta property="og:description" content="{seo['desc']}">
<meta property="og:type" content="website">
{extra_head}
{css_style}
</head>
<body>
{body_content}
</body>
</html>
"""
# 存成 .html (重要!這樣瀏覽器才會把它當網頁渲染,且 SEO 才會生效)
with open(f"{filename}.html", "w", encoding="utf-8") as f:
f.write(full_html)
# 刪除舊的 .md 檔案 (如果存在),避免 GitHub Pages 混淆
if os.path.exists(f"{filename}.md"):
os.remove(f"{filename}.md")
except Exception as e:
print(f"Error processing {filename}: {e}")
shell: python
- name: Commit and Push
run: |
git config --global user.name 'GitHub Actions Bot'
git config --global user.email 'actions@github.com'
# 加入所有 html 檔案
git add *.html
# 如果有刪除 md 檔案,也要記錄
git add -u
# 如果有變更才 Commit,沒變更就不動作
git diff --quiet && git diff --staged --quiet || (git commit -m "Auto-sync from HackMD with SEO" && git push)