SHELL = /bin/sh
CMSROOT = ""
#CMSURL = http://keks.upful.org/p/
CMSURL = http://pyropeter.eu/
.SUFFIXES: .md .txt .htmlpart .htmlsum .html
.PHONY: clean watch
INS := $(shell find . -regextype posix-extended -iregex '.*\.(md|txt)' \
-printf '%TY%Tm%Td%TH%TM %P\n' | sort -r \
| cut -b14- | grep -v robots.txt)
OUTS := $(INS:.txt=.htmlpart)
OUTS := $(OUTS:.md=.htmlpart)
SUMS := $(OUTS:.htmlpart=.htmlsum)
HTMLS := $(OUTS:.htmlpart=.html) blog/index.html
LAYOUT := layout.pre layout.post
INPUT := $(INS) $(LAYOUT)
all: $(HTMLS) list.html listlong.html index.json sitemap.lst
@echo "DONE"
%.htmlpart: %.md
@echo "ART MD $<"
@echo "" > $@
@markdown_py -eutf-8 -ohtml4 $< >> $@
@printf "\n" >> $@
%.htmlpart: %.txt
@echo "ART TXT $<"
@echo "$<
" > $@
@sed 's/&/\&/g; s/\</g; s/>/\>/g' $< >> $@
@echo "
" >> $@
%.htmlsum: %.md
@echo "SUM MD $<"
@echo "" > $@
@head -n12 $< | markdown_py -sremove -eutf-8 -ohtml4 /dev/stdin | sed '0,//s!\(.*\)
!!' >> $@
@echo >> $@
@echo "
Read more…
" >> $@
@echo "" >> $@
%.htmlsum: %.txt
@echo "SUM TXT $<"
@echo "" >>$@
@head -n12 $< | sed 's/&/\&/g; s/\</g; s/>/\>/g' >> $@
@printf "\n
" >> $@
@echo "Read more…
" >> $@
@echo "" >> $@
%.html: %.htmlpart $(LAYOUT)
@echo "HTML $<"
@sed "s!\(
\)\(.*\)!\1$(shell grep /h1 $< | sed 's/<[^>]*>//g; s!\\!\\\\!g; s/!/\\!/g')\2!" layout.pre > $@
@cat $< >> $@
@cat layout.post >> $@
@sed -i "s %root% $(CMSROOT) g" $@
list.html: $(SUMS) $(LAYOUT)
@echo "LIST"
@cp layout.pre $@
@cat $(SUMS) >> $@
@cat layout.post >> $@
@sed -i "s %root% $(CMSROOT) g" $@
blog/index.html: $(filter blog/%,$(SUMS)) $(LAYOUT)
@echo "BLOG"
@sed "s!\(\)\(.*\)!\1Blog\2!" layout.pre > $@
@echo "" >> $@
@echo "My old blog still exists, but I also imported the old entries into this page." >> $@
@echo "
" >> $@
@cat $(filter blog/%,$(SUMS)) >> $@
@cat layout.post >> $@
@sed -i "s %root% $(CMSROOT) g" $@
listlong.html: $(OUTS) $(LAYOUT)
@echo "LISTLNG"
@cp layout.pre $@
@cat $(OUTS) >> $@
@cat layout.post >> $@
@sed -i "s %root% $(CMSROOT) g" $@
index.json: $(INS)
@echo "INDEX"
@./createindex $(INS) > index.json
sitemap.lst: FORCE
@echo "SITEMAP"
@echo "$(HTMLS)" | tr ' ' '\n' | sed 's!^!$(CMSURL)!; s!/index.html$$!/!' > $@
watch:
$(SHELL) -c 'while sleep 1 ; inotifywait -emodify -ecreate -emove $(INPUT) ; true ; do make ; done'
clean:
@echo "CLEAN"
@$(RM) $(OUTS) $(SUMS) $(HTMLS) index.json sitemap.lst
FORCE: