diff options
Diffstat (limited to 'trunk/backlink.sh')
-rw-r--r-- | trunk/backlink.sh | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/trunk/backlink.sh b/trunk/backlink.sh index 7d143a8..15bb11e 100644 --- a/trunk/backlink.sh +++ b/trunk/backlink.sh | |||
@@ -4,13 +4,21 @@ | |||
4 | searchQuery="$1"; # .html file to backlink | 4 | searchQuery="$1"; # .html file to backlink |
5 | outFile="$2"; # .back file to create | 5 | outFile="$2"; # .back file to create |
6 | headerFile="$3"; # header information file | 6 | headerFile="$3"; # header information file |
7 | shift 3; | 7 | islandHead="$4"; |
8 | shift 4; | ||
8 | glob="$@"; # where to search for backlinks | 9 | glob="$@"; # where to search for backlinks |
9 | 10 | ||
11 | islandLink="island" | ||
12 | [[ ! -f ${islandLink}.txt ]] && cat "$islandHead" > ${islandLink}.txt; | ||
13 | |||
10 | # Find backlinkers | 14 | # Find backlinkers |
11 | echo -n "Back-linking \"$searchQuery\"" | 15 | echo -n "Back-linking \"$searchQuery\"" |
12 | cat "$headerFile" > "$outFile"; | 16 | cat "$headerFile" > "$outFile"; |
13 | grep -ql "$searchQuery" $glob >> "$outFile"; | 17 | if ! grep -ql "$searchQuery" $glob >> "$outFile"; then |
18 | echo "[_island_](${islandLink}.htm)." >> "$outFile"; | ||
19 | title=`grep '^title:' "${searchQuery%.html}.txt" | cut -d' ' -f2-`; | ||
20 | echo "- [$title]($searchQuery)" >> "${islandLink}.txt" | ||
21 | fi | ||
14 | 22 | ||
15 | # Change title of $outFile | 23 | # Change title of $outFile |
16 | inText="`basename $searchQuery .html`.txt"; | 24 | inText="`basename $searchQuery .html`.txt"; |
@@ -18,8 +26,11 @@ title=`grep '^title:' "$inText" | cut -d' ' -f2-`; | |||
18 | sed -i "s/_TITLE_/$title/" "$outFile"; | 26 | sed -i "s/_TITLE_/$title/" "$outFile"; |
19 | echo -n "." | 27 | echo -n "." |
20 | 28 | ||
29 | # Change *.txt to *.html | ||
30 | sed -i 's/^\(.*\)\.txt/\1.html/g' "$outFile"; | ||
31 | |||
21 | # Link to backlinks | 32 | # Link to backlinks |
22 | for file in `grep '.html' "$outFile"`; do | 33 | for file in `grep '.html$' "$outFile"`; do |
23 | fText="`basename $file .html`.txt"; | 34 | fText="`basename $file .html`.txt"; |
24 | title=`grep '^title:' $fText | cut -d' ' -f2-`; | 35 | title=`grep '^title:' $fText | cut -d' ' -f2-`; |
25 | sed -i "s/^$file$/- [$title](&)/" "$outFile"; | 36 | sed -i "s/^$file$/- [$title](&)/" "$outFile"; |