重建个人应用入口与静态博客,保留旧文章并支持本地发布
This commit is contained in:
@@ -1,47 +1,20 @@
|
||||
SHELL := /bin/bash
|
||||
POSTS := content/posts
|
||||
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
.PHONY: help new serve build publish clean
|
||||
|
||||
PYTHON := .venv/bin/python
|
||||
.PHONY: help install build test serve deploy
|
||||
help:
|
||||
@echo 'targets:'
|
||||
@echo ' make new SLUG=<slug> TITLE="<标题>" [SUMMARY="<摘要>"] # 新建文章'
|
||||
@echo ' make serve # hugo server -D (需装 hugo)'
|
||||
@echo ' make build # hugo build 到 public/'
|
||||
@echo ' make publish MSG="post: <slug>" # commit + push, 触发 CI'
|
||||
@echo ' make clean # rm -rf public/'
|
||||
|
||||
new:
|
||||
@test -n "$(SLUG)" || { echo 'SLUG required'; exit 1; }
|
||||
@test -n "$(TITLE)" || { echo 'TITLE required'; exit 1; }
|
||||
@test ! -e $(POSTS)/$(SLUG).md || { echo "$(POSTS)/$(SLUG).md already exists"; exit 1; }
|
||||
@DATE="$$(date '+%Y-%m-%dT%H:%M:%S%:z')"; \
|
||||
{ \
|
||||
echo '---'; \
|
||||
echo 'title: "$(TITLE)"'; \
|
||||
echo "date: $$DATE"; \
|
||||
echo 'draft: false'; \
|
||||
if [ -n "$(SUMMARY)" ]; then echo 'summary: "$(SUMMARY)"'; fi; \
|
||||
echo '---'; \
|
||||
echo ''; \
|
||||
echo '<!-- 正文写这里 (markdown) -->'; \
|
||||
} > $(POSTS)/$(SLUG).md
|
||||
@echo "created $(POSTS)/$(SLUG).md"
|
||||
|
||||
serve:
|
||||
hugo server -D
|
||||
|
||||
build:
|
||||
hugo --minify --gc
|
||||
|
||||
publish:
|
||||
@test -n "$(MSG)" || { echo 'MSG required (e.g. MSG="post: 你好世界")'; exit 1; }
|
||||
git add content/
|
||||
@git diff --cached --quiet && { echo 'nothing to commit'; exit 1; } || true
|
||||
git commit -m "$(MSG)"
|
||||
git push
|
||||
|
||||
clean:
|
||||
rm -rf public/
|
||||
@echo 'make install | build | test | serve | deploy'
|
||||
@echo '文章: content/posts/*.md;应用: apps.json;样式: assets/site.css'
|
||||
install: .venv/.installed
|
||||
.venv/.installed: requirements.txt
|
||||
uv venv --allow-existing .venv
|
||||
uv pip install --python $(PYTHON) -r requirements.txt
|
||||
touch $@
|
||||
build: install
|
||||
$(PYTHON) build.py
|
||||
test: install
|
||||
$(PYTHON) -m unittest discover -s tests -v
|
||||
serve: build
|
||||
$(PYTHON) -m http.server 4176 --bind 127.0.0.1 --directory public
|
||||
deploy: test
|
||||
$(PYTHON) deploy.py
|
||||
|
||||
Reference in New Issue
Block a user