summary refs log tree commit diff stats
path: root/trunk/backlink.sh
blob: f6feb7dead7202c6e9f72fef264413da06acc179 (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
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash

# Command-line variables
searchQuery="$1";               # .html file to backlink
outFile="$2";                   # .back file to create
headerFile="$3";                # header information file
shift 3;
glob="$@";                      # where to search for backlinks

# Find backlinkers
echo -n "Back-linking \"$searchQuery\""
cat "$headerFile" > "$outFile";
if ! grep -ql "$searchQuery" $glob >> "$outFile"; then
    echo "[_island_](${islandLink}.htm)." >> "$outFile";
    title=`grep '^title:' "${searchQuery%.html}.txt" | cut -d' ' -f2-`;
    echo "- [$title]($searchQuery)" >> "${islandLink}.txt"
fi

# Change title & id of $outFile
inText="`basename $searchQuery .html`.txt";
title=`grep '^title:' "$inText" | cut -d' ' -f2-`;
id=`grep '^id:' "${searchQuery%.html}.txt" | cut -d' ' -f2`;
sed -i "s/_TITLE_/$title/" "$outFile";
sed -i "s/_ID_/$id/" "$outFile";
echo -n "."

# Change *.txt to *.html
sed -i 's/^\(.*\)\.txt/\1.html/g' "$outFile";

# Link to backlinks
for file in `grep '.html$' "$outFile"`; do
    fText="`basename $file .html`.txt";
    title=`grep '^title:' $fText | cut -d' ' -f2-`;
    sed -i "s/^$file$/- [$title](&)/" "$outFile";
    echo -n "."
done

echo "Done."