Skip to content

Commit 19a03fe

Browse files
authored
feat: reduce layout shift caused by banner (#444)
1 parent eb86f4b commit 19a03fe

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(() => {
2+
const restore = (key, cls, def = false) => {
3+
const saved = localStorage.getItem(key);
4+
if (saved ? saved !== "false" : def) {
5+
document.documentElement.classList.add(cls);
6+
}
7+
};
8+
9+
window.__OXC_BANNER_ID__ = "/blog/2025-06-10-oxlint-stable";
10+
restore(`oxc-banner-dismissed-${__OXC_BANNER_ID__}`, "banner-dismissed");
11+
})();

.vitepress/config/shared.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
import { readFileSync } from "node:fs";
12
import { dirname, resolve } from "node:path";
23
import { fileURLToPath } from "node:url";
34
import { defineConfig, HeadConfig } from "vitepress";
45
import { groupIconMdPlugin, groupIconVitePlugin } from "vitepress-plugin-group-icons";
56

7+
function inlineScript(file: string): HeadConfig {
8+
return [
9+
"script",
10+
{},
11+
readFileSync(resolve(__dirname, `./inlined-scripts/${file}`), "utf-8"),
12+
];
13+
}
14+
615
const head: HeadConfig[] = [
716
[
817
"link",
@@ -31,6 +40,8 @@ const head: HeadConfig[] = [
3140
content: "https://cdn.jsdelivr.net/gh/oxc-project/oxc-assets/preview-universal.png",
3241
},
3342
],
43+
// banner
44+
inlineScript("banner.js"),
3445
// Google Analytics
3546
["script", { async: "", src: "https://www.googletagmanager.com/gtag/js?id=G-X7WQ091KL7" }],
3647
[

.vitepress/theme/components/Banner.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const hide = () => {
1616
document.documentElement.classList.add("banner-dismissed");
1717
};
1818
19+
// Sync with inlined-scripts/banner.js
1920
const slug = "/blog/2025-06-10-oxlint-stable";
2021
2122
const bannerDismissed = useLocalStorage<boolean>(`oxc-banner-dismissed-${slug}`, false);

0 commit comments

Comments
 (0)