diff --git a/docusaurus.config.js b/docusaurus.config.js index d8858bd3..25d9980f 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -57,8 +57,6 @@ const config = { }, ], - clientModules: [require.resolve("./src/clientModules/embed.ts")], - plugins: [ "docusaurus-plugin-sass", [ diff --git a/src/clientModules/embed.ts b/src/clientModules/embed.ts deleted file mode 100644 index f47d7857..00000000 --- a/src/clientModules/embed.ts +++ /dev/null @@ -1,32 +0,0 @@ -import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment"; - -export interface DocsConfigWindow extends Window { - displayConfig?: { - cookieBanner: { - forceHide: boolean; - }; - }; -} - -if (ExecutionEnvironment.canUseDOM && ExecutionEnvironment.canUseEventListeners && typeof window !== "undefined") { - document.addEventListener("DOMContentLoaded", () => { - if (!window) { - return; - } - - const urlParams = new URLSearchParams(window.location.search); - const isEmbedded = urlParams.get("embedded"); - if (!isEmbedded) { - return; - } - - console.log("embedded mode detected"); - - (window as DocsConfigWindow).displayConfig = { - ...(window as DocsConfigWindow).displayConfig, - cookieBanner: { - forceHide: true, - }, - }; - }); -} diff --git a/src/components/CookieBanner/index.tsx b/src/components/CookieBanner/index.tsx index 244c1bd1..6e4b881b 100644 --- a/src/components/CookieBanner/index.tsx +++ b/src/components/CookieBanner/index.tsx @@ -2,19 +2,24 @@ import React, { FC } from "react"; import { Link } from "react-router-dom"; import CookieBanner, { Cookies } from "react-cookie-banner"; import styles from "./index.module.scss"; -import { DocsConfigWindow } from "@site/src/clientModules/embed"; +import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment"; +import useIsBrowser from "@docusaurus/useIsBrowser"; export const CookiesMessageBanner: FC = () => { + const isBrowser = useIsBrowser(); + if (!isBrowser) { + return null; + } + const cookies = new Cookies(); - if ( - !cookies || - cookies.get("accepts-cookies") || - (typeof window !== "undefined" && (window as DocsConfigWindow).displayConfig?.cookieBanner.forceHide) - ) { + if (!cookies || cookies.get("accepts-cookies") || isSiteEmbedded()) { + console.log("disable cookie banner"); return null; } + console.log("enable cookie banner"); + return ( { /> ); }; + +function isSiteEmbedded(): boolean { + if (!ExecutionEnvironment.canUseDOM || typeof window === "undefined") { + return false; + } + + const urlParams = new URLSearchParams(window.location.search); + const embeddedValue = urlParams.get("embedded"); + return embeddedValue === "true"; +}