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.

74 lines
3.7 KiB

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