From e17fda59a32c96cb652ced294f6472c9626c5799 Mon Sep 17 00:00:00 2001 From: ming Date: Fri, 16 Oct 2026 21:59:00 +0800 Subject: [PATCH] compile --- Makefile | 35 ++++++++++++++++++++++++++++++++--- tools/install-hooks.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100755 tools/install-hooks.sh diff --git a/Makefile b/Makefile index 85f47cc..e918cd7 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all render update git +.PHONY: all render deploy update git serve new # 默认目标:执行所有操作 all: render update git @@ -26,13 +26,42 @@ else endif hugo -d blackwolf +# 目标:构建并上传 +deploy: render update + # 目标:更新网站内容 update: rsync -crvP --progress --delete --exclude='.DS_Store' --exclude='.Rproj.user/' blackwolf/* dwuser@drwater.net:/home/www/blackwolf/ +# 目标:本地预览(含草稿) +serve: + hugo server -D --disableFastRender -d blackwolf + +# 目标:新建文章,用法 make new T=article S=my-post +new: + @test -n "$(T)" || { echo "用法: make new T= S="; exit 1; } + @test -n "$(S)" || { echo "用法: make new T= S="; exit 1; } + @f="content/$(T)/$$(date +%Y%m%d)-$(S).md"; \ + if [ -e "$$f" ]; then echo "已存在: $$f"; exit 1; fi; \ + mkdir -p "content/$(T)"; \ + { \ + echo '---'; \ + echo "title: $$(echo '$(S)' | tr '-' ' ')"; \ + echo 'author: Black Wolf'; \ + echo "date: $$(date +%Y-%m-%d)"; \ + echo "slug: $(S)"; \ + echo '---'; \ + echo; \ + } > "$$f"; \ + echo "已创建: $$f" + # 目标:Git 提交和推送 git: - git add . - git commit -m "compile" + if [ -n "$$(git status --porcelain)" ]; then \ + git add -A; \ + git commit -m "compile"; \ + else \ + echo "没有需要提交的改动"; \ + fi; \ git push diff --git a/tools/install-hooks.sh b/tools/install-hooks.sh new file mode 100755 index 0000000..0fd931c --- /dev/null +++ b/tools/install-hooks.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# 安装 git 钩子:提交后自动构建并上传网站。 +# 用法:tools/install-hooks.sh +# 卸载:rm .git/hooks/post-commit(本脚本写入的内容带 "# blackwolf" 标记) +set -e + +root=$(git rev-parse --show-toplevel) +hook="$root/.git/hooks/post-commit" +mkdir -p "$(dirname "$hook")" + +cat > "$hook" <<'EOF' +#!/bin/sh +# blackwolf: 提交后自动部署(构建 + rsync 上传) +log="$(git rev-parse --show-toplevel)/.git/deploy.log" +echo "== $(date '+%F %T') post-commit deploy ==" >> "$log" +if make -s deploy >> "$log" 2>&1; then + echo "网站已更新(详见 .git/deploy.log)" +else + echo "网站部署失败,详见 .git/deploy.log" >&2 +fi +EOF + +chmod +x "$hook" +echo "已安装: $hook" +echo "以后 git commit 后会自动跑 make deploy(构建 + 上传)。" +echo "如需免密上传,请先把公钥装到服务器:" +echo " ssh-copy-id dwuser@drwater.net # 或手动追加 ~/.ssh/id_ed25519.pub"