build_home_page 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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=etc/pages/home-page-1.org
  36. local homePage2=etc/pages/home-page-2.org
  37. local headlines=headlines.org
  38. local outfile=src/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' src/archive/ \
  53. --exclude-dir=the-org-edda \
  54. --exclude-dir=family-business \
  55. | awk -F ':' '{print $4":"$5"|"$1}' \
  56. | sort -r \
  57. | head -n 5 \
  58. | awk -F '|' '{print $2}'`)
  59. for file in "${array[@]}"
  60. do
  61. echo -e "`get-entry $file`" >> $outfile
  62. echo '' >> $outfile
  63. done
  64. if [ -f "$homePage2" ]; then
  65. echo "$(cat $homePage2)" >> $outfile
  66. else
  67. error-exit $homePage2
  68. fi
  69. }
  70. build-home-page_main $@