Skip to content

Commit 70e681f

Browse files
committed
sh
1 parent c2c07da commit 70e681f

File tree

3 files changed

+35
-42
lines changed

3 files changed

+35
-42
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
.Rhistory
33
.RData
44
.Ruserdata
5-
5+
*.sh
66
public/

.vscode/tasks.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
"version": "2.0.0",
33
"tasks": [
44
{
5-
"label": "Auto Update Notes",
5+
"label": "Update Notes",
66
"type": "shell",
77
"command": "./update-notes.sh",
8-
"args": ["auto update"],
8+
"isBackground": false,
9+
"presentation": {
10+
"reveal": "silent",
11+
"panel": "new"
12+
},
913
"problemMatcher": []
1014
}
1115
]

update-notes.sh

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,55 @@ else
77
COMMIT_MSG="$1"
88
fi
99

10-
# === 切换到脚本所在目录(避免 VSCode 工作目录不同)===
11-
cd "$(dirname "$0")"
12-
1310
# === 路径 ===
1411
TYP_FILE="notes/main.typ"
1512
OUT_DIR="static/notes"
16-
OUT_PDF="${OUT_DIR}/notes.pdf"
17-
18-
mkdir -p "$OUT_DIR"
13+
OUT_FILE="${OUT_DIR}/notes.pdf"
1914

20-
# === Typst 编译(PDF) ===
21-
echo "📄 编译 Typst PDF..."
22-
typst compile "$TYP_FILE" "$OUT_PDF"
15+
# === Windows 下 Typst 可执行文件 ===
16+
TYPST_WIN_PATH="/c/Users/thinkbook-cxy/AppData/Local/Microsoft/WinGet/Packages/Typst.Typst_Microsoft.Winget.Source_8wekyb3d8bbwe/typst-x86_64-pc-windows-msvc/typst.exe"
2317

24-
if [ $? -ne 0 ]; then
25-
echo "❌ Typst 编译失败"
18+
# === 检查 Typst ===
19+
if [ -f "$TYPST_WIN_PATH" ]; then
20+
TYPST_CMD="$TYPST_WIN_PATH"
21+
elif command -v typst &> /dev/null; then
22+
TYPST_CMD="typst"
23+
else
24+
echo "❌ typst 未安装,请先安装 Typst CLI。"
2625
exit 1
2726
fi
2827

29-
# === 记录 push 时间 ===
30-
PUSH_LOG=".last_push_time"
28+
mkdir -p "$OUT_DIR"
29+
30+
echo "------------------------------------------------------"
31+
echo "📄 编译 Typst PDF 中..."
32+
echo "------------------------------------------------------"
3133

32-
# === 获取当前时间(秒)===
33-
NOW=$(date +%s)
34+
# === 编译 PDF ===
35+
$TYPST_CMD compile "$TYP_FILE" "$OUT_FILE"
36+
EXITCODE=$?
3437

35-
# === 获取上次 push 时间 ===
36-
if [ -f "$PUSH_LOG" ]; then
37-
LAST_PUSH=$(cat "$PUSH_LOG")
38-
else
39-
LAST_PUSH=0
38+
if [ $EXITCODE -ne 0 ]; then
39+
echo "❌ Typst PDF 编译失败 (exit $EXITCODE)"
40+
exit 1
4041
fi
4142

42-
# 冷却时间:600 秒 = 10 分钟
43-
COOL_DOWN=600
43+
echo "✅ PDF 已输出到: $OUT_FILE"
44+
45+
# === Git 操作 ===
46+
echo "📦 执行 git add/commit/push"
4447

45-
# === Git: add & commit ===
46-
git add "$TYP_FILE" "$OUT_PDF"
48+
git add "$TYP_FILE" "$OUT_FILE"
4749

4850
git commit -m "$COMMIT_MSG"
4951
if [ $? -ne 0 ]; then
50-
echo "ℹ️ 没变化,不需要 commit/push。"
52+
echo "ℹ️ 没有变化,无需 push。"
5153
exit 0
5254
fi
5355

54-
# === 判断是否需要 push ===
55-
SINCE_PUSH=$(( NOW - LAST_PUSH ))
56-
57-
if [ "$SINCE_PUSH" -lt "$COOL_DOWN" ]; then
58-
echo "⏳ 最近 $((SINCE_PUSH/60)) 分钟内 push 过(冷却时间 10 分钟)"
59-
echo "✅ 本地 commit 完成,但暂时不 push。"
60-
exit 0
61-
fi
62-
63-
# === Push ===
64-
echo "🚀 正在 push 到 GitHub..."
6556
git push
66-
6757
if [ $? -eq 0 ]; then
68-
echo "$NOW" > "$PUSH_LOG"
69-
echo "✅ Push 完成!并更新 push 时间记录。"
58+
echo "✅ Push 完成!GitHub Pages 将自动部署。"
7059
else
7160
echo "❌ Push 失败,请检查网络或权限。"
7261
fi

0 commit comments

Comments
 (0)