#!/bin/bash
# take entry id, and give back related articles
NB_EntryID="$1"
NB_EntryID=${NB_EntryID:1}
CAT=$(grep -l $NB_EntryID /home/miekg/miek.nl/blog/data/cat_*.db)
# Get the last 3 articles and print those
j=0
for i in $CAT; do
for art in $(tail -3 $i); do
if [ "$art" != "$NB_EntryID" ]; then
[ ! -r /home/miekg/miek.nl/blog/data/$art ] && continue
title="$(head -1 /home/miekg/miek.nl/blog/data/$art | sed -re 's/^TITLE: //')"
# normalize title, copied from comment.php
t=${title// /_}
t=$(echo $t | tr '[:upper:]' '[:lower:]')
t=$(echo $t | sed -re "s/\.+/_/g") # kill .
# t=${t//./_} # kill .
t=${t//\+/_} # kill +
t=${t//\//} # kill slashes
t=${t//} # kill <
t=${t//\(/} # kill (
t=${t//>/} # kill >
t=${t//\)/} # kill )
# kill quotes
t=$(echo $t | sed -re "s/'(.*)'/\1__/") # kill quotes
date=${art:0:10}
date=${date//-//}
link[$j]="$title"
((j++))
fi
done
break
done
if [[ $j -ne 0 ]]; then
# we have at least one
echo "
Related: "
fi
k=0; ((j--))
while [[ $k -lt $j ]]; do
echo ${link[$k]}","
((k++))
done
if [[ -n ${link[$k]} ]]; then
echo ${link[$k]}
fi