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.

70 lines
3.5 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/server/static/"
  39. mkdir -p "${static_dir}offline/"
  40. # root replace directories
  41. app_dir="app/server/templates"
  42. frontend_dir="frontend"
  43. for ((i = 0; i < $(expr "${#links[@]}" / "$n_columns"); ++i)); do
  44. idx_local=$(expr $i \* $n_columns + 0)
  45. idx_link=$(expr $i \* $n_columns + 1)
  46. local="${links[$idx_local]}"
  47. link="${links[$idx_link]}"
  48. echo "Storing file to $local: $link"
  49. wget --content-on-error -q --show-progress -O "${static_dir}${local}" $link 2>/dev/null
  50. if [ $? -eq 0 ]; then
  51. # For Django: Use 'static' for template, use ^ as delimiter for sed
  52. find $app_dir -type f -exec sed -i "s^${link}^{% static \'${local}\' %}^g" {} \;
  53. # For Vue: Use // for same host, use ^ as delimiter for sed
  54. find $frontend_dir -type f -exec sed -i "s^${link}^//static/${local}^g" {} \;
  55. else
  56. echo "Failed to transform for offline use: $link"
  57. fi
  58. done