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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. tee "config.toml" > /dev/null <<TOML
  47. baseurl = "https://donate.habd.as" # Controls base URL sitewide
  48. languageCode = "en-US" # Controls site language
  49. title = "After Dark" # Homepage title and page title suffix
  50. paginate = 11 # Number of posts to show before paginating
  51. # Controls default theme and theme components
  52. theme = [
  53. "fractal-forest",
  54. "after-dark"
  55. ]
  56. enableRobotsTXT = true # Suggested, enable robots.txt file
  57. disqusShortname = "" # Deprecated, add Disqus shortname for comments
  58. pygmentsCodefences = true # Suggested, highlight fenced code blocks
  59. pygmentsUseClasses = true # Required for custom syntax highlighting
  60. sectionPagesMenu = "main" # Enable menu system for lazy bloggers
  61. footnoteReturnLinkContents = "↩" # Provides a nicer footnote return link
  62. [params]
  63. description = "" # Suggested, controls default description meta
  64. author = "" # Optional, controls author name display on posts
  65. hide_author = true # Optional, set true to hide author name on posts
  66. show_menu = false # Optional, set true to enable section menu
  67. powered_by = true # Optional, set false to disable footer credits
  68. images = [
  69. "https://source.unsplash.com/collection/983219/2000x1322"
  70. ] # Suggested, controls default Open Graph images
  71. [params.modules.fractal_forest]
  72. enabled = true # Optional, set false to disable module
  73. decoders = ["bpgdec8a"] # Optional, 8-bit javascript decoder with animation
  74. TOML
  75. }
  76. update_archetypes () {
  77. echo "Updating site default content archetype ..."
  78. rm -f archetypes/default.md
  79. cp themes/after-dark/archetypes/default.md archetypes
  80. }
  81. generate_help_docs () {
  82. echo "Generating help documentation ..."
  83. meta_path=themes/after-dark/data/npm
  84. mkdir -p "$meta_path" && echo "$THEME_META" | tr '\r\n' ' ' > "$meta_path"/latest.json
  85. hugo new help/index.md --kind help 1>/dev/null
  86. }
  87. serve_help_docs () {
  88. echo "Starting help server ..."
  89. sleep 1
  90. hugo serve --buildExpired --disableLiveReload --port 1414 1>/dev/null &
  91. }
  92. echo "Welcome to the After Dark quick installer. Press CTRL-C at any time to abort."
  93. validate_hugo
  94. create_site_dir "$1"
  95. create_site
  96. download_theme
  97. update_archetypes
  98. download_module "fractal-forest"
  99. configure_theme
  100. generate_help_docs
  101. serve_help_docs
  102. YELLOW='\033[0;33m'
  103. NC='\033[0m'
  104. echo "Installation successful!"
  105. echo "Site created in $SITE_DIR_ABS"
  106. echo "Help server started at http://localhost:1414/"
  107. echo "To stop it run \"kill \$(ps aux | awk '/[h]ugo.*1414/ {print \$2}')\"."
  108. echo "To update and start it again run \"./themes/after-dark/bin/help\"."
  109. printf "${YELLOW}Run \"cd $SITE_DIR && hugo serve\" to start your site.${NC}\n"
  110. echo "Thank you for choosing After Dark."