Skip to content

Commit

Permalink
Disable cookie banner on query param
Browse files Browse the repository at this point in the history
  • Loading branch information
pkosiec committed Aug 8, 2023
1 parent 7d98706 commit fb3e78e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 0 additions & 25 deletions src/clientModules/cloud-communication.ts

This file was deleted.

28 changes: 28 additions & 0 deletions src/clientModules/embed.ts
Original file line number Diff line number Diff line change
@@ -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,
},
};
});
}
9 changes: 6 additions & 3 deletions src/components/CookieBanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit fb3e78e

Please sign in to comment.