swx_rss 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/sh
  2. # Generate a rss feed from a file containing new pages
  3. # usage : swx_rss SRCDIR > feed.xml
  4. # Load config file
  5. if [ ! -f $PWD/swx.conf ]; then
  6. echo "Cannot find swx.conf in current directory"
  7. exit 1
  8. fi
  9. . $PWD/swx.conf
  10. if [ ! -f "$LOG" ]; then
  11. echo "Can't find the News file"
  12. exit 1
  13. fi
  14. WORKTMP=$(mktemp)
  15. # keep MAX news
  16. uniq -u "$LOG" | tail -n $MAX > "$WORKTMP"
  17. mv "$WORKTMP" "$LOG"
  18. # new entry first
  19. tail -r "$LOG" | sed -e "s;$1;;g" > $WORKTMP
  20. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  21. echo "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">"
  22. echo "<channel>"
  23. echo " <title>$TITLE</title>"
  24. echo " <description><![CDATA[$SUBTITLE]]></description>"
  25. echo " <language>fr</language>"
  26. while read line
  27. do
  28. #LINK="/$(echo $PATH | cut -d'/' -f2- | sed -e "s,$EXT$,.html,g")"
  29. #echo $PATH
  30. echo " <item>"
  31. NEWTITLE="$(basename $line | sed -e "s,$EXT$,,g")"
  32. if [ "$NEWTITLE" = "index" ]; then
  33. NEWTITLE="$(basename $(dirname $line))"
  34. fi
  35. echo " <title>$NEWTITLE</title>"
  36. echo " <link>/$(echo $line | cut -d'/' -f2- | sed -e "s,$EXT$,.html,g")</link>"
  37. echo " <guid>/$(echo $line | cut -d'/' -f2- | sed -e "s,$EXT$,.html,g")</guid>"
  38. DATE=$(ls -l "$1/$line" | awk '{print $6"-"$7"-"$8}')
  39. echo " <pubdate>$DATE</pubdate>"
  40. echo " <description><![CDATA[$($CONVERTER $1/$line | sed 's/\\/\\\\/g')]]></description>"
  41. # uncomment for plaint text description
  42. #echo " <description><![CDATA[$(sed 's/\\/\\\\/g' $line)]]></description>"
  43. echo "\n </item>"
  44. done < $WORKTMP
  45. rm $WORKTMP
  46. echo "</channel>"
  47. echo "</rss>"