aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/archive22
-rwxr-xr-xbin/assemble10
-rwxr-xr-xbin/compile-book12
-rwxr-xr-xbin/compile-changelog67
4 files changed, 101 insertions, 10 deletions
diff --git a/bin/archive b/bin/archive
index 4d4c37a..d79d411 100755
--- a/bin/archive
+++ b/bin/archive
@@ -10,7 +10,9 @@ BASEDIR="$DIRNAME/.."
#ARCHIVE="$BASEDIR/archive"
ARCHIVE="archive"
ASSETS="build"
-REVISION="`git describe --tags 2> /dev/null || git log -1 --format=oneline | cut -d ' ' -f 1`"
+#REVISION="`git describe --tags 2> /dev/null || git log -1 --format=oneline | cut -d ' ' -f 1`"
+METADATA=".metadata"
+LATEST="$METADATA/latest.txt"
# Determine the revision file
if [ -e "$ASSETS/revision" ]; then
@@ -39,24 +41,24 @@ if [ ! -e "$REVFILE" ]; then
echo "# $BASENAME: skipping: revision file not found"
exit
else
- OLD_REVISION="`cat $REVFILE`"
+ REVISION="`cat $REVFILE`"
fi
# Check for non-null revision
-if [ -z "$OLD_REVISION" ]; then
+if [ -z "$REVISION" ]; then
echo "# $BASENAME: skipping: old revision is null"
exit
fi
-# Check if it's a tag
-if git tag | grep -q "^${OLD_REVISION}"; then
+# Check if the revision is a tag
+if git tag | grep -q "^${REVISION}$"; then
# Check if archive does not exists
- if [ ! -d "$ARCHIVE/$OLD_REVISION" ]; then
- echo "# $BASENAME: archiving $OLD_REVISION..."
- cp -alf $ASSETS $ARCHIVE/$OLD_REVISION
+ if [ ! -d "$ARCHIVE/$REVISION" ]; then
+ echo "# $BASENAME: archiving $REVISION..."
+ cp -alf $ASSETS $ARCHIVE/$REVISION
else
- echo "# $BASENAME: revision $OLD_REVISION already archived"
+ echo "# $BASENAME: revision $REVISION already archived"
fi
else
- echo "# $BASENAME: not archiving: revision $OLD_REVISION is not a tag"
+ echo "# $BASENAME: not archiving: revision $REVISION is not a tag"
fi
diff --git a/bin/assemble b/bin/assemble
index 04ae785..4c9d81c 100755
--- a/bin/assemble
+++ b/bin/assemble
@@ -32,3 +32,13 @@ fi
if [ -e "$NOTEBOOK" ]; then
mv $NOTEBOOK $BUILD/notes
fi
+
+# Move Atom feed
+if [ -e "atom.xml" ]; then
+ mv atom.xml $BUILD
+fi
+
+# Move RSS feed
+if [ -e "rss.xml" ]; then
+ mv rss.xml $BUILD
+fi
diff --git a/bin/compile-book b/bin/compile-book
index e68a36d..a068fe7 100755
--- a/bin/compile-book
+++ b/bin/compile-book
@@ -12,6 +12,8 @@ OUTPUT="${1:-book}"
REVISION="$2"
DATE="$3"
LANG="`grep lang _common.yml _book.yml _notes.yml 2> /dev/null | tail -1 | cut -d : -f 3 | sed -e 's/"//g' -e 's/ //g'`"
+METADATA=".metadata"
+LATEST="$METADATA/latest.txt"
# Set the language
if [ -z "$LANG" ]; then
@@ -32,6 +34,9 @@ rm -f $OUTPUT.md $OUTPUT.Rmd
cat _book.yml >> $OUTPUT.md ; echo "" >> $OUTPUT.md
cat _common.yml >> $OUTPUT.md ; echo "" >> $OUTPUT.md
+# Build changelog
+$DIRNAME/compile-changelog
+
# Bibliography
$BASEDIR/bin/biblio-yml > _biblio.yml
cat _biblio.yml >> $OUTPUT.md
@@ -74,3 +79,10 @@ fi
# Symlink as a Bookdown source
ln -sf $OUTPUT.md $OUTPUT.Rmd
+
+# Check if the revision is a tag
+if git tag | grep -q "^${REVISION}$"; then
+ # Save info on the latest tagged release
+ mkdir -p $METADATA
+ echo $REVISION > $LATEST
+fi
diff --git a/bin/compile-changelog b/bin/compile-changelog
new file mode 100755
index 0000000..862df31
--- /dev/null
+++ b/bin/compile-changelog
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+#
+# Feed compiler
+# Based on https://recursewithless.net/projects/pandoc-feeds.html
+#
+
+# Parameters
+BASENAME="`basename $0 | sed -e 's/\(.\)/\U\1/'`"
+DIRNAME="`dirname $0`"
+BASEDIR="$DIRNAME/.."
+CHANGES="_changelog.yml"
+CHANGELOG="content/notes/00-changelog/changelog.md"
+BOOK="_book.yml"
+COMMON="_common.yml"
+META=".metadata/feed.yml"
+RSS_TMPL="$BASEDIR/templates/rss.xml"
+ATOM_TMPL="$BASEDIR/templates/atom.xml"
+CHANGELOG_TMPL="$BASEDIR/templates/changelog.md"
+CHANGES_TMPL="$BASEDIR/templates/_changelog.yml"
+URL="snippets/url.txt"
+CONTACT="snippets/contact.txt"
+
+# Ensure the changes file exists
+if [ ! -e "$CHANGES" ]; then
+ # Create sample $CHANGES file
+ cp $CHANGES_TMPL $CHANGES
+fi
+
+# Create .metadata/feed.yaml with the needed metadata
+mkdir -p "`dirname $META`"
+echo '---' > $META
+echo "url: $(cat $URL)" >> $META
+echo "email: $(cat $CONTACT)" >> $META
+
+# Generate the Atom feed
+pandoc -M updated="$(LC_ALL=C date --iso-8601='seconds')" \
+ --metadata-file=$META \
+ --metadata-file=$CHANGES \
+ --metadata-file=$BOOK \
+ --metadata-file=$COMMON \
+ --template=$ATOM_TMPL \
+ -t plain \
+ -o atom.xml < /dev/null
+
+# Generate the RSS feed
+pandoc -M updated="$(LC_ALL=C date '+%d %b %Y %T %z')" \
+ --metadata-file=$META \
+ --metadata-file=$CHANGES \
+ --metadata-file=$BOOK \
+ --metadata-file=$COMMON \
+ --template=$RSS_TMPL \
+ -t plain \
+ -o rss.xml < /dev/null
+
+# Generate changelog.md
+mkdir -p "`dirname $CHANGELOG`"
+pandoc \
+ --metadata-file=$META \
+ --metadata-file=$CHANGES \
+ --metadata-file=$BOOK \
+ --metadata-file=$COMMON \
+ --template=$CHANGELOG_TMPL \
+ -t markdown \
+ -o $CHANGELOG < /dev/null
+
+# Fix list formatting in the Markdown output
+sed -i -e 's/- /* /' $CHANGELOG