Skip to content

Commit

Permalink
init logic and releaseit conf
Browse files Browse the repository at this point in the history
  • Loading branch information
hrenaud (NovaGaïa) committed Sep 19, 2022
1 parent bc8d5e4 commit 9076e9a
Show file tree
Hide file tree
Showing 6 changed files with 7,684 additions and 6 deletions.
Empty file added .release-it.json
Empty file.
38 changes: 38 additions & 0 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,41 @@
* See: https://www.gatsbyjs.com/docs/browser-apis/
*/
// You can delete this file if you're not using it
import {
clearItemsInLS,
readItemInLS,
removeItemInLS,
setItemInLS,
} from './src/utils/ls'

function load_js(element, consent = false) {
const { key, scriptToInclude, mandatory } = element
if (consent || mandatory) {
const head = document.getElementsByTagName('head')[0]
const script = document.createElement('script')
script.key = key
script.src = scriptToInclude
head.appendChild(script)
}
removeItemInLS(key, mandatory) // <-- Pas ici
setItemInLS(key, consent, mandatory) // <-- Pas ici
}

function doThings(src, pluginOptions) {
console.log(`rgpd-acceptance launched by ${src}`, pluginOptions)
localStorage.setItem('rgpd-acceptance_accept-date', new Date())
pluginOptions.list.forEach(element => {
load_js(element, true)
})
}

export const onRouteUpdate = ({ location }, pluginOptions = {}) => {
doThings(`onRouteUpdate`, pluginOptions)

return null
}

export function onInitialClientRender(_, pluginOptions) {
// clearItemsInLS() // <-- Pas ici
doThings(`onRouteUpdate`, pluginOptions)
}
40 changes: 40 additions & 0 deletions gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,43 @@
* See: https://www.gatsbyjs.com/docs/ssr-apis/
*/
// You can delete this file if you're not using it

import React from 'react'

function buildInformationMessage() {
return (
<script
key="ecoindex_message"
dangerouslySetInnerHTML={{
__html: `
console.log("La RGPD, c'est quoi ? https://www.economie.gouv.fr/entreprises/reglement-general-sur-protection-des-donnees-rgpd")
`,
}}
/>
)
}

export const onRenderBody = ({
setBodyAttributes,
setPostBodyComponents,
setHeadComponents,
}) => {
// const preconnectEcoIndex =
// ((
// <link
// rel="preconnect"
// key="preconnect-ecoindex"
// href="https://cdn.jsdelivr.net/gh/simonvdfr/ecoindex-light-js@main/ecoindex.min.js"
// />
// ),
// (
// <link
// rel="dns-prefetch"
// key="dns-prefetch-ecoindex"
// href="https://cdn.jsdelivr.net/gh/simonvdfr/ecoindex-light-js@main/ecoindex.min.js"
// />
// ))
// setHeadComponents([preconnectEcoIndex])
// setBodyAttributes({ style: { position: 'relative' } })
setPostBodyComponents([buildInformationMessage()])
}
Loading

0 comments on commit 9076e9a

Please sign in to comment.