diff options
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." | ||