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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 in $SITE_DIR ..."
  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. meta=$(wget -qO - https://registry.npmjs.org/after-dark/latest)
  30. vers=$(echo "$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://domain.example/" # 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 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. create_archetypes () {
  77. echo "Establishing archetypes for new content ..."
  78. rm -f archetypes/default.md
  79. cp themes/after-dark/archetypes/*.md archetypes
  80. }
  81. create_example_post () {
  82. echo "Creating an example post to get you started ..."
  83. hugo new post/welcome.md --kind help 1>/dev/null
  84. }
  85. serve_site_locally () {
  86. echo "Serving your content locally ..."
  87. hugo serve --buildExpired --port 1313 --bind "0.0.0.0" 1>/dev/null &
  88. }
  89. echo "Welcome to the After Dark quick installer. Press CTRL-C at any time to abort."
  90. validate_hugo
  91. create_site_dir "$1"
  92. create_site
  93. download_theme
  94. create_archetypes
  95. download_module "fractal-forest"
  96. configure_theme
  97. create_example_post
  98. serve_site_locally
  99. echo "Installation completed successfully!"
  100. echo "Site created in $SITE_DIR_ABS"
  101. echo "Navigate to http://0.0.0.0:1313/ to view it now."
  102. echo "Run 'kill $(ps aux | awk '/[h]ugo.*1313/ {print $2}')' to stop it."
  103. echo "Run 'cd $SITE_DIR && hugo serve --buildDrafts' to start it again."
  104. echo "Run 'hugo serve --buildExpired' to view the online help."
  105. echo "Thank you for choosing After Dark."