diff --git a/Makefile b/Makefile index d5ba539..f87ed79 100644 --- a/Makefile +++ b/Makefile @@ -11,11 +11,13 @@ SRC_RAW_FILES := $(shell find $(SRC_DIR) -type f) DST_RAW_FILES := $(patsubst $(SRC_DIR)/%,$(DST_DIR)/%,$(SRC_RAW_FILES)) ALL += $(DST_RAW_FILES) +# COPY EVERYTHING $(DST_DIR)/% : $(SRC_DIR)/% mkdir -p "$(dir $@)" cp "$<" "$@" +# ORG -> HTML EXT := .org SRC_PANDOC_FILES ?= $(shell find $(SRC_DIR) -type f -name "*$(EXT)") DST_PANDOC_FILES ?= $(subst $(EXT),.html, \ @@ -40,6 +42,32 @@ $(DST_DIR)/%.html: $(SRC_DIR)/%.org $(TEMPLATE) $(PANDOC) $< \ --output $@ + +# HTML INDEX +HTML_INDEX := $(DST_DIR)/index.html + +$(HTML_INDEX): $(SRC_PANDOC_FILES) + mkdir -p $(DST_DIR) + engine/mk-index.sh + +ALL += $(HTML_INDEX) + +# ORG -> GEMINI +EXT := .org +SRC_GMI_FILES ?= $(shell find $(SRC_DIR) -type f -name "*$(EXT)") +DST_GMI_FILES ?= $(subst $(EXT),.gmi, \ + $(subst $(SRC_DIR),$(DST_DIR), \ + $(SRC_GMI_FILES))) + +ALL += $(DST_GMI_FILES) + +GMI := engine/org2gemini.sh + +$(DST_DIR)/%.gmi: $(SRC_DIR)/%.org + mkdir -p $(dir $@) + $(GMI) "$<" "$@" + + allatend: $(ALL) clean: diff --git a/engine/mk-index.sh b/engine/mk-index.sh new file mode 100755 index 0000000..32bffa3 --- /dev/null +++ b/engine/mk-index.sh @@ -0,0 +1,156 @@ +#!/usr/bin/env zsh + +cd "$(git rev-parse --show-toplevel)" || exit 1 +# Directory +webdir="_site" +postsdir="$webdir/posts" +indexfile="$webdir/index.html" + +# maximal number of articles to put in the RSS file +maxarticles=10 + +# RSS Metas +rsstitle="her.esy.fun" +rssurl="https://her.esy.fun/rss.xml" +websiteurl="https://her.esy.fun" +rssdescription="her.esy.fun articles, mostly random personal thoughts" +rsslang="en" +rssauthor="yann@esposito.host (Yann Esposito)" +rssimgurl="https://her.esy.fun/img/FlatAvatar.png" + +# HTML Accessors (similar to CSS accessors) +dateaccessor='.yyydate' +contentaccessor='#content' +# title and keyword shouldn't be changed +titleaccessor='title' +keywordsaccessor='meta[name=keywords]::attr(content)' + +formatdate() { + # format the date for RSS + local d="$1" + # echo "DEBUG DATE: $d" >&2 + LC_TIME=en_US date --date $d +'%a, %d %b %Y %H:%M:%S %z' +} + +finddate(){ < $1 hxselect -c $dateaccessor | sed 's/\[//g;s/\]//g;s/ .*$//' } +findtitle(){ < $1 hxselect -c $titleaccessor } +getcontent(){ + < $1 hxselect $contentaccessor | \ + perl -pe 'use URI; $base="'$2'"; s# (href|src)="((?!https?://)[^"]*)"#" ".$1."=\"".URI->new_abs($2,$base)->as_string."\""#eig' } +findkeywords(){ < $1 hxselect -c $keywordsaccessor | sed 's/,/ /g' } +mkcategories(){ + for keyword in $*; do + printf "\\n%s" $keyword + done +} + +autoload -U colors && colors + +tmpdir=$(mktemp -d) +typeset -a dates +dates=( ) +for fic in $postsdir/**/*.html; do + if echo $fic|egrep -- '-(mk|min|sci|modern).html$'>/dev/null; then + continue + fi + postfile="$(echo "$fic"|sed 's#^'$postsdir'/##')" + blogfile="$(echo "$fic"|sed 's#^'$webdir'/##')" + printf "%-30s" $postfile + xfic="$tmpdir/$fic.xml" + mkdir -p $(dirname $xfic) + hxclean $fic > $xfic + d=$(finddate $xfic) + echo -n " [$d]" + rssdate=$(formatdate $d) + title=$(findtitle $xfic) + keywords=( $(findkeywords $xfic) ) + printf ": %-55s" "$title ($keywords)" + categories=$(mkcategories $keywords) + absoluteurl="${websiteurl}/${blogfile}" + { printf "\\n