site

scripts to generate personal blog and git repositories

git clone https://9o.is/git/site.git

Makefile

(3046B)


      1 .POSIX:
      2 .SUFFIXES: .md .cfg .html .git .out
      3 
      4 SAAIT        = saait
      5 STAGIT       = stagit
      6 STAGIT_INDEX = stagit-index
      7 LOWDOWN      = lowdown
      8 RCLONE       = rclone
      9 OUTDIR       = output
     10 RCLONE_PATH  = sftp:9o.is/htdocs
     11 RCLONE_ARGS  = -v --size-only --stats 5s --stats-one-line
     12 
     13 REPOS      != find stagit -type f -name '*.git'
     14 PAGES      != find pages -type f -name '*.md'
     15 REPOS_OUT  != echo "$(REPOS)"  | tr ' ' '\n' | sed 's|\.git$$|.out|g'
     16 PAGES_CFG  != echo "$(PAGES)"  | tr ' ' '\n' | sed 's|\.md$$|.cfg|g'
     17 PAGES_HTML != echo "$(PAGES)"  | tr ' ' '\n' | sed 's|\.md$$|.html|g'
     18 
     19 all: $(OUTDIR)/index.html $(OUTDIR)/git/index.html stagit-all
     20 
     21 $(OUTDIR)/index.html: $(PAGES_HTML) $(PAGES_CFG)
     22 	@printf "  %-8s %s\n" "SAAIT" "$@"
     23 	@mkdir -p $(OUTDIR)
     24 	@printf "$(PAGES_CFG)" | sort -r | xargs $(SAAIT)
     25 	@cp -r assets/* $(OUTDIR)
     26 
     27 $(OUTDIR)/git/index.html: $(REPOS_OUT)
     28 	@printf "  %-8s %s\n" "STAGIT" "$@"
     29 	@mkdir -p $(OUTDIR)/git
     30 	@sorted_repos=$$( \
     31 		for repo in $(REPOS); do \
     32 			path=""; \
     33 			. "$$repo"; \
     34 			if [ -n "$$path" ] && [ -d "$$path" ]; then \
     35 				ts=$$(git --git-dir="$$path" log -1 --format="%ct" 2>/dev/null || echo 0); \
     36 				echo "$$ts $$path"; \
     37 			fi; \
     38 		done | sort -rn | cut -d' ' -f2- \
     39 	); \
     40 	$(STAGIT_INDEX) $$sorted_repos > $@
     41 
     42 stagit-all: $(REPOS_OUT)
     43 	@for repo in $(REPOS); do \
     44 		source $$repo && $(MAKE) REPO=$$name stagit; \
     45 	done
     46 
     47 stagit-sync-all: $(REPOS_OUT)
     48 	@for repo in $(REPOS); do \
     49 		source $$repo && $(MAKE) REPO=$$name sync-stagit; \
     50 	done
     51 
     52 stagit: $(OUTDIR)/git/index.html
     53 	@test "$(REPO)" || { echo "error: missing REPO argument" 1>&2; exit 1; }
     54 	@test -e stagit/$(REPO).git || { echo "error: $(REPO) not configured" 1>&2; exit 1; }
     55 	@printf "  %-8s %s\n" "STAGIT" "$(REPO)"
     56 	@mkdir -p $(OUTDIR)/git/$(REPO)
     57 	@source stagit/$(REPO).git; \
     58 		cd $(OUTDIR)/git/$(REPO); \
     59 		$(STAGIT) $$path
     60 
     61 sync-git-repo:
     62 	@printf "  %-8s %s\n" "SYNC" "$(REPO).git"
     63 	@source stagit/$(REPO).git; \
     64 		cd $$path && git update-server-info; \
     65 		$(RCLONE) $(RCLONE_ARGS) sync $$path $(RCLONE_PATH)/git/$(REPO).git
     66 
     67 sync-stagit: stagit sync-git-repo
     68 	@printf "  %-8s %s\n" "SYNC" "$(REPO)"
     69 	@$(RCLONE) $(RCLONE_ARGS) sync \
     70 		--include '/index.html' --include '/$(REPO)/**' \
     71 		output/git $(RCLONE_PATH)/git
     72 
     73 sync-blog: $(OUTDIR)/index.html
     74 	@printf "  %-8s %s\n" "SYNC" "blog"
     75 	@$(RCLONE) $(RCLONE_ARGS) sync --max-depth 1 output $(RCLONE_PATH)
     76 	@$(RCLONE) $(RCLONE_ARGS) sync output/images $(RCLONE_PATH)/images
     77 
     78 clean:
     79 	@rm -rf $(OUTDIR)
     80 	@rm -f pages/*.cfg
     81 	@rm -f pages/*.html
     82 	@rm -f stagit/*.out
     83 
     84 .md.cfg:
     85 	@printf "  %-8s %s\n" "LOWDOWN" "$@"
     86 	@rm -f $@
     87 	@for cfg in `$(LOWDOWN) -L $<`; do \
     88 		echo "$$cfg = `$(LOWDOWN) -X "$$cfg" $<`" >> $@; \
     89 	done
     90 
     91 .md.html:
     92 	@printf "  %-8s %s\n" "LOWDOWN" "$@"
     93 	@$(LOWDOWN) --html-no-skiphtml --html-no-escapehtml $< > $@
     94 
     95 .git.out:
     96 	@printf "  %-8s %s\n" "GEN" "$<"
     97 	@source $<; \
     98 		printf "$$description" > $$path/description; \
     99 		printf "https://9o.is/git/%s.git" "$$name" > $$path/url; \
    100 		touch $@
    101 
    102 .PHONY: all stagit stagit-all stagit-sync-all sync-stagit sync-blog clean