From efc660b0ac7f629da17ec567d8e63436a2fe0472 Mon Sep 17 00:00:00 2001 From: Edward Betts <edward@4angle.com> Date: Sat, 30 Mar 2024 10:18:21 +0000 Subject: [PATCH] Avoid CDN for frontend CSS and Javascript Closes: #137 --- package.json | 27 +++++++++++++++++++++++++++ templates/base.html | 12 ++---------- templates/index.html | 6 +++--- templates/trip_list.html | 10 +++------- templates/trip_page.html | 11 +++-------- webpack.config.js | 18 ++++++++++++++++++ 6 files changed, 56 insertions(+), 28 deletions(-) create mode 100644 package.json create mode 100644 webpack.config.js diff --git a/package.json b/package.json new file mode 100644 index 0000000..082b994 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "agenda", + "version": "1.0.0", + "directories": { + "test": "tests" + }, + "repository": { + "type": "git", + "url": "https://git.4angle.com/edward/agenda.git" + }, + "license": "ISC", + "devDependencies": { + "copy-webpack-plugin": "^12.0.2", + "webpack": "^5.91.0", + "webpack-cli": "^5.1.4" + }, + "dependencies": { + "@fullcalendar/core": "^6.1.11", + "@fullcalendar/daygrid": "^6.1.11", + "@fullcalendar/list": "^6.1.11", + "@fullcalendar/timegrid": "^6.1.11", + "bootstrap": "^5.3.3", + "es-module-shims": "^1.8.3", + "leaflet": "^1.9.4", + "leaflet.geodesic": "^2.7.1" + } +} diff --git a/templates/base.html b/templates/base.html index 08ccfb7..c89cf90 100644 --- a/templates/base.html +++ b/templates/base.html @@ -7,11 +7,7 @@ <title>{% block title %}{% endblock %}</title> <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>📅</text></svg>"> - {% if config.USE_CDN %} - <link href="https://unpkg.com/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> - {% else %} - <link href="{{ url_for("static", filename="bootstrap5/css/bootstrap.min.css") }}" rel="stylesheet"> - {% endif %} + <link href="{{ url_for("static", filename="bootstrap5/css/bootstrap.min.css") }}" rel="stylesheet"> {% block style %} {% endblock %} @@ -22,10 +18,6 @@ {% block nav %}{{ navbar() }}{% endblock %} {% block content %}{% endblock %} {% block scripts %}{% endblock %} - {% if config.USE_CDN %} - <script src="https://unpkg.com/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script> - {% else %} - <script src="{{ url_for("static", filename="bootstrap5/js/bootstrap.bundle.min.js") }}"></script> - {% endif %} + <script src="{{ url_for("static", filename="bootstrap5/js/bootstrap.bundle.min.js") }}"></script> </body> </html> diff --git a/templates/index.html b/templates/index.html index 4034a2f..720520a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,10 +4,10 @@ <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Agenda</title> - <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> + <link href="{{ url_for("static", filename="bootstrap5/css/bootstrap.min.css") }}" rel="stylesheet"> <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>📅</text></svg>"> - <script async src="https://unpkg.com/es-module-shims@1.8.2/dist/es-module-shims.js"></script> + <script async src="{{ url_for("static", filename="es-module-shims/es-module-shims.js") }}"></script> <script type='importmap'> { @@ -210,6 +210,6 @@ </div> </div> -<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script> + <script src="{{ url_for("static", filename="bootstrap5/js/bootstrap.bundle.min.js") }}"></script> </body> </html> diff --git a/templates/trip_list.html b/templates/trip_list.html index 22f2f56..83525ee 100644 --- a/templates/trip_list.html +++ b/templates/trip_list.html @@ -6,9 +6,7 @@ {% block style %} - <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" - integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" - crossorigin=""/> + <link rel="stylesheet" href="{{ url_for("static", filename="leaflet/leaflet.css") }}"> {% set conference_column_count = 7 %} {% set accommodation_column_count = 7 %} @@ -112,11 +110,9 @@ {% block scripts %} -<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" - integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" - crossorigin=""></script> +<script src="{{ url_for("static", filename="leaflet/leaflet.js") }}"></script> -<script src="https://unpkg.com/leaflet.geodesic@2.7.1/dist/leaflet.geodesic.umd.min.js"></script> +<script src="{{ url_for("static", filename="leaflet-geodesic/leaflet.geodesic.umd.min.js") }}"></script> <script src="{{ url_for("static", filename="js/map.js") }}"></script> <script> diff --git a/templates/trip_page.html b/templates/trip_page.html index 1743951..d76ac5a 100644 --- a/templates/trip_page.html +++ b/templates/trip_page.html @@ -20,9 +20,7 @@ {% block style %} {% if coordinates %} - <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" - integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" - crossorigin=""/> + <link rel="stylesheet" href="{{ url_for("static", filename="leaflet/leaflet.css") }}"> {% endif %} {% set conference_column_count = 7 %} @@ -260,11 +258,8 @@ {% block scripts %} -<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" - integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" - crossorigin=""></script> - -<script src="https://unpkg.com/leaflet.geodesic@2.7.1/dist/leaflet.geodesic.umd.min.js"></script> +<script src="{{ url_for("static", filename="leaflet/leaflet.js") }}"></script> +<script src="{{ url_for("static", filename="leaflet-geodesic/leaflet.geodesic.umd.min.js") }}"></script> <script src="{{ url_for("static", filename="js/map.js") }}"></script> diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..67d98db --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,18 @@ +const path = require('path'); +const CopyPlugin = require('copy-webpack-plugin'); + +module.exports = { + mode: 'development', + entry: './frontend/index.js', // Ensure this entry point exists and is valid. + plugins: [ + new CopyPlugin({ + patterns: [ + // Copy Bootstrap's CSS and JS from node_modules to your desired location + { from: 'node_modules/bootstrap/dist', to: path.resolve(__dirname, 'static/bootstrap5') }, + { from: 'node_modules/leaflet/dist', to: path.resolve(__dirname, 'static/leaflet') }, + { from: 'node_modules/leaflet.geodesic/dist', to: path.resolve(__dirname, 'static/leaflet-geodesic'), }, + { from: 'node_modules/es-module-shims/dist', to: path.resolve(__dirname, 'static/es-module-shims') } + ], + }), + ] +};