From bd9abbe4eb94b9c77865bd28bf73ec6eb0b39a95 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 2 Apr 2015 17:34:26 -0700 Subject: Fix #15: add compile support for indeces --- trunk/common-titles.head | 17 +++++++++++++++++ trunk/common-titles.sh | 21 +++++++++++++++++++++ trunk/first-lines.head | 17 +++++++++++++++++ trunk/first-lines.sh | 32 +++++++++++++++++++++----------- 4 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 trunk/common-titles.head create mode 100644 trunk/common-titles.sh create mode 100644 trunk/first-lines.head (limited to 'trunk') diff --git a/trunk/common-titles.head b/trunk/common-titles.head new file mode 100644 index 0000000..705647d --- /dev/null +++ b/trunk/common-titles.head @@ -0,0 +1,17 @@ +--- +title: Autocento of the breakfast table +id: common-titles +subtitle: index of common titles +genre: prose + +project: + title: About Autocento + class: meta + next: + - title: Index of first lines + link: first-lines + prev: + - title: About _Autocento_ + link: about +... + diff --git a/trunk/common-titles.sh b/trunk/common-titles.sh new file mode 100644 index 0000000..9bc0de8 --- /dev/null +++ b/trunk/common-titles.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +outFile="$1"; +header="$2"; +shift 2; +glob="$@"; + +echo -n "Compiling ${outFile}..."; +cat "$header" > $outFile; + +for file in $glob; do + # Copy title to $outFile & link + title="$(grep '^title:' "$file" | cut -d' ' -f2- | sed 's/"//g')"; + if (( $RANDOM % 13 == 0 )); then + echo -n "| "; + else + echo -n " "; + fi + echo "[$title](${file%.*}.html)" >> "$outFile"; +done +echo "Done."; diff --git a/trunk/first-lines.head b/trunk/first-lines.head new file mode 100644 index 0000000..f73b410 --- /dev/null +++ b/trunk/first-lines.head @@ -0,0 +1,17 @@ +--- +title: Autocento of the breakfast table +id: first-lines +subtitle: index of first lines +genre: prose + +project: + title: About Autocento + class: meta + next: + - title: About _Autocento_ + link: about + prev: + - title: Index of common titles + link: common-titles +... + diff --git a/trunk/first-lines.sh b/trunk/first-lines.sh index 50b0e0c..37b7291 100644 --- a/trunk/first-lines.sh +++ b/trunk/first-lines.sh @@ -1,17 +1,27 @@ #!/bin/bash -outFile=src/first-lines.txt +outFile="$1"; +header="$2"; +shift 2; +glob="$@"; -echo "" > $outFile +firstLineOf() { # $1 = file + endOfYaml=$(sed -n '/^\.\.\.$/=' "$1") + tryLineNumber=$((endOfYaml + 1)) + try="" + while [[ -z $try ]]; do + try=$(head -n $tryLineNumber "$1" | tail -n 1 |\ + sed -e 's/^[|>] //' -e 's/[][]//g' -e 's/^#.*//' -e 's/^--.*//') + (( tryLineNumber += 1 )) + done + echo "$try" +} -for file in src/*.txt; do - echo -n "Getting first line of $file .. " - endOfYAML=$(sed -n '/^\.\.\.$/=' "$file") - firstLineNumber=$((endOfYAML + 2)) +echo -n "Compiling ${outFile}..." +cat "$header" > $outFile - echo "$file: " >> $outFile - echo " $(head -n $firstLineNumber "$file" | tail -n 1)" >> $outFile - - unset endOfYAML firstLineNumber - echo "Done." +for file in $glob; do + # Copy first line to $outFile & link + echo "[$(firstLineOf "$file")](${file%.*}.html)" >> $outFile done +echo "Done." -- cgit 1.4.1-21-gabe81