Add CSS cache buster
This commit is contained in:
parent
bd8d958bae
commit
9c0e7e8c68
|
@ -3,16 +3,20 @@ import * as metadata from "./metadata";
|
||||||
import { Metadata } from "./metadata";
|
import { Metadata } from "./metadata";
|
||||||
import * as util from "./util";
|
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> {
|
export default async function layout(text: string, pageMetadata: Metadata, layoutPath: string): Promise<string> {
|
||||||
const layoutFile = path.join("site/layouts", layoutPath);
|
const layoutFile = path.join("site/layouts", layoutPath);
|
||||||
let layoutPage = await metadata.get(layoutFile);
|
let layoutPage = await metadata.get(layoutFile);
|
||||||
text = util.render(layoutPage.text, {
|
text = util.render(layoutPage.text, {
|
||||||
content: text,
|
content: text,
|
||||||
metadata: pageMetadata
|
metadata: pageMetadata,
|
||||||
|
stylesheetCacheBuster,
|
||||||
}, layoutFile);
|
}, layoutFile);
|
||||||
if (layoutPage.metadata.layout) {
|
if (layoutPage.metadata.layout) {
|
||||||
return await layout(text, pageMetadata, layoutPage.metadata.layout);
|
return await layout(text, pageMetadata, layoutPage.metadata.layout);
|
||||||
} else {
|
} else {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,11 +32,11 @@
|
||||||
<script>
|
<script>
|
||||||
(() => {
|
(() => {
|
||||||
const theme = localStorage.getItem("theme") || "auto";
|
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>
|
</script>
|
||||||
<noscript>
|
<noscript>
|
||||||
<link rel="stylesheet" href="/css/auto.css">
|
<link rel="stylesheet" href="/css/auto.css?<%= stylesheetCacheBuster %>">
|
||||||
</noscript>
|
</noscript>
|
||||||
</head>
|
</head>
|
||||||
<body itemscope itemtype="https://schema.org/Blog">
|
<body itemscope itemtype="https://schema.org/Blog">
|
||||||
|
|
Loading…
Reference in New Issue