From d832dace648047cdeee32f295b7f1c799d0b5b50 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 2 Apr 2015 21:27:55 -0700 Subject: Add Islands for backlinkless files --- trunk/backlink.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'trunk/backlink.sh') 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 @@ searchQuery="$1"; # .html file to backlink outFile="$2"; # .back file to create headerFile="$3"; # header information file -shift 3; +islandHead="$4"; +shift 4; glob="$@"; # where to search for backlinks +islandLink="island" +[[ ! -f ${islandLink}.txt ]] && cat "$islandHead" > ${islandLink}.txt; + # Find backlinkers echo -n "Back-linking \"$searchQuery\"" cat "$headerFile" > "$outFile"; -grep -ql "$searchQuery" $glob >> "$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 of $outFile inText="`basename $searchQuery .html`.txt"; @@ -18,8 +26,11 @@ title=`grep '^title:' "$inText" | cut -d' ' -f2-`; sed -i "s/_TITLE_/$title/" "$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 +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"; -- cgit 1.4.1-21-gabe81