From f512d18a5913a5f257940e2dc40f39c7a77c0126 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Tue, 27 Apr 2021 15:02:02 +0200 Subject: [PATCH] Almost done --- Makefile | 28 ++++ engine/mk-index.sh | 156 ++++++++++++++++++ src/css/y.css | 3 + src/drafts/XXX-code-architecture/index.org | 2 +- .../index.org | 2 +- src/posts/0009-optim-nojs-website/index.org | 2 +- src/posts/0010-Haskell-Now/index.org | 2 +- src/posts/0011-export-tangle-names/index.org | 2 +- 8 files changed, 192 insertions(+), 5 deletions(-) create mode 100755 engine/mk-index.sh 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
  • " + printf "\\n%s" "${blogfile}" "$title" + printf "\\n%s%s" "$rssdate" + printf "%s" "$categories" + printf "\\n
  • \\n\\n" + } >> "$tmpdir/${d}-$(basename $fic).index" + dates=( $d $dates ) + echo " [${fg[green]}OK${reset_color}]" +done +echo "Publishing" +for fic in $(ls $tmpdir/*.index | sort -r | head -n $maxarticles ); do + echo "${fic:t}" + cat $fic >> $tmpdir/index +done + +rssmaxdate=$(formatdate $(for d in $dates; do echo $d; done | sort -r | head -n 1)) +rssbuilddate=$(formatdate $(date)) +title="Index" +description="Index of latest posts." +author="Yann Esposito" +{ +cat < + + + + + $title + + + + + + +
    + +
    +
    +
    +
    +

    $title

    +
    + $date on + + $author's blog +
    +
    + $description +
    +
    +
    +
    +END +cat $tmpdir/index +cat < +
    +
    + +
    +
    +
    + + +END +} > "$indexfile" + +rm -rf $tmpdir +echo "* RSS [done]" diff --git a/src/css/y.css b/src/css/y.css index 6dc22d5..d7e7612 100644 --- a/src/css/y.css +++ b/src/css/y.css @@ -266,3 +266,6 @@ code { background: var(--rbg); } .kw { color:var(--y); } .st { color:var(--g); } .co { color:var(--fg0); } + +.pubDate { font-size: .7em; color: var(--b1); } +.tag { font-size: .7em; background-color: var(--b1); } diff --git a/src/drafts/XXX-code-architecture/index.org b/src/drafts/XXX-code-architecture/index.org index ba234c2..678c4e6 100644 --- a/src/drafts/XXX-code-architecture/index.org +++ b/src/drafts/XXX-code-architecture/index.org @@ -2,7 +2,7 @@ #+AUTHOR: Yann Esposito #+EMAIL: yann@esposito.host #+DATE: [2021-01-10 Sun] -#+KEYWORDS: haskell, clojure, architecture, programming +#+KEYWORDS: haskell clojure architecture programming #+DESCRIPTION: Here is a simple description on how to architect a big functional programming application. #+OPTIONS: auto-id:t toc:nil diff --git a/src/posts/0007-switch-iterm-profile-catalina/index.org b/src/posts/0007-switch-iterm-profile-catalina/index.org index c8f589b..ad4a2ce 100644 --- a/src/posts/0007-switch-iterm-profile-catalina/index.org +++ b/src/posts/0007-switch-iterm-profile-catalina/index.org @@ -2,7 +2,7 @@ #+AUTHOR: Yann Esposito #+EMAIL: yann@esposito.host #+DATE: [2019-11-10 Sun] -#+KEYWORDS: self-hosting, chat, irc +#+KEYWORDS: self-hosting chat irc #+DESCRIPTION: Change the profile of iTerm in sync with macOS preferences. #+OPTIONS: auto-id:t toc:nil diff --git a/src/posts/0009-optim-nojs-website/index.org b/src/posts/0009-optim-nojs-website/index.org index 5bfd068..01a55a0 100644 --- a/src/posts/0009-optim-nojs-website/index.org +++ b/src/posts/0009-optim-nojs-website/index.org @@ -2,7 +2,7 @@ #+AUTHOR: Yann Esposito #+EMAIL: yann@esposito.host #+DATE: [2019-12-06 Fri] -#+KEYWORDS: blog, shell, script +#+KEYWORDS: blog shell script #+DESCRIPTION: Optimize the size of a full static website by taking advantage #+DESCRIPTION: of information found in both HTML and CSS. #+OPTIONS: auto-id:t toc:nil diff --git a/src/posts/0010-Haskell-Now/index.org b/src/posts/0010-Haskell-Now/index.org index 3a18613..642620a 100644 --- a/src/posts/0010-Haskell-Now/index.org +++ b/src/posts/0010-Haskell-Now/index.org @@ -3,7 +3,7 @@ #+date: [2019-12-15 Sun] #+author: Yann Esposito #+EMAIL: yann@esposito.host -#+keywords: Haskell, programming, functional, tutorial +#+keywords: Haskell programming functional tutorial #+DESCRIPTION: A short and intense introduction to Haskell. This is an update of my old (2012) article. A lot of things have changed since then. Mostly I changed my approach about the easiest way to install a Haskell playground. I removed the not as important part, and added a short introduction about starting a new project. #+OPTIONS: auto-id:t toc:t #+STARTUP: overview diff --git a/src/posts/0011-export-tangle-names/index.org b/src/posts/0011-export-tangle-names/index.org index 6521f94..5c96795 100644 --- a/src/posts/0011-export-tangle-names/index.org +++ b/src/posts/0011-export-tangle-names/index.org @@ -2,7 +2,7 @@ #+date: [2020-02-29 Sat] #+author: Yann Esposito #+EMAIL: yann@esposito.host -#+keywords: org-mode, blog +#+keywords: org-mode blog #+DESCRIPTION: Add links to code block during orgmode export. #+OPTIONS: auto-id:t toc:t #+STARTUP: overview