about summary refs log tree commit diff stats
path: root/trunk/first-lines.sh
blob: 1378a829dd45d9f78e128cf1dfe4cc6f64c2b23b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash

outFile="$1";
shift 1;
glob="$@";

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"
}

echo -n "Compiling ${outFile}"

for file in $glob; do
    # Copy first line to $outFile & link
    echo "[$(firstLineOf "$file")](${file%.*}.html)" >> $outFile;
    echo -n ".";
done
echo "Done."