diff --git a/docusaurus.config.js b/docusaurus.config.js index 897f83e5..d8858bd3 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -57,7 +57,7 @@ const config = { }, ], - clientModules: [require.resolve("./src/clientModules/cloud-communication.ts")], + clientModules: [require.resolve("./src/clientModules/embed.ts")], plugins: [ "docusaurus-plugin-sass", diff --git a/src/clientModules/cloud-communication.ts b/src/clientModules/cloud-communication.ts deleted file mode 100644 index feefd8c4..00000000 --- a/src/clientModules/cloud-communication.ts +++ /dev/null @@ -1,25 +0,0 @@ -import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment"; - -const globalParams = { - cookie: { - hide: true, - }, -}; - -if (ExecutionEnvironment.canUseDOM) { - document.addEventListener("DOMContentLoaded", function () { - console.log("Test DOM loaded"); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - window.globalParams = globalParams; - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - console.log("window.globalParams", window.globalParams); - const cookieBannerElem = document.querySelector(".react-cookie-banner"); - console.log("cookieBannerElem", cookieBannerElem); - if (cookieBannerElem) { - console.log("Cookie banner exist"); - cookieBannerElem.style.display = "none"; - } - }); -} diff --git a/src/clientModules/embed.ts b/src/clientModules/embed.ts new file mode 100644 index 00000000..815fd02d --- /dev/null +++ b/src/clientModules/embed.ts @@ -0,0 +1,28 @@ +import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment"; + +export interface DocsConfigWindow extends Window { + displayConfig?: { + cookieBanner: { + forceHide: boolean; + }; + }; +} + +if (ExecutionEnvironment.canUseDOM) { + document.addEventListener("DOMContentLoaded", function () { + 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 c187dbd0..071641cb 100644 --- a/src/components/CookieBanner/index.tsx +++ b/src/components/CookieBanner/index.tsx @@ -2,13 +2,16 @@ 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"; export const CookiesMessageBanner: FC = () => { const cookies = new Cookies(); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - if (!cookies || cookies.get("accepts-cookies") || window.globalParams?.cookie?.hide) { + if ( + !cookies || + cookies.get("accepts-cookies") || + (window as DocsConfigWindow).displayConfig?.cookieBanner.forceHide + ) { return null; }