M .woodpecker.yml => .woodpecker.yml +4 -3
@@ 1,14 1,15 @@
+---
pipeline:
# build static content
build:
image: alpine
commands:
- - apk add sed pandoc
- - sh ./build.sh
+ - apk add bash sed pandoc
+ - bash ./build.sh https://ccw.icu
# publish content
publish:
image: alpine
- secrets: [ deploy_pass ]
+ secrets: [deploy_pass]
commands:
- apk add rsync
- export RSYNC_PASSWORD="$${DEPLOY_PASS}"
M build.sh => build.sh +99 -4
@@ 1,13 1,17 @@
#!/bin/bash
# depends: pandoc, sed, awk
+host="${1:-https://example.com}"
root="$(dirname $0)"
srcdir="$root/src"
assetdir="$root/res"
+eldir="$root/el"
+templatedir="$root/templates"
builddir="$root/build"
+feedsdir="$srcdir/feeds"
# pandoc syntax highlighting theme
-pandocTheme="./el/gruvbox.theme"
+pandocTheme="$templatedir/gruvbox.theme"
# pandoc export target
pandocTarget="html5"
pandocTargetExtension="html"
@@ 24,7 28,9 @@ function convertOrg() {
-t $pandocTarget \
-c '/base.css' \
--toc --toc-depth=1 \
- --template ./el/html.template \
+ -V postlink="$3" \
+ -M date-meta="$4" \
+ --template $2 \
--highlight-style="$pandocTheme" \
- |
# pandoc does not autoreplace the ->.org links,
@@ 42,12 48,23 @@ mkdir -p $builddir
cp $assetdir/* -r $builddir
prefix="s/^$(echo $srcdir | sed 's/\//\\\//')\///"
-
# loop through all source files
find $srcdir -type f | \
# remove leading $srcdir
sed "$prefix" | \
+ # create a publishing date + path id to sort the posts
while read file; do
+ ts="$(cat $srcdir/$file | \
+ grep -E '#\+DATE: <([^<>]+)>' | \
+ sed -r 's/#\+DATE: <([^<>]+)>/\1/' | \
+ head -n 1)"
+ echo "$ts;$file"
+ done | \
+ # sort the posts by date
+ sort -r | \
+ while read mark; do
+ file="$(echo $mark | awk -F';' '{ print $2 }')"
+ ts="$(echo $mark | awk -F';' '{ print $1 }')"
# initialise builddir path
mkdir -p "$(dirname "$builddir/$file")"
@@ 58,10 75,88 @@ find $srcdir -type f | \
newName="$(echo $file | sed "s/\.org$/\.$pandocTargetExtension/")"
echo $newName
# me need to convert .org files
- convertOrg $srcdir/$file \
+ convertOrg $srcdir/$file $templatedir/page.html \
> $builddir/$newName
+
+ if [ ! "$(basename $file)" = "index.org" ] && [ ! "$ts" = "" ]; then
+ root="$(echo $file | awk -F'/' '{ print $1 }')"
+ if [ $root = "feeds" ]; then
+ # is a blog post
+ # so we have to generate an rss feed compatible version
+
+ # id of the subfeed
+ feed="$(echo $file | awk -F'/' '{ print $2 }')"
+
+ filename=$(basename $file | sed -r 's/org$/html/')
+ cont="$(convertOrg \
+ $srcdir/$file \
+ $templatedir/rss-post.xml \
+ $host/feeds/$feed/$filename \
+ $ts
+ )"
+
+ echo "$cont" >> $builddir/feeds/rss
+ echo "$cont" >> $builddir/feeds/$feed/rss
+ fi
+ fi
else
# all other files can just be copied to the build dir
cp $srcdir/$file $builddir/$file
fi
done
+
+# RSS FEED
+function read_arg() {
+ file=$1
+ arg=$2
+
+ reg="#\+$arg: ([^\n]+)"
+
+ # print file
+ cat $1 | \
+ # only select lines with a reasonable beginning
+ grep -E "$reg" | \
+ # only use the first entry
+ head -n 1 | \
+ # extract the text
+ sed -r "s/$reg/\1/"
+}
+function escape() {
+ echo $1 | \
+ sed -r 's/\//\\\//g' | \
+ sed -r 's/\./\\\./g'
+}
+rssheader="$(cat $templatedir/rss-header.xml)"
+rssfooter="$(cat $templatedir/rss-footer.xml)"
+# list all feeds
+find $feedsdir -type d -maxdepth 1 | \
+ # remove ugly prefixes
+ sed "$prefix" |
+ # loop over feeds
+ while read feed; do
+ rsspath="$builddir/$feed/rss"
+ infopath="$srcdir/$feed/index.org"
+ webpath="$host/$feed/index.html"
+
+ # only publish rss feeds with at least one post
+ if [ -f $rsspath ]; then
+ rsscont="$(cat $rsspath)"
+
+ title="$(read_arg $infopath TITLE)"
+ description="$(read_arg $infopath DESCRIPTION)"
+
+ # overwrite file with header
+ echo "$rssheader" | \
+ # replace weblink
+ sed -r "s/\\\$host\\\$/$(escape "$webpath")/g" | \
+ # replace feed title
+ sed -r "s/\\\$title\\\$/$(escape "$title")/g" | \
+ # replace feed description
+ sed -r "s/\\\$description\\\$/$(escape "$description")/g" \
+ > $rsspath
+ # add content back to feed
+ echo "$rsscont" >> $rsspath
+ # close missing tags
+ echo "$rssfooter" >> $rsspath
+ fi
+ done
R el/gruvbox.theme => templates/gruvbox.theme +0 -0
R el/html.template => templates/page.html +0 -0
A => +2 -0
@@ 0,0 1,2 @@
</channel>
</rss>
A => +6 -0
@@ 0,0 1,6 @@
<rss version="2.0">
<channel>
<title>$title$</title>
<description>$description$</description>
<link>$host$</link>
<generator>pandoc + bash script</generator>
A => +13 -0
@@ 0,0 1,13 @@
<item>
<title>$if(title-prefix)$$title-prefix$ - $endif$$pagetitle$</title>
<description>
$body$
</description>
<link>
$postlink$
</link>
<guid>
$postlink$
</guid>
<pubDate>$date-meta$</pubDate>
</item>