You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.2 KiB

  1. # -*- mode: shell-script -*-
  2. HUGO_CONFIG="/etc/hugo"
  3. HUGO_BASE="/opt/apps/hugo"
  4. HUGO_SOURCE="$HUGO_BASE/src"
  5. HUGO_OUTPUT="$HUGO_BASE/output"
  6. HUGO_THEME="$HUGO_BASE/theme"
  7. HOST_HUGO_SOURCE="$SERVICE_DATASTORE$HUGO_BASE/src"
  8. HOST_HUGO_OUTPUT="$SERVICE_DATASTORE$HUGO_BASE/output"
  9. HOST_HUGO_THEME="$SERVICE_DATASTORE$HUGO_BASE/theme"
  10. HOST_HUGO_CONFIG="$SERVICE_CONFIGSTORE$HUGO_CONFIG"
  11. HUGO_BUILDER_DEFAULT_IMAGE="docker.0k.io/hugo:0.88.1"
  12. hugo:init-dir() {
  13. mkdir -p "$HOST_HUGO_SOURCE" || return 1
  14. cd "$HOST_HUGO_SOURCE" &&
  15. git config --global user.email "compose@mail.com" &&
  16. git config --global user.name "compose" &&
  17. docker run --rm -v "$HOST_HUGO_SOURCE":"$HUGO_SOURCE" \
  18. -w "$HUGO_SOURCE" "$HUGO_BUILDER_DEFAULT_IMAGE" \
  19. new site -f yaml . &&
  20. docker run --rm -v "$HOST_HUGO_SOURCE":"$HUGO_SOURCE" \
  21. -w "$HUGO_SOURCE" "$HUGO_BUILDER_DEFAULT_IMAGE" \
  22. new posts/my-first-post.md &&
  23. sed -ri '/^baseURL:/d' config.yaml &&
  24. git init &&
  25. git add -A . &&
  26. git commit -m "First import"
  27. }
  28. hugo:generate() {
  29. local src="$1" dst="$2" configs c
  30. theme_url=$(options-get theme-url 2>/dev/null) || true
  31. theme_url=${theme_url:-https://github.com/theNewDynamic/gohugo-theme-ananke.git}
  32. if ! [ -d "$HOST_HUGO_THEME/default" ]; then
  33. mkdir -p "$HOST_HUGO_THEME"
  34. git clone "${theme_url}" "$HOST_HUGO_THEME/default" || {
  35. err "Could not clone theme '$HOST_HUGO_THEME'."
  36. return 1
  37. }
  38. fi
  39. echo "theme: default" > "$HOST_HUGO_CONFIG/80-theme.yaml"
  40. config_files=("$HOST_HUGO_CONFIG/"*.yaml)
  41. configs=""
  42. for c in "${config_files[@]}"; do
  43. configs+="config${c#$SERVICE_CONFIGSTORE$HUGO_CONFIG},"
  44. done
  45. mkdir -p "$dst" || return 1
  46. docker run --rm -v "$src":"$HUGO_SOURCE" \
  47. -v "$dst":"$HUGO_OUTPUT" \
  48. -v "$HOST_HUGO_CONFIG":"$HUGO_CONFIG" \
  49. -v "$HOST_HUGO_THEME":"$HUGO_SOURCE/themes" \
  50. -v "$HOST_HUGO_CONFIG":"$HUGO_SOURCE/config" \
  51. -w "$HUGO_SOURCE" "$HUGO_BUILDER_DEFAULT_IMAGE" \
  52. -D --config "${configs}config.yaml" \
  53. -d "${dst#$SERVICE_DATASTORE}" &&
  54. find "$HOST_HUGO_SOURCE" -depth -type d -empty -delete
  55. }