Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

149 lines
4.8KB

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