File tree 3 files changed +74
-0
lines changed
3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change @@ -88,3 +88,6 @@ yarn-error.log
88
88
.devcontainer
89
89
90
90
src /images /infrastructure_screenshot_full_sonarqube-dashboard.webp
91
+
92
+ # Local Netlify folder
93
+ .netlify
Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ package = "@netlify/plugin-gatsby"
4
4
[functions ]
5
5
included_files = [" !.cache/data/datastore/data.mdb" ," !.cache/query-engine" ]
6
6
7
+ [[edge_functions ]]
8
+ path = " /*"
9
+ function = " osano-country"
10
+
7
11
[[headers ]]
8
12
for = " /*"
9
13
Original file line number Diff line number Diff line change
1
+ import { HTMLRewriter } from 'https://ghuc.cc/worker-tools/html-rewriter/index.ts' ;
2
+
3
+ export default async ( request , context ) => {
4
+ const response = await context . next ( ) ;
5
+ const hasGdpr = [
6
+ 'AT' ,
7
+ 'BE' ,
8
+ 'BG' ,
9
+ 'HR' ,
10
+ 'CY' ,
11
+ 'CZ' ,
12
+ 'DK' ,
13
+ 'EE' ,
14
+ 'FI' ,
15
+ 'FR' ,
16
+ 'DE' ,
17
+ 'GR' ,
18
+ 'HU' ,
19
+ 'IE' ,
20
+ 'IT' ,
21
+ 'LV' ,
22
+ 'LT' ,
23
+ 'LU' ,
24
+ 'MT' ,
25
+ 'NL' ,
26
+ 'PL' ,
27
+ 'PT' ,
28
+ 'RO' ,
29
+ 'SK' ,
30
+ 'SI' ,
31
+ 'ES' ,
32
+ 'SE' ,
33
+ ] . includes ( context . geo . country . code ) ;
34
+
35
+ if ( hasGdpr ) {
36
+ return (
37
+ new HTMLRewriter ( )
38
+ // .on('script', {
39
+ // text(text) {
40
+ // buffer += text.text;
41
+
42
+ // if (text.lastInTextNode) {
43
+ // text.replace(buffer.replace(/variant=one/gi, 'variant=two'));
44
+ // buffer = '';
45
+ // } else {
46
+ // text.remove();
47
+ // }
48
+ // },
49
+ // })
50
+ . on ( 'script' , {
51
+ element ( element ) {
52
+ const scriptSrc = element . getAttribute ( 'src' ) ;
53
+ if (
54
+ typeof scriptSrc === 'string' &&
55
+ scriptSrc . includes ( 'cmp.osano.com/' )
56
+ ) {
57
+ element . setAttribute (
58
+ 'src' ,
59
+ scriptSrc . replace ( / v a r i a n t = o n e / gi, 'variant=two' )
60
+ ) ;
61
+ }
62
+ } ,
63
+ } )
64
+ . transform ( response )
65
+ ) ;
66
+ }
67
+ } ;
You can’t perform that action at this time.
0 commit comments