Skip to content

Commit 61fe987

Browse files
authored
Fix CSP violation from inline script on layout (#41)
The section header toggle was defined as an inline <script> in default.hbs, which was blocked by the site's script-src 'self' Content Security Policy. Moved it into app.js where it's loaded as an external file.
1 parent a980c5b commit 61fe987

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

default.hbs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,6 @@
2727

2828
{{> "footer"}}
2929

30-
<script>
31-
let sections = document.querySelectorAll('.section-header');
32-
function handleClick(event) {
33-
const isActive = event.currentTarget.parentNode.classList.contains("active");
34-
if (!isActive) {
35-
event.currentTarget.parentNode.classList.add("active");
36-
} else {
37-
event.currentTarget.parentNode.classList.remove("active");
38-
}
39-
}
40-
sections.forEach(function(section) {
41-
section.addEventListener("click", handleClick);
42-
});
43-
</script>
4430
{{!-- Outputs important scripts - should always be included before closing body tag --}}
4531
{{ghost_foot}}
4632
</body>

src/js/app/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import "../../css/app.css"
22
import './navigation-top';
33

4+
document.querySelectorAll('.section-header').forEach((header) => {
5+
header.addEventListener('click', function () {
6+
this.parentNode.classList.toggle('active');
7+
});
8+
});
9+
410
// LiveReload server
511
if (ENV === 'development') {
612
const script = document.createElement('script');

0 commit comments

Comments
 (0)