From e7ac28b826cfb750825e409826c1a36085ad48cc Mon Sep 17 00:00:00 2001 From: alexisben <alex@noesya.coop> Date: Tue, 26 Sep 2023 17:28:15 +0200 Subject: [PATCH] merge csp --- assets/js/theme/design-system/search.js | 24 +++++++++++++++++------- layouts/partials/head/csp.html | 12 +++++------- layouts/partials/header/search.html | 1 + package.json | 4 +--- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/assets/js/theme/design-system/search.js b/assets/js/theme/design-system/search.js index a7c674f1..1b4d3d06 100644 --- a/assets/js/theme/design-system/search.js +++ b/assets/js/theme/design-system/search.js @@ -1,3 +1,11 @@ +// const pagefind = await import("/pagefind/pagefind.js"); +// await pagefind.options({ +// baseUrl: "/", +// // ... more search options +// }); + +// console.log(pagefind) + class Search { constructor(button, pageFind) { this.button = button; @@ -5,7 +13,6 @@ class Search { this.closeButton = this.element.querySelector('.search__close'); this.searchInstance = pageFind; - if (!this.element) { return; } @@ -82,17 +89,20 @@ class Search { } // Selectors -window.addEventListener('DOMContentLoaded', (event) => { +window.addEventListener('DOMContentLoaded', () => { const pageFindSearch = document.querySelector("#search"); - + + if (typeof PagefindUI == "undefined") return; + if (pageFindSearch) { - let pageFind = new PagefindUI({ element: pageFindSearch, showSubResults: true }); + let pageFind = new PagefindUI({ + element: pageFindSearch, + showSubResults: true + }); (function () { const searchButton = document.querySelector(".pagefind-ui__toggle"); new Search(searchButton, pageFind); })(); - } - else { - return; } + }); diff --git a/layouts/partials/head/csp.html b/layouts/partials/head/csp.html index ac8482b0..de1b2d94 100644 --- a/layouts/partials/head/csp.html +++ b/layouts/partials/head/csp.html @@ -1,10 +1,8 @@ {{- with site.Data.website.external_domains -}} -<meta http-equiv="-Content-Security-Policy" +<meta http-equiv="Content-Security-Policy" content=" - default-src 'self' {{ delimit . " " }} {{ if not hugo.IsProduction }}'unsafe-inline'{{ end }}; - {{ if site.Params.search.active }} - script-src 'unsafe-eval'; - img-src * 'self' data: https:; - {{ end }} + default-src 'self' {{ delimit . " " }} + {{ if not hugo.IsProduction }}'unsafe-inline'{{ end }} + {{ if site.Params.search.active }}'wasm-unsafe-eval'{{ end }}; " /> -{{- end -}} \ No newline at end of file +{{- end -}} diff --git a/layouts/partials/header/search.html b/layouts/partials/header/search.html index d9fbe756..067d5176 100644 --- a/layouts/partials/header/search.html +++ b/layouts/partials/header/search.html @@ -3,6 +3,7 @@ </button> <script src="/pagefind/pagefind-ui.js"></script> + <div id="search" class="search__modal" aria-hidden="true" aria-modal="true" role="dialog"> <button class="search__close" aria-label="{{ i18n "commons.search.close" }}"> {{ i18n "commons.search.close" }} diff --git a/package.json b/package.json index 79b8a0a4..66b60b9b 100644 --- a/package.json +++ b/package.json @@ -8,14 +8,12 @@ "arnaudlevy <arnaud.levy@noesya.coop>" ], "license": "MIT", - "devDependencies": { - "shelljs": "^0.8.5" - }, "dependencies": { "@splidejs/splide": "^3.6.12", "glightbox": "^3.1.0", "intersection-observer": "^0.12.0", "leaflet": "^1.9.4", + "shelljs": "^0.8.5", "pagefind": "^1.0.3" }, "bin": "./bin/osuny.js" -- GitLab