diff options
author | Case Duckworth | 2015-04-02 17:34:26 -0700 |
---|---|---|
committer | Case Duckworth | 2015-04-02 17:34:26 -0700 |
commit | bd9abbe4eb94b9c77865bd28bf73ec6eb0b39a95 (patch) | |
tree | ebfeb8135d5610aac69b8938d4dab09b23b758e2 /trunk | |
parent | Refactor makefile; Add hapax preprocessor (diff) | |
download | autocento-bd9abbe4eb94b9c77865bd28bf73ec6eb0b39a95.tar.gz autocento-bd9abbe4eb94b9c77865bd28bf73ec6eb0b39a95.zip |
Fix #15: add compile support for indeces
Diffstat (limited to 'trunk')
-rw-r--r-- | trunk/common-titles.head | 17 | ||||
-rw-r--r-- | trunk/common-titles.sh | 21 | ||||
-rw-r--r-- | trunk/first-lines.head | 17 | ||||
-rw-r--r-- | trunk/first-lines.sh | 32 |
4 files changed, 76 insertions, 11 deletions
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 @@ | |||
1 | --- | ||
2 | title: Autocento of the breakfast table | ||
3 | id: common-titles | ||
4 | subtitle: index of common titles | ||
5 | genre: prose | ||
6 | |||
7 | project: | ||
8 | title: About Autocento | ||
9 | class: meta | ||
10 | next: | ||
11 | - title: Index of first lines | ||
12 | link: first-lines | ||
13 | prev: | ||
14 | - title: About _Autocento_ | ||
15 | link: about | ||
16 | ... | ||
17 | |||
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 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | outFile="$1"; | ||
4 | header="$2"; | ||
5 | shift 2; | ||
6 | glob="$@"; | ||
7 | |||
8 | echo -n "Compiling ${outFile}..."; | ||
9 | cat "$header" > $outFile; | ||
10 | |||
11 | for file in $glob; do | ||
12 | # Copy title to $outFile & link | ||
13 | title="$(grep '^title:' "$file" | cut -d' ' -f2- | sed 's/"//g')"; | ||
14 | if (( $RANDOM % 13 == 0 )); then | ||
15 | echo -n "| "; | ||
16 | else | ||
17 | echo -n " "; | ||
18 | fi | ||
19 | echo "[$title](${file%.*}.html)" >> "$outFile"; | ||
20 | done | ||
21 | 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 @@ | |||
1 | --- | ||
2 | title: Autocento of the breakfast table | ||
3 | id: first-lines | ||
4 | subtitle: index of first lines | ||
5 | genre: prose | ||
6 | |||
7 | project: | ||
8 | title: About Autocento | ||
9 | class: meta | ||
10 | next: | ||
11 | - title: About _Autocento_ | ||
12 | link: about | ||
13 | prev: | ||
14 | - title: Index of common titles | ||
15 | link: common-titles | ||
16 | ... | ||
17 | |||
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 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | outFile=src/first-lines.txt | 3 | outFile="$1"; |
4 | header="$2"; | ||
5 | shift 2; | ||
6 | glob="$@"; | ||
4 | 7 | ||
5 | echo "" > $outFile | 8 | firstLineOf() { # $1 = file |
9 | endOfYaml=$(sed -n '/^\.\.\.$/=' "$1") | ||
10 | tryLineNumber=$((endOfYaml + 1)) | ||
11 | try="" | ||
12 | while [[ -z $try ]]; do | ||
13 | try=$(head -n $tryLineNumber "$1" | tail -n 1 |\ | ||
14 | sed -e 's/^[|>] //' -e 's/[][]//g' -e 's/^#.*//' -e 's/^--.*//') | ||
15 | (( tryLineNumber += 1 )) | ||
16 | done | ||
17 | echo "$try" | ||
18 | } | ||
6 | 19 | ||
7 | for file in src/*.txt; do | 20 | echo -n "Compiling ${outFile}..." |
8 | echo -n "Getting first line of $file .. " | 21 | cat "$header" > $outFile |
9 | endOfYAML=$(sed -n '/^\.\.\.$/=' "$file") | ||
10 | firstLineNumber=$((endOfYAML + 2)) | ||
11 | 22 | ||
12 | echo "$file: " >> $outFile | 23 | for file in $glob; do |
13 | echo " $(head -n $firstLineNumber "$file" | tail -n 1)" >> $outFile | 24 | # Copy first line to $outFile & link |
14 | 25 | echo "[$(firstLineOf "$file")](${file%.*}.html)" >> $outFile | |
15 | unset endOfYAML firstLineNumber | ||
16 | echo "Done." | ||
17 | done | 26 | done |
27 | echo "Done." | ||