Hugo Dark Theme Site Generator https://after-dark.habd.as
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.

install 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/bin/sh
  2. set -e
  3. validate_hugo () {
  4. # Exit with error if hugo is not installed
  5. if ! hash hugo 2>/dev/null ; then
  6. echo "Error: After Dark requires Hugo version 0.44 or greater" >&2; exit 1
  7. fi
  8. # Exit with error if not minimum required hugo version
  9. re="v(0\d*\.([4-9][4-9]|[5-9])|[1-9]).*"
  10. if ! hugo version | grep -qE "$re" ; then
  11. echo "Error: After Dark requires Hugo version 0.44 or greater" >&2; exit 1
  12. fi
  13. }
  14. create_site_dir () {
  15. SITE_DIR="flying-toasters"
  16. if [ "$1" != "" ] ; then
  17. SITE_DIR="$1"
  18. fi
  19. SITE_DIR_ABS="$PWD/$SITE_DIR"
  20. mkdir -p "$SITE_DIR"
  21. }
  22. create_site () {
  23. echo "Creating a new Hugo site ..."
  24. hugo new site "$SITE_DIR" 1>/dev/null
  25. cd "$SITE_DIR" || exit 1
  26. }
  27. download_theme () {
  28. echo "Downloading the latest version of After Dark ..."
  29. THEME_META=$(wget -qO - https://registry.npmjs.org/after-dark/latest)
  30. vers=$(echo "$THEME_META" | egrep -o "\"version\".*[^,]*," | cut -d ',' -f1 | cut -d ':' -f2 | tr -d '" ')
  31. mkdir -p themes/after-dark
  32. wget -qO - https://registry.npmjs.org/after-dark/-/after-dark-"$vers".tgz | tar --strip-components=1 -xz -C themes/after-dark
  33. echo "Version $vers downloaded to $SITE_DIR/themes/after-dark"
  34. }
  35. download_module () {
  36. [ -z "$1" ] && { echo "Error: Attempt to download undefined module" >&2; exit 1; }
  37. echo "Downloading $1 module for After Dark ..."
  38. meta=$(wget -qO - https://registry.npmjs.org/"$1"/latest)
  39. vers=$(echo "$meta" | egrep -o "\"version\".*[^,]*," | cut -d ',' -f1 | cut -d ':' -f2 | tr -d '" ')
  40. mkdir -p themes/"$1"
  41. wget -qO - https://registry.npmjs.org/"$1"/-/"$1"-"$vers".tgz | tar --strip-components=1 -xz -C themes/"$1"
  42. echo "Version $vers downloaded to $SITE_DIR/themes/$1"
  43. }
  44. configure_theme () {
  45. echo "Configuring basic After Dark theme settings ..."
  46. mkdir data/theme && echo -E "$THEME_META" > data/theme/latest.json
  47. tee "config.toml" > /dev/null <<TOML
  48. baseurl = "https://domain.example/" # Controls base URL sitewide
  49. languageCode = "en-US" # Controls site language
  50. title = "After Dark" # Homepage title and page title suffix
  51. paginate = 11 # Number of posts to show before paginating
  52. # Controls default theme and theme components
  53. theme = [
  54. "fractal-forest",
  55. "after-dark"
  56. ]
  57. enableRobotsTXT = true # Suggested, enable robots.txt file
  58. disqusShortname = "" # Deprecated, add Disqus shortname for comments
  59. pygmentsCodefences = true # Suggested, highlight fenced code blocks
  60. pygmentsUseClasses = true # Required for custom syntax highlighting
  61. sectionPagesMenu = "main" # Enable menu system for lazy bloggers
  62. footnoteReturnLinkContents = "↩" # Provides a nicer footnote return link
  63. [params]
  64. description = "" # Suggested, controls default description meta
  65. author = "" # Optional, controls author name display on posts
  66. hide_author = true # Optional, set true to hide author name on posts
  67. show_menu = false # Optional, set true to enable section menu
  68. powered_by = true # Optional, set false to disable credits
  69. images = [
  70. "https://source.unsplash.com/collection/983219/2000x1322"
  71. ] # Suggested, controls default Open Graph images
  72. [params.modules.fractal_forest]
  73. enabled = true # Optional, set false to disable module
  74. decoders = ["bpgdec8a"] # Optional, 8-bit javascript decoder with animation
  75. TOML
  76. }
  77. update_archetypes () {
  78. echo "Updating site default content archetype ..."
  79. rm -f archetypes/default.md
  80. cp themes/after-dark/archetypes/default.md archetypes
  81. }
  82. generate_help_docs () {
  83. echo "Generating help documentation ..."
  84. mkdir data/theme && echo "$THEME_META" | tr '\r\n' ' ' > data/theme/latest.json
  85. hugo new help/index.md --kind help 1>/dev/null
  86. }
  87. serve_help_docs () {
  88. echo "Starting help server ..."
  89. hugo serve --buildExpired --disableLiveReload --port 1414 1>/dev/null &
  90. }
  91. echo "Welcome to the After Dark quick installer. Press CTRL-C at any time to abort."
  92. validate_hugo
  93. create_site_dir "$1"
  94. create_site
  95. download_theme
  96. update_archetypes
  97. download_module "fractal-forest"
  98. configure_theme
  99. generate_help_docs
  100. serve_help_docs
  101. YELLOW='\033[0;33m'
  102. NC='\033[0m'
  103. echo "Installation successful!"
  104. echo "Site created in $SITE_DIR_ABS"
  105. echo "Help server started at http://localhost:1414/"
  106. echo "To stop it run \"kill \$(ps aux | awk '/[h]ugo.*1414/ {print \$2}')\"."
  107. printf "${YELLOW}Run \"cd $SITE_DIR && hugo serve\" to start your site.${NC}\n"
  108. echo "To start help later run \"hugo serve --buildExpired\"."
  109. echo "Thank you for choosing After Dark."