Skip to content

Commit

Permalink
Add cookiebot consent functionality (#76)
Browse files Browse the repository at this point in the history
* Add cookiebot consent functionality

* fixed slideshow overflow

* Link underline in cookiebot

* fixup buttons

* Fixup home page path function
  • Loading branch information
pookmish authored Oct 31, 2024
1 parent d67bc54 commit 1ed6ff0
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 18 deletions.
13 changes: 2 additions & 11 deletions app/api/revalidate/route.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import {NextRequest, NextResponse} from "next/server"
import {revalidateTag, unstable_cache as nextCache} from "next/cache"
import {getEntityFromPath} from "@lib/gql/gql-queries"
import {revalidateTag} from "next/cache"
import {getHomePagePath} from "@lib/gql/gql-queries"

export const revalidate = 0

export const getHomePagePath = nextCache(
async () => {
const {entity} = await getEntityFromPath("/")
return entity?.path
},
[],
{tags: ["paths:/"]}
)

export const GET = async (request: NextRequest) => {
const secret = request.nextUrl.searchParams.get("secret")
if (secret !== process.env.DRUPAL_REVALIDATE_SECRET)
Expand Down
10 changes: 6 additions & 4 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import UserAnalytics from "@components/elements/user-analytics"
import clsx from "clsx"
import Editori11y from "@components/tools/editorially"
import localFont from "next/font/local"
import Cookiebot from "@components/elements/cookiebot"

const appleIcons: Icon[] = [60, 72, 76, 114, 120, 144, 152, 180].map(size => ({
url: `https://www-media.stanford.edu/assets/favicon/apple-touch-icon-${size}x${size}.png`,
Expand Down Expand Up @@ -48,11 +49,12 @@ const RootLayout = ({children, modal}: {children: React.ReactNode; modal: React.

return (
<html lang="en" className={clsx(sourceSans3.className, roboto.variable, stanford.variable)}>
<UserAnalytics />
<DrupalWindowSync />
{isDevMode && <Editori11y />}

<body className="text-archway-dark">
<Cookiebot />
<UserAnalytics />
<DrupalWindowSync />
{isDevMode && <Editori11y />}

<nav aria-label="Skip Links">
<a href="#main-content" className="skiplink">
Skip to main content
Expand Down
2 changes: 1 addition & 1 deletion app/sitemap.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {MetadataRoute} from "next"
import {graphqlClient} from "@lib/gql/gql-client"
import {NodeUnion} from "@lib/gql/__generated__/drupal.d"
import {getHomePagePath} from "./api/revalidate/route"
import {getHomePagePath} from "@lib/gql/gql-queries"

// https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
export const revalidate = 604800
Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const nextConfig = {
experimental: {},
typescript: {
// Disable build errors since dev dependencies aren't loaded on prod. Rely on GitHub actions to throw any errors.
ignoreBuildErrors: process.env.CI !== 'true',
// ignoreBuildErrors: process.env.CI !== 'true',
},
images: {
remotePatterns: [
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"postcss": "^8.4.47",
"qs": "^6.13.0",
"react": "19.0.0-rc-fb9a90fa48-20240614",
"react-cookiebot": "^1.0.10",
"react-dom": "19.0.0-rc-fb9a90fa48-20240614",
"react-error-boundary": "^4.1.2",
"react-focus-lock": "^2.13.2",
Expand Down Expand Up @@ -65,6 +66,7 @@
"@storybook/nextjs": "^8.3.6",
"@storybook/react": "^8.3.6",
"@storybook/testing-library": "^0.2.2",
"@types/react-cookiebot": "^1.0.5",
"@types/react-slick": "^0.23.13",
"concurrently": "^9.0.1",
"encoding": "^0.1.13",
Expand Down
9 changes: 9 additions & 0 deletions src/components/elements/cookiebot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use client"

import ReactCookieBot from "react-cookiebot"

const Cookiebot = () => {
return <ReactCookieBot domainGroupId="bcda1e2f-63c7-4cad-81b4-04a49e30b05f" />
}

export default Cookiebot
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const SumCarouselParagraph = ({paragraph, ...props}: Props) => {
)}

{paragraph.sumCarouselSlides && (
<div className="relative left-1/2 mb-32 mt-0 w-screen -translate-x-1/2">
<div className="relative left-1/2 mb-32 mt-0 w-screen -translate-x-1/2 overflow-x-hidden">
<Slideshow className="mx-auto w-[calc(100%-50px)] xl:w-[calc(100%-150px)]">
{paragraph.sumCarouselSlides.map((slide, slideIndex) => {
return (
Expand Down
9 changes: 9 additions & 0 deletions src/lib/gql/gql-queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,12 @@ export const getAlgoliaCredential = nextCache(
["algolia"],
{tags: ["algolia"]}
)

export const getHomePagePath = nextCache(
async () => {
const {entity} = await getEntityFromPath("/")
return entity?.path
},
[],
{tags: ["paths:/"]}
)
6 changes: 6 additions & 0 deletions src/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,9 @@ body button:focus {
padding-right: 59px;
}
}

#CybotCookiebotDialog {
a:hover, a:focus-visible, button:hover, button:focus-visible {
text-decoration: underline;
}
}
23 changes: 23 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6470,6 +6470,15 @@ __metadata:
languageName: node
linkType: hard

"@types/react-cookiebot@npm:^1.0.5":
version: 1.0.5
resolution: "@types/react-cookiebot@npm:1.0.5"
dependencies:
"@types/react": "npm:*"
checksum: 10c0/963ae31e3dfe2c94ca29df9676a8404e8c788a9daced47afa46d24a0d9491628b0bd3337ffc16c212d6ce38ceb60c89925a9393b77a532821d2c2c2f458cb367
languageName: node
linkType: hard

"@types/react-dom@npm:[email protected]":
version: 19.0.0-rc.1
resolution: "types-react-dom@npm:19.0.0-rc.1"
Expand Down Expand Up @@ -14806,6 +14815,18 @@ __metadata:
languageName: node
linkType: hard

"react-cookiebot@npm:^1.0.10":
version: 1.0.10
resolution: "react-cookiebot@npm:1.0.10"
dependencies:
"@babel/runtime": "npm:^7.12.5"
prop-types: "npm:^15.7.2"
peerDependencies:
react: "*"
checksum: 10c0/f40848be28c24e1103373e6f78a1793c90054c96ccd213b43712c2c1dc43a4bcd35e6d76bd2c460b9b5602670d331baee07b45d23c96d04c518bdf9241fb7797
languageName: node
linkType: hard

"react-docgen-typescript@npm:^2.2.2":
version: 2.2.2
resolution: "react-docgen-typescript@npm:2.2.2"
Expand Down Expand Up @@ -16662,6 +16683,7 @@ __metadata:
"@tailwindcss/container-queries": "npm:^0.1.1"
"@types/node": "npm:^22.8.4"
"@types/react": "npm:^19.0.0-rc.1"
"@types/react-cookiebot": "npm:^1.0.5"
"@types/react-dom": "npm:19.0.0-rc.1"
"@types/react-slick": "npm:^0.23.13"
algoliasearch: "npm:^5.12.0"
Expand All @@ -16687,6 +16709,7 @@ __metadata:
prettier-plugin-tailwindcss: "npm:^0.6.8"
qs: "npm:^6.13.0"
react: "npm:19.0.0-rc-fb9a90fa48-20240614"
react-cookiebot: "npm:^1.0.10"
react-docgen: "npm:^7.1.0"
react-dom: "npm:19.0.0-rc-fb9a90fa48-20240614"
react-error-boundary: "npm:^4.1.2"
Expand Down

0 comments on commit 1ed6ff0

Please sign in to comment.