-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·64 lines (52 loc) · 1.76 KB
/
build.sh
File metadata and controls
executable file
·64 lines (52 loc) · 1.76 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
#!/bin/bash
set -euo pipefail
# 默认输出目录
OUT_DIR="./public"
BLOG_DIR="./blogs"
BLOG_OUT="$OUT_DIR/blogs"
BLOG_INDEX="$BLOG_OUT/README.md"
# 解析命令行参数
while [[ $# -gt 0 ]]; do
case "$1" in
-o|--output)
OUT_DIR="$2"
BLOG_OUT="$OUT_DIR/blogs"
BLOG_INDEX="$BLOG_OUT/README.md"
shift 2
;;
*)
echo "❌ Unknown parameter: $1"
exit 1
;;
esac
done
echo "🚧 编译 Pug 模板..."
npx pug ./index.pug -o "$OUT_DIR"
echo "🚧 压缩 JavaScript..."
npx terser ./js/*.js -o "$OUT_DIR/js/main.js" -c -m
echo "🚧 构建 TailwindCSS..."
npx tailwindcss -i ./css/styles.css -o "$OUT_DIR/css/styles.css" --minify
echo "🚧 压缩附加 CSS..."
npx uglifycss ./css/fontawesome.css ./css/solid.css ./css/brands.css --output "$OUT_DIR/css/icons.css"
npx uglifycss ./css/markdown.css ./css/code.css --output "$OUT_DIR/css/display.css"
echo "🚧 复制静态资源..."
cp -r ./image/ "$OUT_DIR/image"
cp -r ./blogs/ "$BLOG_OUT"
find "$BLOG_OUT" -type f -name info -delete
cp ./*.md "$OUT_DIR/"
echo "🚧 生成索引 README.md..."
printf "# Blog 归档\n\n" > "$BLOG_INDEX"
declare -a entries
for dir in "$BLOG_DIR"/*/; do
info_file="${dir}info"
[[ -f "$info_file" ]] || continue
title=$(grep '^title:' "$info_file" | sed 's/^title:[[:space:]]*//')
date=$(grep '^date:' "$info_file" | sed 's/^date:[[:space:]]*//')
slug=$(basename "$dir")
entries+=("$date|$title|$slug")
done
for line in $(printf "%s\n" "${entries[@]}" | sort -r); do
IFS='|' read -r date title slug <<< "$line"
printf -- "- title: %s\n date: %s\n link: #/blogs/%s/\n\n" "$title" "$date" "$slug" >> "$BLOG_INDEX"
done
echo "✅ 构建完成,输出目录:$OUT_DIR"