Test cky integration

This commit is contained in:
Mark Dumay
2024-09-20 06:30:19 +02:00
parent 195f0b192f
commit fe2e3ba5f4
6 changed files with 93 additions and 10 deletions

View File

@@ -41,7 +41,7 @@
# toml-docs-start debugging
[debugging]
showJS = false
showJS = true
showSCSS = false
purgeHTMLComments = false
includeSVGOrigin = true

View File

@@ -0,0 +1,48 @@
/* eslint-disable no-undef, no-unused-vars */
let _manager
function loadScriptSync (src) {
const s = document.createElement('script')
s.src = src
s.type = 'text/javascript'
s.async = false
document.getElementsByTagName('head')[0].appendChild(s)
}
function hasConsent (category) {
if (typeof _manager !== 'undefined' && _manager !== null) {
return _manager.hasConsent(category)
} else {
console.log('no mgr defined: ' + category)
return false
}
}
function getLocalStorage (key, def, category) {
if (hasConsent(category)) {
return localStorage.getItem(key)
} else {
return def
}
}
function setLocalStorage (key, val, category) {
if (hasConsent(category)) {
localStorage.setItem(key, val)
}
}
function getSessionStorage (key, def, category) {
if (hasConsent(category)) {
return sessionStorage.getItem(key)
} else {
return def
}
}
function setSessionStorage (key, val, category) {
if (hasConsent(category)) {
sessionStorage.setItem(key, val)
}
}

View File

@@ -0,0 +1,35 @@
// TODO: move to module
/* eslint-disable no-undef, no-unused-vars */
{{- if or site.Params.modules.cookieyes.force (not hugo.IsServer) -}}
{{ with site.Params.modules.cookieyes.id }}
class CookieYesManager {
#consent
updateConsent () {
this.#consent = getCkyConsent()
}
constructor () {
loadScriptSync('https://cdn-cookieyes.com/client_data/{{ (. | urlize) }}/script.js')
this.updateConsent()
}
hasConsent (category) {
if (typeof this.#consent !== 'undefined' && this.#consent !== null) {
console.log('invoke cky consent: ' + category + this.#consent)
return true
} else {
console.log('cky consent undefined: ' + category)
return false
}
}
}
_manager = new CookieYesManager()
{{ else }}
{{ warnf "Cannot find CookieYes ID, check 'params.modules.cookieyes.id'" }}
{{ end }}
{{ end }}

View File

@@ -15,7 +15,7 @@
transpiler = "dartsass"
[debugging]
showJS = false
showJS = true
showSCSS = false
purgeHTMLComments = true # prevents a Goldmark warning when processing HTML comments (as used by markdownlint)
includeSVGOrigin = true

View File

@@ -7,15 +7,15 @@ for = '/**'
X-XSS-Protection = "1; mode=block"
Content-Security-Policy = """\
default-src 'self'; \
script-src 'self' https://*.google-analytics.com https://*.googletagmanager.com; \
style-src 'self' https://fonts.googleapis.com https://www.youtube.com; \
script-src 'self' cdn-cookieyes.com https://*.google-analytics.com https://*.googletagmanager.com; \
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://www.youtube.com; \
object-src 'none'; \
base-uri 'self'; \
connect-src 'self'
connect-src 'self' *.cookieyes.com cdn-cookieyes.com \
https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com; \
font-src 'self' https://fonts.gstatic.com; \
frame-src 'self' https://player.cloudinary.com https://player.vimeo.com https://www.youtube-nocookie.com https://www.youtube.com; \
img-src 'self' data: https://*.imgix.net https://*.imagekit.io https://*.cloudinary.com https://i.vimeocdn.com https://i.ytimg.com https://*.google-analytics.com https://*.googletagmanager.com https://tile.openstreetmap.org; \
img-src 'self' data: cdn-cookieyes.com https://*.imgix.net https://*.imagekit.io https://*.cloudinary.com https://i.vimeocdn.com https://i.ytimg.com https://*.google-analytics.com https://*.googletagmanager.com https://tile.openstreetmap.org; \
manifest-src 'self'; \
media-src 'self' \
"""

View File

@@ -21,19 +21,19 @@
Content-Security-Policy = """\
default-src 'self'; \
child-src 'self' app.netlify.com; \
script-src 'self' \
script-src 'self' cdn-cookieyes.com \
https://*.netlify.app app.netlify.com netlify-cdp-loader.netlify.app \
https://*.google-analytics.com https://*.googletagmanager.com; \
style-src 'self' \
style-src 'self' 'unsafe-inline' \
https://*.netlify.app https://fonts.googleapis.com https://www.youtube.com; \
object-src 'none'; \
base-uri 'self'; \
connect-src 'self'
connect-src 'self' *.cookieyes.com cdn-cookieyes.com \
https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com; \
font-src 'self' https://*.netlify.app https://fonts.gstatic.com; \
frame-src 'self' https://player.cloudinary.com https://player.vimeo.com https://www.youtube-nocookie.com https://www.youtube.com \
app.netlify.com; \
img-src 'self' data: https://*.imgix.net https://*.imagekit.io https://*.cloudinary.com https://*.netlify.app https://i.vimeocdn.com https://i.ytimg.com https://*.google-analytics.com https://*.googletagmanager.com https://tile.openstreetmap.org; \
img-src 'self' data: cdn-cookieyes.com https://*.imgix.net https://*.imagekit.io https://*.cloudinary.com https://*.netlify.app https://i.vimeocdn.com https://i.ytimg.com https://*.google-analytics.com https://*.googletagmanager.com https://tile.openstreetmap.org; \
manifest-src 'self'; \
media-src 'self' \
"""