diff options
Diffstat (limited to 'trunk/backlink.sh')
-rw-r--r-- | trunk/backlink.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/trunk/backlink.sh b/trunk/backlink.sh new file mode 100644 index 0000000..7d143a8 --- /dev/null +++ b/trunk/backlink.sh | |||
@@ -0,0 +1,29 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | # Command-line variables | ||
4 | searchQuery="$1"; # .html file to backlink | ||
5 | outFile="$2"; # .back file to create | ||
6 | headerFile="$3"; # header information file | ||
7 | shift 3; | ||
8 | glob="$@"; # where to search for backlinks | ||
9 | |||
10 | # Find backlinkers | ||
11 | echo -n "Back-linking \"$searchQuery\"" | ||
12 | cat "$headerFile" > "$outFile"; | ||
13 | grep -ql "$searchQuery" $glob >> "$outFile"; | ||
14 | |||
15 | # Change title of $outFile | ||
16 | inText="`basename $searchQuery .html`.txt"; | ||
17 | title=`grep '^title:' "$inText" | cut -d' ' -f2-`; | ||
18 | sed -i "s/_TITLE_/$title/" "$outFile"; | ||
19 | echo -n "." | ||
20 | |||
21 | # Link to backlinks | ||
22 | for file in `grep '.html' "$outFile"`; do | ||
23 | fText="`basename $file .html`.txt"; | ||
24 | title=`grep '^title:' $fText | cut -d' ' -f2-`; | ||
25 | sed -i "s/^$file$/- [$title](&)/" "$outFile"; | ||
26 | echo -n "." | ||
27 | done | ||
28 | |||
29 | echo "Done." | ||