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.

69 lines
3.5 KiB

  1. #!/usr/bin/env bash
  2. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  3. cd $DIR
  4. unset DIR
  5. # FOUND LINKS:
  6. # app/server/templates/admin.html
  7. # https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/vs2015.min.css
  8. # app/server/templates/base.html
  9. # https://use.fontawesome.com/releases/v5.0.13/css/all.css
  10. # https://fonts.googleapis.com/css?family=Open+Sans:300,400,700
  11. # https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css
  12. # https://cdn.jsdelivr.net/npm/bulma-extensions@4.0.1/bulma-divider/dist/css/bulma-divider.min.css
  13. # https://cdn.jsdelivr.net/npm/bulma-extensions@4.0.1/bulma-checkradio/dist/css/bulma-checkradio.min.css
  14. # https://cdn.jsdelivr.net/npm/bulma-extensions@4.0.1/bulma-tooltip/dist/css/bulma-tooltip.min.css
  15. # app/server/templates/index.html
  16. # https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.3/css/swiper.min.css
  17. # https://source.unsplash.com/RWnpyGtY1aU
  18. # https://source.unsplash.com/6Ticnhs1AG0
  19. # https://i.imgsafe.org/ba/baa924a5e3.png
  20. # frontend/nuxt.config.js
  21. # https://use.fontawesome.com/releases/v5.0.6/js/all.js
  22. # https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons
  23. n_columns="2"
  24. declare -a links=("offline/vs2015.min.css" "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/vs2015.min.css"
  25. "offline/all.css" "https://use.fontawesome.com/releases/v5.0.13/css/all.css"
  26. "offline/opensans.css" "https://fonts.googleapis.com/css?family=Open+Sans:300,400,700"
  27. "offline/bulma.min.css" "https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css"
  28. "offline/bulma-divider.min.css" "https://cdn.jsdelivr.net/npm/bulma-extensions@4.0.1/bulma-divider/dist/css/bulma-divider.min.css"
  29. "offline/bulma-checkradio.min.css" "https://cdn.jsdelivr.net/npm/bulma-extensions@4.0.1/bulma-checkradio/dist/css/bulma-checkradio.min.css"
  30. "offline/bulma-tooltip.min.css" "https://cdn.jsdelivr.net/npm/bulma-extensions@4.0.1/bulma-tooltip/dist/css/bulma-tooltip.min.css"
  31. "offline/photo-1.jpg" "https://source.unsplash.com/RWnpyGtY1aU"
  32. "offline/photo-2.jpg" "https://source.unsplash.com/6Ticnhs1AG0"
  33. "offline/photo-3.jpg" "https://i.imgsafe.org/ba/baa924a5e3.png"
  34. "offline/all.js" "https://use.fontawesome.com/releases/v5.0.6/js/all.js"
  35. "offline/google-roboto.css" "https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons"
  36. )
  37. static_dir="app/server/static/"
  38. mkdir -p "${static_dir}offline/"
  39. # root replace directories
  40. app_dir="app/server/templates"
  41. frontend_dir="frontend"
  42. for ((i = 0; i < "$(expr ${#links[@]} / $n_columns)"; ++i)); do
  43. idx_local=$(expr $i \* $n_columns + 0)
  44. idx_link=$(expr $i \* $n_columns + 1)
  45. local="${links[$idx_local]}"
  46. link="${links[$idx_link]}"
  47. echo "Storing file to $local: $link"
  48. wget --content-on-error -q --show-progress -O "${static_dir}${local}" $link 2>/dev/null
  49. if [ $? -eq 0 ]; then
  50. # For Django: Use 'static' for template, use ^ as delimiter for sed
  51. find $app_dir -type f -exec sed -i "s^${link}^{% static \'${local}\' %}^g" {} \;
  52. # For Vue: Use // for same host, use ^ as delimiter for sed
  53. find $frontend_dir -type f -exec sed -i "s^${link}^//static/${local}^g" {} \;
  54. else
  55. echo "Failed to transform for offline use: $link"
  56. fi
  57. done