Skip to content

Commit

Permalink
build header script to remove inline script for csp (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
countableSet authored Apr 15, 2023
1 parent 2fe33a7 commit 39af887
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions gulp.d/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ module.exports = (src, dest, preview) => () => {
.pipe(uglify({ output: { comments: /^! / } }))
// NOTE concat already uses stat from newest combined file
.pipe(concat('js/site.js')),
vfs
.src('js/header/+([0-9])-*.js', { ...opts, read: false, sourcemaps })
.pipe(bundle(opts))
.pipe(uglify({ output: { comments: /^! / } }))
// NOTE concat already uses stat from newest combined file
.pipe(concat('js/header.js')),
vfs
.src('js/vendor/*([^.])?(.bundle).js', { ...opts, read: false })
.pipe(bundle(opts))
Expand Down
8 changes: 8 additions & 0 deletions src/js/header/01-root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict'

// eslint-disable-next-line no-unused-vars
var uiRootPath = '_'

if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.setAttribute('data-theme', 'dark')
}
3 changes: 1 addition & 2 deletions src/partials/head-scripts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
<script async src="https://www.googletagmanager.com/gtag/js?id={{this}}"></script>
<script>function gtag(){dataLayer.push(arguments)};window.dataLayer=window.dataLayer||[];gtag('js',new Date());gtag('config','{{this}}')</script>
{{/with}}
<script>var uiRootPath = '{{{uiRootPath}}}'</script>
<script>if (window.matchMedia('(prefers-color-scheme: dark)').matches) document.documentElement.setAttribute('data-theme', 'dark')</script>
<script id="header-script" src="_/js/header.js" data-ui-root-path="_"></script>

0 comments on commit 39af887

Please sign in to comment.