build-home-page 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env bash
  2. set -e
  3. set -u
  4. set -o pipefail
  5. # -*- Mode: shell -*-
  6. get-date() {
  7. # sed -n '/#+DATE/p' ${file} | sed -n -e 's/<//p' | sed -n -e 's/>//p' | awk -F ': ' '{ printf $2 }'
  8. echo `sed -n -e 's/#+DATE://p' $1 \
  9. | sed -n -e 's/<//p' | sed -n -e 's/>//p'`
  10. }
  11. get-desc() {
  12. echo `sed -n -e 's/#+DESCRIPTION://p' $1`
  13. }
  14. get-keyw() {
  15. echo `sed -n -e 's/#+KEYWORDS://p' $1`
  16. }
  17. get-link() {
  18. echo '.'${1:4}
  19. }
  20. get-titl() {
  21. echo `sed -n -e 's/#+TITLE://p' $1`
  22. }
  23. get-entry() {
  24. local file=$1
  25. #NOTE: I don't think I want the keywords right now.
  26. # `get-keyw $file`'\n'\
  27. echo -e '* '`get-date $file` - `get-titl $file`'\n'\
  28. '[[file:'`get-link $file`']['`get-desc $file`'...]]\n'
  29. }
  30. error-exit() {
  31. echo "Missing: "$1
  32. exit 1
  33. }
  34. build-home-page_main() {
  35. local homePage1=template/home-page-1.org
  36. local headlines=headlines.org
  37. local homePage2=template/home-page-2.org
  38. local outfile=site/index.org
  39. if [ -f "$homePage1" ]; then
  40. echo "$(cat $homePage1)" > $outfile
  41. echo '' >> $outfile
  42. else
  43. error-exit $homePage1
  44. fi
  45. if [ -f "$headlines" ]; then
  46. echo "$(cat $headlines)" >> $outfile
  47. echo '' >> $outfile
  48. else
  49. error-exit $headlines
  50. fi
  51. local array=(\
  52. ` grep -irn '#+Date' site/archive/ \
  53. | awk -F ':' '{print $4":"$5"|"$1}' \
  54. | sort -r \
  55. | head -n 5 \
  56. | awk -F '|' '{print $2}'`)
  57. for file in "${array[@]}"
  58. do
  59. echo -e "`get-entry $file`" >> $outfile
  60. echo '' >> $outfile
  61. done
  62. if [ -f "$homePage2" ]; then
  63. echo "$(cat $homePage2)" >> $outfile
  64. else
  65. error-exit $homePage2
  66. fi
  67. }
  68. build-home-page_main $@