summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryingyu5658 <i@yingyu5658.me>2025-12-29 22:29:56 +0800
committeryingyu5658 <i@yingyu5658.me>2025-12-29 22:29:56 +0800
commit03fbc53b6af58e750ef7c6f1c0931394a01145e5 (patch)
tree0083d0319241352af3fa3f1f181d4443ecb18480
parent42745471b8a9244b9906eb15538501e5da254d3a (diff)
downloadblog-03fbc53b6af58e750ef7c6f1c0931394a01145e5.tar.gz
blog-03fbc53b6af58e750ef7c6f1c0931394a01145e5.zip
fix: enable comments on all posts by default
-rw-r--r--layouts/_default/single.html2
-rw-r--r--publish.sh69
2 files changed, 66 insertions, 5 deletions
diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index 8b8f326..21e185f 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -137,7 +137,7 @@
<div class="toc">{{ partial "toc.html" . }}</div>
{{ end }}
-{{ if .Params.comments }}
+{{ if .Params.comments | default true}}
<hr />
<details>
<summary>
diff --git a/publish.sh b/publish.sh
index 9adb72c..2d39278 100644
--- a/publish.sh
+++ b/publish.sh
@@ -1,10 +1,69 @@
#!/bin/sh
-#word_counter=$(find ~/blog/content/ -type f -name "*.md" -exec cat {} + | \
-#perl -CSD -pe 's/[\p{P}\p{S}\s\p{M}\p{C}\p{Z}]//g; s/$$.*?$$$$.*?$$//g; s/[*#_\-`~=+|><\^]//g; s/\!$$.*?$$$$.*?$$//g' | \
-#grep -oP '[\p{Han}a-zA-Z]' | \
-#wc -m)
+SRC="./public"
+# 安装必要的工具(如果未安装)
+if ! command -v uglifyjs &> /dev/null; then
+ echo "安装 uglify-js..."
+ npm install -g uglify-js
+fi
+
+if ! command -v cleancss &> /dev/null; then
+ echo "安装 clean-css-cli..."
+ npm install -g clean-css-cli
+fi
+
+if ! command -v html-minifier &> /dev/null; then
+ echo "安装 html-minifier-terser..."
+ npm install -g html-minifier-terser
+fi
+
+echo "开始原地压缩文件..."
+
+# 创建临时目录用于备份
+BACKUP_DIR=$(mktemp -d)
+
+# 先备份原文件
+echo "备份原文件..."
+find "$SRC" -type f \( -name "*.js" -o -name "*.css" -o -name "*.html" \) | while read file; do
+ rel_path="${file#$SRC/}"
+ backup_path="$BACKUP_DIR/$rel_path"
+ mkdir -p "$(dirname "$backup_path")"
+ cp "$file" "$backup_path"
+done
+
+# 压缩文件(原地覆盖)
+find "$SRC" -type f \( -name "*.js" -o -name "*.css" -o -name "*.html" \) | while read file; do
+ case "$file" in
+ *.js)
+ # 跳过已经是 .min.js 的文件
+ if [[ "$file" != *.min.js ]]; then
+ echo "压缩 JS: ${file#$SRC/}"
+ uglifyjs "$file" -c -m -o "${file}.tmp" && mv "${file}.tmp" "$file"
+ fi
+ ;;
+ *.css)
+ # 跳过已经是 .min.css 的文件
+ if [[ "$file" != *.min.css ]]; then
+ echo "压缩 CSS: ${file#$SRC/}"
+ cleancss "$file" -o "${file}.tmp" && mv "${file}.tmp" "$file"
+ fi
+ ;;
+ *.html)
+ echo "压缩 HTML: ${file#$SRC/}"
+ html-minifier "$file" \
+ --collapse-whitespace \
+ --remove-comments \
+ --minify-css \
+ --minify-js \
+ -o "${file}.tmp" && mv "${file}.tmp" "$file"
+ ;;
+ esac
+done
+
+echo "压缩完成!"
+
+# 执行 Hugo 构建和部署
commit_date=$(date +"%Y-%m-%d %H:%M:%S")
cd ~/blog/
hugo --cleanDestinationDir --gc
@@ -12,3 +71,5 @@ cd ~/blog/public || exit 1
git add .
git commit -m "auto update: $commit_date"
git push origin main
+
+echo "部署完成!"