diff options
| author | Kevin J Hoerr <kjhoerr@protonmail.com> | 2024-01-02 01:30:36 +0000 |
|---|---|---|
| committer | Kevin J Hoerr <kjhoerr@protonmail.com> | 2024-01-02 01:30:36 +0000 |
| commit | cb206634e736249a9fe32ac57c11c5684e9abefc (patch) | |
| tree | f940602f2c5ef6e2f868bab650a526e01f0350f9 | |
| parent | e5b3c5bbbba1eae131af77e43144d27a41dd5751 (diff) | |
| download | submelon.dev-cb206634e736249a9fe32ac57c11c5684e9abefc.tar.gz submelon.dev-cb206634e736249a9fe32ac57c11c5684e9abefc.tar.bz2 submelon.dev-cb206634e736249a9fe32ac57c11c5684e9abefc.zip | |
Better escapement for template and serve mode
| -rw-r--r-- | src/config.ts | 15 | ||||
| -rw-r--r-- | src/templates/layouts/page.njk | 45 | ||||
| -rw-r--r-- | 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 `<meta http-equiv="Content-Security-Policy" content="${policy}">`; + }); + // 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 <kjhoerr@submelon.tech> +copyYear: 2024 +author: Kevin J Hoerr +description: The official website of Kevin Hoerr, developer of websites. +themeColor: "#e1e1e1" +--- <!DOCTYPE html> <html lang="en"> <head> <meta charSet="utf-8"/> <meta http-equiv="x-ua-compatible" content="ie=edge"/> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/> - <meta name="theme-color" content="#e1e1e1"/> - <meta name="description" content="The official website of Kevin Hoerr, developer of websites."/> - <meta name="twitter:description" content="The official website of Kevin Hoerr, developer of websites."/> - <meta name="twitter:title" content="Kevin J Hoerr <kjhoerr@submelon.tech>"/> - <meta name="twitter:creator" content="Kevin J Hoerr"/> + <meta name="theme-color" content="{{ themeColor }}"/> + <meta name="description" content="{{ description }}"/> + <meta name="twitter:description" content="{{ description }}"/> + <meta name="twitter:title" content="{{ pageTitle | escape | replace('@', '@') }}"/> + <meta name="twitter:creator" content="{{ author }}"/> <meta name="twitter:card" content="summary"/> - <meta http-equiv="Content-Security-Policy" content="default-src 'self';img-src 'self' data:;script-src 'none';object-src 'none';base-uri 'none';"> + {% metaCsp %} <meta name="generator" content="{{ eleventy.generator }}"> - <link rel="stylesheet" href="/styles.css"/> - <link rel="icon" href="/favicon-32x32.png" type="image/png"/> - <link rel="manifest" href="/manifest.webmanifest"/> - <link rel="apple-touch-icon" sizes="48x48" href="/icons/icon-48x48.png"/> - <link rel="apple-touch-icon" sizes="72x72" href="/icons/icon-72x72.png"/> - <link rel="apple-touch-icon" sizes="96x96" href="/icons/icon-96x96.png"/> - <link rel="apple-touch-icon" sizes="144x144" href="/icons/icon-144x144.png"/> - <link rel="apple-touch-icon" sizes="192x192" href="/icons/icon-192x192.png"/> - <link rel="apple-touch-icon" sizes="256x256" href="/icons/icon-256x256.png"/> - <link rel="apple-touch-icon" sizes="384x384" href="/icons/icon-384x384.png"/> - <link rel="apple-touch-icon" sizes="512x512" href="/icons/icon-512x512.png"/> - <title>Kevin J Hoerr <kjhoerr@submelon.tech></title> + <link rel="stylesheet" href="{{ '/styles.css' | url }}"/> + <link rel="icon" href="{{ '/favicon-32x32.png' | url }}" type="image/png"/> + <link rel="manifest" href="{{ '/manifest.webmanifest' | url }}"/> + <link rel="apple-touch-icon" sizes="48x48" href="{{ '/icons/icon-48x48.png' | url }}"/> + <link rel="apple-touch-icon" sizes="72x72" href="{{ '/icons/icon-72x72.png' | url }}"/> + <link rel="apple-touch-icon" sizes="96x96" href="{{ '/icons/icon-96x96.png' | url }}"/> + <link rel="apple-touch-icon" sizes="144x144" href="{{ '/icons/icon-144x144.png' | url }}"/> + <link rel="apple-touch-icon" sizes="192x192" href="{{ '/icons/icon-192x192.png' | url }}"/> + <link rel="apple-touch-icon" sizes="256x256" href="{{ '/icons/icon-256x256.png' | url }}"/> + <link rel="apple-touch-icon" sizes="384x384" href="{{ '/icons/icon-384x384.png' | url }}"/> + <link rel="apple-touch-icon" sizes="512x512" href="{{ '/icons/icon-512x512.png' | url }}"/> + <title>{{ pageTitle | escape | replace('@', '@') }}</title> </head> <body> <main> @@ -31,7 +38,7 @@ {{ content | safe }} </article> <footer> - <span>©2024 kjhoerr@https://submelon.dev/:{{ buildTimeEncoded }}</span> + <span>©{{ copyYear }} kjhoerr@https://submelon.dev/:{{ buildTimeEncoded }}</span> </footer> </main> </body> 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. */ |
