From fb993d8928f54d57366cdd3162b871134f5d4332 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Sat, 8 May 2021 10:07:10 +0200 Subject: [PATCH] parallized rss build --- .gitignore | 7 +------ Makefile | 18 ++++++++++++------ engine/mk-index.sh | 2 +- engine/mk-rss-entry.sh | 11 +++-------- engine/mkrss.sh | 19 +++++++++++-------- 5 files changed, 28 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 70863a7..85226e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,3 @@ -_cache/ +.cache/ _site/ -_optim/ -src/archive.org .direnv/ -_shake/ -.shake/ -dist-newstyle/ diff --git a/Makefile b/Makefile index ab20643..d1e7a07 100644 --- a/Makefile +++ b/Makefile @@ -56,17 +56,18 @@ $(HTML_INDEX): $(DST_PANDOC_FILES) $(MKINDEX) ALL += $(HTML_INDEX) # RSS - SRC_POSTS_DIR ?= $(SRC_DIR)/posts -SRC_POST_FILES ?= $(shell find $(SRC_POSTS_DIR) -type f -name "*$(EXT)") +DST_POSTS_DIR ?= $(DST_DIR)/posts +SRC_POSTS_FILES ?= $(shell find $(SRC_POSTS_DIR) -type f -name "*$(EXT)") RSS_CACHE_DIR ?= $(CACHE_DIR)/rss -DST_RSS_FILES ?= $(subst .$(EXT),.rss, \ +DST_RSS_FILES ?= $(patsubst %.org,%.rss, \ $(patsubst $(SRC_POSTS_DIR)/%,$(RSS_CACHE_DIR)/%, \ $(SRC_POSTS_FILES))) MK_RSS_ENTRY := ./engine/mk-rss-entry.sh -$(RSS_CACHE_DIR)/%.rss: $(DST_DIR)/posts/%.html $(MK_RSS_ENTRY) +$(RSS_CACHE_DIR)/%.rss: $(DST_POSTS_DIR)/%.html $(MK_RSS_ENTRY) @mkdir -p $(RSS_CACHE_DIR) - $(MK_RSS_ENTRY) $@ + $(MK_RSS_ENTRY) "$<" "$@" +ALL += $(DST_RSS_FILES) RSS := $(DST_DIR)/rss.xml MKRSS := engine/mkrss.sh @@ -74,11 +75,14 @@ $(RSS): $(DST_RSS_FILES) $(MKRSS) $(MKRSS) ALL += $(RSS) +rss: $(DST_RSS_FILES) $(RSS) + + # ORG -> GEMINI EXT := .org SRC_GMI_FILES ?= $(shell find $(SRC_DIR) -type f -name "*$(EXT)" $(NO_DRAFT)) DST_GMI_FILES ?= $(subst $(EXT),.gmi, \ - $(subst $(SRC_DIR),$(DST_DIR), \ + $(patsubst $(SRC_DIR)/%,$(DST_DIR)/%, \ $(SRC_GMI_FILES))) GMI := engine/org2gemini.sh $(DST_DIR)/%.gmi: $(SRC_DIR)/%.org $(GMI) engine/org2gemini_step1.sh @@ -101,6 +105,8 @@ $(GEM_ATOM): $(DST_GMI_FILES) $(MK_GEMINI_ATOM) $(MK_GEMINI_ATOM) ALL += $(GEM_ATOM) +gemini: $(DST_GMI_FILES) $(GMI_INDEX) $(GEM_ATOM) + # Images SRC_IMG_FILES ?= $(shell find $(SRC_DIR) -type f -name "*.jpg" -or -name "*.jpeg" -or -name "*.gif" -or -name "*.png") DST_IMG_FILES ?= $(patsubst $(SRC_DIR)/%,$(DST_DIR)/%, $(SRC_IMG_FILES)) diff --git a/engine/mk-index.sh b/engine/mk-index.sh index d424cf9..84faab1 100755 --- a/engine/mk-index.sh +++ b/engine/mk-index.sh @@ -145,4 +145,4 @@ template=$(< templates/post.html | perl -pe 's#(\$[^\$]*)\$#$1#g' ) } > "$indexfile" rm -rf $tmpdir -echo "* RSS [done]" +echo "* HTML INDEX [done]" diff --git a/engine/mk-rss-entry.sh b/engine/mk-rss-entry.sh index 4a6f26c..a76abaa 100755 --- a/engine/mk-rss-entry.sh +++ b/engine/mk-rss-entry.sh @@ -8,6 +8,7 @@ indexdir=".cache/rss" # file to handle fic="$1" +dst="$2" # RSS Metas websiteurl="https://her.esy.fun" @@ -41,15 +42,10 @@ mkcategories(){ autoload -U colors && colors -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="$indexdir/$fic.xml" -mkdir -p $(dirname $xfic) +xfic="${dst:r}.xml" hxclean $fic > $xfic d=$(finddate $xfic) echo -n " [$d]" @@ -59,7 +55,6 @@ keywords=( $(findkeywords $xfic) ) printf ": %-55s" "$title ($keywords)" categories=$(mkcategories $keywords) absoluteurl="${websiteurl}/${blogfile}" -dst="$indexdir/$fic.rss" mkdir -p $(dirname $dst) { printf "\\n" printf "\\n%s" "$title" @@ -68,5 +63,5 @@ mkdir -p $(dirname $dst) printf "%s" "$categories" printf "\\n" "$(getcontent "$xfic" "$absoluteurl")" printf "\\n\\n\\n" -} >> "$dst" +} > "$dst" echo " [${fg[green]}OK${reset_color}]" diff --git a/engine/mkrss.sh b/engine/mkrss.sh index f53253a..ba6d4b4 100755 --- a/engine/mkrss.sh +++ b/engine/mkrss.sh @@ -32,28 +32,29 @@ formatdate() { isodate() { # format the date for sorting local d="$1" - # echo "DEBUG DATE: $d" >&2 - LC_TIME=en_US date --date $d +'%Y-%m-%dT%H:%M:%S' + echo "DEBUG DATE: $d" >&2 + LC_TIME=en_US date --date "$d" +'%Y-%m-%dT%H:%M:%S' } -finddate(){ < $1 hxselect -c $dateaccessor | sed 's/\[//g;s/\]//g;s/ .*$//' } +finddate(){ < $1 hxselect -c $dateaccessor } autoload -U colors && colors typeset -a dates dates=( ) tmpdir=$(mktemp -d) -for fic in $indexdir/*.rss; do - rssdate=$(finddate $xfic) - echo -n "${fic:t} [$d]" +for fic in $indexdir/**/*.rss; do + rssdate=$(finddate $fic) + echo -n "${fic:r} [$d]" d=$(isodate $rssdate) dates=( $d $dates ) echo " [${fg[green]}OK${reset_color}]" - cp $fic $tmpdir/$d-${fic:t}.rss + cp $fic $tmpdir/$d-${${fic:h}:t}.rss done echo "Publishing" +n=1 for fic in $(ls $tmpdir/*.rss | sort -r | head -n $maxarticles ); do - echo "${fic:t}" + echo "$((n++)) ${fic:t}" cat $fic >> $tmpdir/rss done @@ -97,6 +98,8 @@ END # HACK TO UPDATE OLD RSS FEEDS legacyenrss="$webdir/Scratch/en/blog/feed/feed.xml" legacyfrrss="$webdir/Scratch/fr/blog/feed/feed.xml" +mkdir -p "${legacyenrss:h}" +mkdir -p "${legacyfrrss:h}" cp -f "$rssfile" "$legacyenrss" cp -f "$rssfile" "$legacyfrrss"