Add CSS cache buster

This commit is contained in:
Shadowfacts 2021-04-08 21:41:05 -04:00
parent bd8d958bae
commit 9c0e7e8c68
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 8 additions and 4 deletions

View File

@ -3,12 +3,16 @@ import * as metadata from "./metadata";
import { Metadata } from "./metadata";
import * as util from "./util";
// create the date once so that every page uses the same value
const stylesheetCacheBuster = new Date().getTime();
export default async function layout(text: string, pageMetadata: Metadata, layoutPath: string): Promise<string> {
const layoutFile = path.join("site/layouts", layoutPath);
let layoutPage = await metadata.get(layoutFile);
text = util.render(layoutPage.text, {
content: text,
metadata: pageMetadata
metadata: pageMetadata,
stylesheetCacheBuster,
}, layoutFile);
if (layoutPage.metadata.layout) {
return await layout(text, pageMetadata, layoutPage.metadata.layout);

View File

@ -32,11 +32,11 @@
<script>
(() => {
const theme = localStorage.getItem("theme") || "auto";
document.write(`<link rel="stylesheet" href="/css/${theme}.css">`);
document.write(`<link rel="stylesheet" href="/css/${theme}.css?<%= stylesheetCacheBuster %>">`);
})();
</script>
<noscript>
<link rel="stylesheet" href="/css/auto.css">
<link rel="stylesheet" href="/css/auto.css?<%= stylesheetCacheBuster %>">
</noscript>
</head>
<body itemscope itemtype="https://schema.org/Blog">