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 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2019 Josh Habdas <jhabdas@protonmail.com>
  4. #
  5. # This file is part of After Dark.
  6. #
  7. # After Dark is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published
  9. # by the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # After Dark is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. validate_hugo () {
  21. # Exit with error if hugo is not installed
  22. if ! hash hugo 2>/dev/null ; then
  23. echo "Error: After Dark requires Hugo version 0.51 or greater" >&2; exit 1
  24. fi
  25. # Exit with error if not minimum required hugo version
  26. re="v(0\d*\.([5-9][1-9]|[6-9])|[1-9]).*"
  27. if ! hugo version | grep -qE "$re" ; then
  28. echo "Error: After Dark requires Hugo version 0.51 or greater" >&2; exit 1
  29. fi
  30. }
  31. create_site_dir () {
  32. SITE_DIR="flying-toasters"
  33. if [ "$1" != "" ] ; then
  34. SITE_DIR="$1"
  35. fi
  36. SITE_DIR_ABS="$PWD/$SITE_DIR"
  37. mkdir -p "$SITE_DIR"
  38. }
  39. create_site () {
  40. echo "Creating a new Hugo site ..."
  41. hugo new site "$SITE_DIR" 1>/dev/null
  42. cd "$SITE_DIR" || exit 1
  43. }
  44. download_theme () {
  45. echo "Downloading the latest version of After Dark ..."
  46. LATEST_META=$(wget -qO - https://registry.npmjs.org/after-dark/latest)
  47. vers=$(echo "$LATEST_META" | grep -oE "\"version\".*[^,]*," | cut -d ',' -f1 | cut -d ':' -f2 | tr -d '" ')
  48. mkdir -p themes/after-dark
  49. wget -qO - https://registry.npmjs.org/after-dark/-/after-dark-"$vers".tgz | tar --strip-components=1 -xz -C themes/after-dark
  50. echo "Version $vers downloaded to $SITE_DIR/themes/after-dark"
  51. }
  52. download_module () {
  53. [ -z "$1" ] && { echo "Error: Attempt to download undefined module" >&2; exit 1; }
  54. echo "Downloading $1 module for After Dark ..."
  55. meta=$(wget -qO - https://registry.npmjs.org/"$1"/latest)
  56. vers=$(echo "$meta" | grep -oE "\"version\".*[^,]*," | cut -d ',' -f1 | cut -d ':' -f2 | tr -d '" ')
  57. mkdir -p themes/"$1"
  58. wget -qO - https://registry.npmjs.org/"$1"/-/"$1"-"$vers".tgz | tar --strip-components=1 -xz -C themes/"$1"
  59. echo "Version $vers downloaded to $SITE_DIR/themes/$1"
  60. }
  61. configure_theme () {
  62. echo "Configuring basic After Dark theme settings ..."
  63. tee "config.toml" > /dev/null <<TOML
  64. baseurl = "https://domain.example" # Controls base URL sitewide
  65. languageCode = "en-US" # Controls site language
  66. title = "After Dark" # Homepage title and page title suffix
  67. paginate = 11 # Number of posts to show before paginating
  68. copyright = "Copyright &copy; Copyright Owner. Licensed under <a target=\"_blank\" rel=\"external noopener license\" href=\"https://creativecommons.org/licenses/by-nd/4.0/\">CC-BY-ND-4.0</a>." # Optional, remove to suppress copyright notices
  69. # Controls default theme and theme components
  70. theme = [
  71. "fractal-forest", # OBSD
  72. "after-dark" # AGPL-3.0-or-later
  73. ]
  74. disableLiveReload = false # Optional, set true to disable live reload
  75. enableRobotsTXT = true # Suggested, enable robots.txt file
  76. pygmentsCodefences = true # Suggested, highlight fenced code blocks
  77. pygmentsUseClasses = true # Required for custom syntax highlighting
  78. sectionPagesMenu = "main" # Enable menu system for lazy bloggers
  79. footnoteReturnLinkContents = "↩" # Provides a nicer footnote return link
  80. [params]
  81. description = "" # Suggested, controls default description meta
  82. author = "" # Optional, controls author name display on posts
  83. hide_author = false # Optional, set true to hide author name on posts
  84. disable_csp = false # Optional, set true to disable content security policy
  85. images = [
  86. "https://source.unsplash.com/collection/983219/2000x1322"
  87. ] # Suggested, controls default Open Graph images
  88. [params.layout.menu.main]
  89. hidden = true # Optional, set false or remove to show section menu
  90. [params.layout.footer]
  91. hidden = false # Optional, set true to hide footer
  92. [params.modules.fractal_forest]
  93. enabled = true # Optional, set false to disable module
  94. decoders = ["bpgdec8a"] # Optional, 8-bit javascript decoder with animation
  95. TOML
  96. }
  97. update_archetypes () {
  98. echo "Updating the default content archetype ..."
  99. rm -f archetypes/default.md
  100. cp themes/after-dark/archetypes/default.md archetypes
  101. }
  102. create_welcome_post () {
  103. echo "Creating welcome post ..."
  104. hugo new post/welcome.md 1>/dev/null
  105. }
  106. serve_site () {
  107. echo "Starting site server ..."
  108. hugo serve --buildDrafts --navigateToChanged --port 1313 1>/dev/null &
  109. }
  110. generate_help_docs () {
  111. echo "Generating help documentation ..."
  112. THEME_PATH=themes/after-dark
  113. meta_path="$THEME_PATH"/data/npm
  114. mkdir -p "$meta_path" && echo "$LATEST_META" | tr '\r\n' ' ' > "$meta_path"/latest.json
  115. cd "$THEME_PATH"/docs && mkdir themes && ln -s ../.. "$THEME_PATH"
  116. hugo new validate.md --kind validate 1>/dev/null
  117. }
  118. serve_help () {
  119. echo "Starting help server ..."
  120. hugo serve --disableLiveReload --port 1414 1>/dev/null &
  121. }
  122. set -e
  123. echo "Welcome to the After Dark quick installer. Press CTRL-C at any time to abort."
  124. validate_hugo
  125. create_site_dir "$1"
  126. create_site
  127. download_theme
  128. update_archetypes
  129. download_module "fractal-forest"
  130. configure_theme
  131. create_welcome_post
  132. serve_site
  133. generate_help_docs
  134. serve_help
  135. YELLOW='\033[0;33m'
  136. NC='\033[0m'
  137. printf "${YELLOW}Installation successful!${NC}\n"
  138. echo "Site created in $SITE_DIR_ABS"
  139. echo "Site server started at http://localhost:1313/"
  140. echo "To stop it run \"kill \$(ps aux | awk '/[h]ugo.*1313/ {print \$2}')\"."
  141. echo "Help server started at http://localhost:1414/"
  142. echo "To stop and restart it run \"./themes/after-dark/bin/help\"."
  143. echo "Thank you for choosing After Dark."