Skip to content

Commit b4ff291

Browse files
committed
docs: banner mod
1 parent b59d452 commit b4ff291

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"docusaurus-plugin-react-docgen-typescript": "^1.3.0",
2828
"file-loader": "^6.2.0",
2929
"git-branch": "^2.0.1",
30+
"js-cookie": "^3.0.5",
3031
"prism-react-renderer": "^1.3.5",
3132
"react": "^18.3.1",
3233
"react-docgen-typescript": "^2.2.2",

website/pnpm-lock.yaml

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/src/theme/DocSidebar/index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
import React, { useEffect, useRef } from 'react';
22
import { useColorMode } from '@docusaurus/theme-common';
33
import OriginalDocSidebar from '@theme-original/DocSidebar';
4+
import Cookies from 'js-cookie';
5+
6+
const COOKIE_NAME = 'bwndw_fallback_cached';
7+
const COOKIE_DURATION = 28; // days (4 weeks)
48

59
async function shouldUseFallback() {
6-
return true; // Temporarily disable EthicalAds
10+
const cached = Cookies.get(COOKIE_NAME);
11+
12+
if (cached !== undefined) {
13+
return cached === 'true';
14+
}
715

816
while (typeof ethicalads === 'undefined') {
917
await new Promise((resolve) => setTimeout(resolve, 300));
1018
}
1119

1220
const placements = await ethicalads.wait;
21+
const useFallback = !placements.length || placements[0].response.campaign_type !== 'paid';
22+
23+
Cookies.set(COOKIE_NAME, useFallback.toString(), {
24+
expires: COOKIE_DURATION,
25+
sameSite: 'lax'
26+
});
1327

14-
return !placements.length || placements[0].response.campaign_type !== 'paid';
28+
return useFallback;
1529
}
1630

1731
function createEthicalAdsBlock(root) {

0 commit comments

Comments
 (0)