From cb206634e736249a9fe32ac57c11c5684e9abefc Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Tue, 2 Jan 2024 01:30:36 +0000 Subject: Better escapement for template and serve mode --- src/config.ts | 15 ++++++++++++++ src/templates/layouts/page.njk | 45 ++++++++++++++++++++++++------------------ tsconfig.json | 2 +- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/config.ts b/src/config.ts index 3746503..71a6c66 100644 --- a/src/config.ts +++ b/src/config.ts @@ -47,6 +47,21 @@ ${Object.values(metadata) }, ); + // add `cspMode` shortcode + config.addShortcode("metaCsp", function () { + const runMode = this.eleventy.env.runMode; + let policy: string; + if (runMode === "serve" || runMode == "watch") { + policy = + "default-src http://localhost:8080/;img-src http://localhost:8080/ data:;connect-src ws://localhost:8080/;script-src 'strict-dynamic' 'sha512-7Y25+FX/kRUbZEHtQBOSLffzofBxz8ABQErLAVpGkfzactkpJU5wtTmhIfIZeTw7VHg1JeTIC5kHkzPq7LqR1w==';"; + } else { + // runMode === "build" or unknown + policy = + "default-src 'self';img-src 'self' data:;script-src 'none';object-src 'none';base-uri 'none';connect-src: 'none';"; + } + return ``; + }); + // add `date` filter config.addFilter("formatDate", formatDate); diff --git a/src/templates/layouts/page.njk b/src/templates/layouts/page.njk index 333a50e..c14caf5 100644 --- a/src/templates/layouts/page.njk +++ b/src/templates/layouts/page.njk @@ -1,29 +1,36 @@ +--- +pageTitle: Kevin J Hoerr +copyYear: 2024 +author: Kevin J Hoerr +description: The official website of Kevin Hoerr, developer of websites. +themeColor: "#e1e1e1" +--- - - - - - + + + + + - + {% metaCsp %} - - - - - - - - - - - - Kevin J Hoerr <kjhoerr@submelon.tech> + + + + + + + + + + + + {{ pageTitle | escape | replace('@', '@') }}
@@ -31,7 +38,7 @@ {{ content | safe }}
diff --git a/tsconfig.json b/tsconfig.json index dc5ba34..c5254b5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -80,7 +80,7 @@ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ - // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ + "noImplicitThis": false, /* Enable error reporting when `this` is given the type `any`. */ // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ -- cgit