swx_blog 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/sh
  2. # Generate a blog page with recent articles
  3. #
  4. # usage : swx_blog page.html
  5. # if ":::BLOG:::" is found in page.html, it will be replaced by recent articles
  6. # change it in swx.conf
  7. # Load config file
  8. if [ ! -f $PWD/swx.conf ]; then
  9. echo "Cannot find swx.conf in current directory"
  10. exit 1
  11. fi
  12. . $PWD/swx.conf
  13. if [ ! -f "$LOG" ]; then
  14. echo "Can't find the News file"
  15. exit 1
  16. fi
  17. if [ -z "$1" ]; then
  18. "usage : $0 page.html"
  19. exit 1
  20. fi
  21. WORKTMP=$(mktemp)
  22. # keep MAX news
  23. uniq -u "$LOG" | tail -n $MAX > "$WORKTMP"
  24. mv "$WORKTMP" "$LOG"
  25. # new entry first
  26. tac "$LOG" > $WORKTMP
  27. NEWS=""
  28. while read line; do
  29. NEWTITLE="$(basename $line | sed -e "s,$EXT$,,g")"
  30. if [ "$NEWTITLE" = "index" ]; then
  31. NEWTITLE="$(basename $(dirname $line))"
  32. fi
  33. URL="$(echo $line | cut -d'/' -f2- | sed -e "s,$EXT$,.html,g")"
  34. PUBDATE="$(stat -c %z "$line")"
  35. NEWS="\n$NEWS <div class='article'>\n"
  36. NEWS="$NEWS\n <a href="$URL">$NEWTITLE - $PUBDATE </a>"
  37. NEWS="$NEWS\n $($CONVERTER $line) "
  38. NEWS="$NEWS </div>"
  39. done < $WORKTMP
  40. echo "" > $WORKTMP
  41. while read line; do
  42. if [ "$line" != "$NEWSSTR" ]; then
  43. echo "$line" >> $WORKTMP
  44. else
  45. echo "$NEWS" >> $WORKTMP
  46. fi
  47. done < "$1"
  48. mv $WORKTMP "$1"
  49. exit 0