Commit: e4502622c568e3efca8fff6f0b16ebe2fa048111
Parent: 49f64afb6725ce90c8059a3213bf9980134d471b
Author: Randy Palamar
Date: Thu, 19 Aug 2021 13:18:47 -0600
replace card2html with deck2data
stdio buffering is preventing the scripts from working as originally
intended so this will be used as a workaround.
card2html never would have worked anyways because it wasn't a pure
textflow script like fetchcard, rubify, furigana.
Diffstat:
3 files changed, 35 insertions(+), 20 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,7 +1,7 @@
PREFIX=/usr/local
SCRIPTS =\
- card2html\
+ deck2data\
fetchcard\
furigana\
gencard\
diff --git a/card2html b/card2html
@@ -1,19 +0,0 @@
-#!/bin/sh
-
-# takes a path from stdin and outputs the card data in a format usable
-# by oboeruhttp on stdout
-
-read path
-front=$(smu "$path"/front.md | tr -d '\n' |
- sed 's;src="\([^"]*\)";src="/_/'$path'/\1";g')
-back=$(smu "$path"/back.md | tr -d '\n' |
- sed 's;src="\([^"]*\)";src="/_/'$path'/\1";g')
-
-extra="$path"/extra.html
-if [ -f "$extra" ]; then
- extra=$(cat "$extra" | tr -d '\n')
- front="$(echo "$front" | sed 's|==EXTRA==|'"$extra"'|g')"
- back="$(echo "$back" | sed 's|==EXTRA==|'"$extra"'|g')"
-fi
-
-printf "%s\t%s" "$front" "$back"
diff --git a/deck2data b/deck2data
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+# temporary script to workaround stdio buffering problem
+# takes a deck file and converts all cards to html
+# outputs 1 per line in the form "cardid\tfront\tback"
+
+usage() {
+ echo "usage: $0 cards.deck"
+ exit 1
+}
+
+[ $# -eq 1 ] || usage
+
+deck=$(echo "$1" | cut -d '.' -f 1)
+
+while read line; do
+ id=$(echo "$line" | cut -f 1)
+ path="$deck"/"$id"
+ front=$(smu "$path"/front.md | tr -d '\n' | rubify |
+ sed -e 's;src="\([^"]*\)";src="/_/'$path'/\1";g' \
+ -e 's:/\>:>:g')
+ back=$(smu "$path"/back.md | tr -d '\n' | rubify |
+ sed -e 's;src="\([^"]*\)";src="/_/'$path'/\1";g' \
+ -e 's:/\>:>:g')
+
+ extra="$path"/extra.html
+ if [ -f "$extra" ]; then
+ extra=$(cat "$extra" | tr -d '\n')
+ front="$(echo "$front" | sed 's|==EXTRA==|'"$extra"'|g')"
+ back="$(echo "$back" | sed 's|==EXTRA==|'"$extra"'|g')"
+ fi
+
+ printf "%s\t%s\t%s\n" "$id" "$front" "$back"
+done < $1