68 lines
1.9 KiB
Makefile
68 lines
1.9 KiB
Makefile
.PHONY: all render deploy update git serve new
|
|
|
|
# 默认目标:执行所有操作
|
|
all: render update git
|
|
|
|
# 渲染 .qmd 的命令:优先用 quarto CLI,其次用 R 的 quarto 包;
|
|
# 两者都没有时跳过(忽略 .qmd,直接用已提交的 .md)。
|
|
QUARTO ?= $(shell command -v quarto 2>/dev/null)
|
|
ifeq ($(QUARTO),)
|
|
QUARTO_R := $(shell Rscript -e 'if (requireNamespace("quarto", quietly = TRUE)) cat("yes")' 2>/dev/null)
|
|
endif
|
|
|
|
HUGO_CACHEDIR ?= $(TMPDIR)hugo-cache
|
|
export HUGO_CACHEDIR
|
|
|
|
# 目标:渲染 Quarto 文件
|
|
render:
|
|
ifeq ($(QUARTO),)
|
|
ifeq ($(QUARTO_R),yes)
|
|
Rscript -e "quarto::quarto_render()"
|
|
else
|
|
@echo "warn: quarto 与 R 的 quarto 包均未安装,跳过 .qmd 渲染,直接使用已生成的 .md"
|
|
endif
|
|
else
|
|
$(QUARTO) render
|
|
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=<article|note|math|music> S=<slug>"; exit 1; }
|
|
@test -n "$(S)" || { echo "用法: make new T=<article|note|math|music> S=<slug>"; 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:
|
|
if [ -n "$$(git status --porcelain)" ]; then \
|
|
git add -A; \
|
|
git commit -m "compile"; \
|
|
else \
|
|
echo "没有需要提交的改动"; \
|
|
fi; \
|
|
git push
|
|
|