about summary refs log tree commit diff stats
path: root/trunk/backlink.sh
blob: 7d143a8e59b304524a2ba3bbeca0a6849e869d68 (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
#!/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";
grep -ql "$searchQuery" $glob >> "$outFile";

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

# 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."