diff --git a/Makefile b/Makefile index 932d514..ba5245e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ # Makefile for Quarto Project Automation # Detect OS +HOSTNAME := $(shell hostname) OS := $(shell uname | tr A-Z a-z) ifeq ($(OS), darwin) OS := OSX @@ -49,13 +50,12 @@ GREPSTR := " \|(\|)\|^submit\|^analysis\|_cache\|_freeze\|^site_libs\|^www" all: local upload clean commit -force: check_git_status render filehash upload clean commit +force: updrefbib check_git_status render filehash upload clean commit -local: check_git_status lazyrender +local: updrefbib check_git_status lazyrender -# Update Makefile from a specific location if on macOS updmakefile: - @if [ "$(OS)" = "OSX" ]; then \ + @if [ "$(OS)" = "OSX" ] && [ "$(HOSTNAME)" = "max" ]; then \ echo "基于 $$HOME/bin/publish2dw.Makefile 更新本项目 Makefile..."; \ cp "$$HOME/bin/publish2dw.Makefile" "./Makefile"; \ git add "Makefile" && git commit -m "Update Makefile"; \ @@ -65,6 +65,23 @@ updmakefile: fi +updrefbib: + @if [ "$(OS)" = "OSX" ] && [ "$(HOSTNAME)" = "max" ]; then \ + echo "更新本项目参考文献..."; \ + cp "$$HOME/literature/Ref.bib" "./BB/"; \ + echo "推送本地参考文献到远程服务器..."; \ + rsync -azvu --progress "$$HOME/literature/Ref.bib" "drwater@serev:/home/www/drwater/datapool/public/BB/Ref.bib"; \ + echo "本项目参考文献更新完成."; \ + else \ + echo "更新本项目参考文献..."; \ + wget -O BB/Ref.bib "https://drwater.rcees.ac.cn/datapool/public/BB/Ref.bib"; \ + echo "本项目参考文献更新完成."; \ + fi; \ + git add BB/Ref.bib; \ + if [ "$$(git diff --cached)" ]; then \ + git commit -m "Update Ref.bib"; \ + fi + check_git_status: @uncommitted=$$(git status --porcelain); \ if [ -n "$$uncommitted" ]; then \ @@ -163,7 +180,7 @@ clean: @rm -f ./*.spl ./*.aux ./*.bbl ./*.blg ./*.log ./*.tex ./*.bcf ./*.tex.sedbak ./*.fdb_latexmk # Upload files to server and fix links -upload: +upload: backupdocx @mkdir -p "$(outputdir)" && chmod -R 2775 "$(outputdir)" @$(MAKE) fix_links @if rsync -azvu --progress --delete -r "$(outputdir)" "$(remotedir)"; then \ @@ -181,6 +198,57 @@ upload: fi; \ fi +backupdocx: + @echo "备份MS.docx文件..."; \ + currentcommithash=$$(git rev-parse --short HEAD); \ + datetime=$$(git show -s --format=%ci $$currentcommithash | sed 's/[-: ]//g' | cut -c3-12); \ + mkdir -p TC/MS/; \ + existing_file=$$(find TC/MS -name "MS*.docx" -exec cmp -s www/MS/MS.docx {} \; -print -quit); \ + if [ -n "$$existing_file" ]; then \ + echo "与www/MS/MS.docx 内容相同的备份文件已存在: $$existing_file"; \ + echo "无需备份."; \ + else \ + if [ ! -e TC/MS/MS$${datetime}_$${currentcommithash}.docx ]; then \ + cp www/MS/MS.docx TC/MS/MS$${datetime}_$${currentcommithash}.docx; \ + echo "备份TC/MS/MS-$${datetime}_$${currentcommithash}.docx完成."; \ + git add TC/MS/MS-$${datetime}_$${currentcommithash}.docx; \ + if [ "$$(git diff --cached)" ]; then \ + git commit -m "备份TC/MS/MS-$${datetime}_$${currentcommithash}.docx"; \ + fi; \ + else \ + echo "TC/MS/MS-$${datetime}_$${currentcommithash}.docx已存在,无需备份."; \ + fi; \ + fi; + + +trackchange: + @echo "选择两个提交以比较文档..."; \ + hashes=$$(git log --pretty=format:'%h: %s BY %an (%ar)' \ + | grep -E "$$(ls TC/MS/*.docx | xargs -n1 basename | sed -E 's/MS.*_([0-9a-f]+)\.docx/\1/' | tr '\n' '|')SMT_】" \ + | fzf --multi --reverse --preview="echo {}" ); \ + echo $$hashes; \ + hash1=$$(echo $$hashes | sed -e 's/) \([a-z0-9]\{7\}:\)/)\n\1/g' | tail -n 1 | awk '{print $$1}' | tr -d ':'); \ + datetime1=$$(git show -s --format=%ci $$hash1 | sed 's/[-: ]//g' | cut -c3-12); \ + hash2=$$(echo $$hashes | sed -e 's/) \([a-z0-9]\{7\}:\)/)\n\1/g' | head -n 1 | awk '{print $$1}' | tr -d ':'); \ + datetime2=$$(git show -s --format=%ci $$hash2 | sed 's/[-: ]//g' | cut -c3-12); \ + if [ -z "$$hash1" ] || [ -z "$$hash2" ]; then \ + echo "必须选择两个提交."; \ + exit 1; \ + fi; \ + doc1="TC/MS/MS$${datetime1}_$$hash1.docx"; \ + echo "$$doc1"; \ + doc2="TC/MS/MS$${datetime2}_$$hash2.docx"; \ + echo "$$doc2"; \ + if [ -f "$$doc1" ] && [ -f "$$doc2" ] && [ "$$doc1" != "$$doc2" ]; then \ + echo "打开文件: $$doc1 和 $$doc2"; \ + open "$$doc1" "$$doc2"; \ + printf "MS$${datetime1}-$${datetime2}_$${hash1}-$${hash2}" | pbcopy; \ + echo "请在word中对比两个版本形成带修改痕迹的版本,并保存至TC/MS$${datetime1}-$${datetime2}_$${hash1}-$${hash2}.docx!"; \ + else \ + echo "一个或两个文件不存在: $$doc1, $$doc2"; \ + exit 1; \ + fi + # Fix links in www directory fix_links: @find ./www -type f -name "*.html" -exec sed -i.bak \