aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--v2/.gitignore2
-rw-r--r--v2/dynamic.mk12
-rwxr-xr-xv2/src/bin/extract103
-rwxr-xr-xv2/src/development/dynmake.sh3
4 files changed, 116 insertions, 4 deletions
diff --git a/v2/.gitignore b/v2/.gitignore
index 74445d1..4ce7eaa 100644
--- a/v2/.gitignore
+++ b/v2/.gitignore
@@ -6,4 +6,4 @@
/src/content/pastebins/*.html
/src/content/pastebins/*.txt
-/src/content/pastebins/*.feed-entry
+/src/content/pastebins/*.entry-*
diff --git a/v2/dynamic.mk b/v2/dynamic.mk
index 09edfa7..01b8917 100644
--- a/v2/dynamic.mk
+++ b/v2/dynamic.mk
@@ -11,7 +11,7 @@ include generated.mk
.SUFFIXES:
-.SUFFIXES: .md .html .in
+.SUFFIXES: .md .html .in .entry-content .entry-env
.in:
@@ -24,6 +24,12 @@ include generated.mk
.md.html:
sh src/development/genhtml.sh $< > $@
+.md.entry-content:
+ extract -t content < $? > $@
+
+.md.entry-env:
+ extract -t env < $? > $@
+
pastebins.html = $(pastebins.md:.md=.html)
@@ -49,8 +55,8 @@ collections = pastebins
clean:
for c in $(collections); do \
rm -f \
- src/content/$$c/*.txt \
- src/content/$$c/*.atom; \
+ src/content/$$c/*.entry-* \
+ src/content/$$c/*.txt; \
done
rm -rf \
$(ALL) generated.mk src/development/config.env \
diff --git a/v2/src/bin/extract b/v2/src/bin/extract
new file mode 100755
index 0000000..ce4b115
--- /dev/null
+++ b/v2/src/bin/extract
@@ -0,0 +1,103 @@
+#!/bin/sh
+set -eu
+
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ extract -t TYPE < STDIN
+ extract -h
+ EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -t TYPE the type of extraction to perform ("content" or "env")
+ -h, --help show this message
+
+
+ Separate the content from the "frontmatter", and emit the
+ selected one.
+
+
+ Examples:
+
+ Get the content:
+
+ $ extract -t content < src/file.md > src/file.entry-content
+
+
+ Get the "frontmatter":
+
+ $ extract -t env < src/f.md > src/f.entry-env
+ EOF
+}
+
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+TYPE=''
+while getopts 't:h' flag; do
+ case "$flag" in
+ t)
+ TYPE="$OPTARG"
+ ;;
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+
+eval "$(assert-arg "$TYPE" '-t TYPE')"
+
+
+case "$TYPE" in
+ content)
+ awk '
+ separator >= 2
+ /^---$/ { separator++ }
+ '
+ ;;
+ env)
+ awk '
+ /^---$/ {
+ if (++separator > 1) {
+ exit
+ } else {
+ next
+ }
+ }
+
+ { print }
+ '
+ ;;
+ *)
+ printf 'Bad value for TYPE: "%s".\n\n' \
+ "$TYPE" >&2
+ usage >&2
+ exit 2
+ ;;
+esac
diff --git a/v2/src/development/dynmake.sh b/v2/src/development/dynmake.sh
index a04e70e..033cbc3 100755
--- a/v2/src/development/dynmake.sh
+++ b/v2/src/development/dynmake.sh
@@ -73,3 +73,6 @@ pastebins() {
printf 'pastebins.md = \\\n'
pastebins | varlist
printf '\n'
+
+pastebins | sed 's/^\(.*\)\.md$/\1.html: \1.entry-content/'
+pastebins | sed 's/^\(.*\)\.md$/\1.html: \1.entry-env/'