Skip to content

Commit af2bacb

Browse files
authored
Merge branch '@ksienkiewicz/docs-fundamentals' into @ksienkiewicz/feat-docs-project-configuration
2 parents 7db83cd + a60f30a commit af2bacb

8 files changed

Lines changed: 95 additions & 207 deletions

File tree

docs/docusaurus.config.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// @ts-check
22
// Note: type annotations allow type checking and IDEs autocompletion
33

4+
import { topbarBannerReservationScript } from '@swmansion/t-rex-ui/topbar-banner';
5+
import { TOP_BAR_BANNER } from './src/components/topbarBanner.config.ts';
6+
47
const path = require('path');
58

69
const lightCodeTheme = require('./src/theme/CodeBlock/highlighting-light.js');
@@ -53,6 +56,21 @@ function enrichedHtmlLocalSourcePlugin() {
5356
};
5457
}
5558

59+
const firstBannerZone = TOP_BAR_BANNER.zones[0];
60+
const bannerReservationHeadTags = firstBannerZone
61+
? [
62+
{
63+
tagName: 'script',
64+
attributes: { type: 'text/javascript' },
65+
innerHTML: topbarBannerReservationScript(
66+
firstBannerZone.zoneId,
67+
firstBannerZone.contentId,
68+
TOP_BAR_BANNER.hiddenPaths,
69+
),
70+
},
71+
]
72+
: [];
73+
5674
/** @type {import('@docusaurus/types').Config} */
5775
const config = {
5876
title: 'React Native Enriched HTML',
@@ -113,6 +131,10 @@ const config = {
113131
require.resolve('@swmansion/t-rex-ui/preset'),
114132
],
115133

134+
headTags: bannerReservationHeadTags,
135+
136+
clientModules: [require.resolve('./src/clientModules/topbarBannerRefresh.ts')],
137+
116138
plugins: [
117139
reactNativeWebPlugin,
118140
enrichedHtmlLocalSourcePlugin,
@@ -135,13 +157,12 @@ const config = {
135157
},
136158
};
137159
},
138-
// TODO: enable Google Tag Manager with a container id for this site.
139-
// process.env.NODE_ENV === 'production' && [
140-
// '@docusaurus/plugin-google-tag-manager',
141-
// {
142-
// containerId: 'GTM-XXXXXXX',
143-
// },
144-
// ],
160+
process.env.NODE_ENV === 'production' && [
161+
'@docusaurus/plugin-google-tag-manager',
162+
{
163+
containerId: 'GTM-N5QK8TMT',
164+
},
165+
],
145166
].filter(Boolean),
146167

147168
themeConfig:

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@emotion/styled": "^11.14.0",
2828
"@mdx-js/react": "^3.0.0",
2929
"@mui/material": "^7.1.0",
30-
"@swmansion/t-rex-ui": "1.3.2",
30+
"@swmansion/t-rex-ui": "1.3.4",
3131
"clsx": "^2.1.0",
3232
"copy-text-to-clipboard": "3.2.2",
3333
"prettier": "^3.6.2",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { ClientModule } from '@docusaurus/types';
2+
import type { BannerZone } from '@swmansion/t-rex-ui';
3+
import { TOP_BAR_BANNER } from '../components/topbarBanner.config';
4+
5+
// Revive's async tag only scans <ins> slots once, on initial load; re-trigger it after each SPA nav so remounted slots get filled.
6+
const contentIds = Array.from(
7+
new Set(TOP_BAR_BANNER.zones.map((zone: BannerZone) => zone.contentId)),
8+
);
9+
10+
function refreshBannerContent() {
11+
contentIds.forEach((contentId) => {
12+
document.dispatchEvent(new CustomEvent(`content-${contentId}-refresh`));
13+
});
14+
}
15+
16+
export const onRouteDidUpdate: ClientModule['onRouteDidUpdate'] = ({
17+
previousLocation,
18+
location,
19+
}) => {
20+
if (!previousLocation || previousLocation.pathname === location.pathname) {
21+
return;
22+
}
23+
// Defer until after the new route's <ins> nodes are actually in the DOM.
24+
setTimeout(refreshBannerContent, 0);
25+
};

docs/src/components/TopPromoRotator/index.tsx

Lines changed: 0 additions & 114 deletions
This file was deleted.

docs/src/components/TopPromoRotator/styles.module.css

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
export const TOP_BAR_BANNER = {
3+
rotateIntervalMs: 4000,
4+
zones: [
5+
{
6+
zoneId: 'enriched-topbar-1',
7+
contentId: 'ea15c4216158c4097b65fe6504a4b3b7',
8+
fallbackBgColor: '#001a72',
9+
},
10+
{
11+
zoneId: 'enriched-topbar-2',
12+
contentId: 'ea15c4216158c4097b65fe6504a4b3b7',
13+
fallbackBgColor: '#001a72',
14+
},
15+
{
16+
zoneId: 'enriched-topbar-3',
17+
contentId: 'ea15c4216158c4097b65fe6504a4b3b7',
18+
fallbackBgColor: '#001a72',
19+
},
20+
] satisfies BannerZone[],
21+
};

docs/src/theme/Navbar/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import React from 'react';
2-
import { Navbar } from '@swmansion/t-rex-ui';
3-
import TopPromoRotator from '@site/src/components/TopPromoRotator';
2+
import { useLocation } from '@docusaurus/router';
3+
import { Navbar, TopbarBanner, isBannerHidden } from '@swmansion/t-rex-ui';
4+
import { TOP_BAR_BANNER } from '@site/src/components/topbarBanner.config';
45

56
export default function NavbarWrapper(props) {
7+
const location = useLocation();
8+
const bannerHidden = isBannerHidden(
9+
location.pathname,
10+
TOP_BAR_BANNER.hiddenPaths,
11+
);
612
return (
713
<div style={{ display: 'flex', flexDirection: 'column', flexShrink: 0 }}>
8-
<TopPromoRotator />
14+
{!bannerHidden && (
15+
<TopbarBanner
16+
zones={TOP_BAR_BANNER.zones}
17+
rotateIntervalMs={TOP_BAR_BANNER.rotateIntervalMs}
18+
/>
19+
)}
920
<Navbar
1021
useLandingLogoDualVariant={true}
1122
isAlgoliaActive={false}

docs/yarn.lock

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4062,9 +4062,9 @@ __metadata:
40624062
languageName: node
40634063
linkType: hard
40644064

4065-
"@swmansion/t-rex-ui@npm:1.3.2":
4066-
version: 1.3.2
4067-
resolution: "@swmansion/t-rex-ui@npm:1.3.2"
4065+
"@swmansion/t-rex-ui@npm:1.3.4":
4066+
version: 1.3.4
4067+
resolution: "@swmansion/t-rex-ui@npm:1.3.4"
40684068
dependencies:
40694069
"@docusaurus/core": "npm:3.9.2"
40704070
"@docusaurus/module-type-aliases": "npm:3.9.2"
@@ -4085,10 +4085,11 @@ __metadata:
40854085
"@emotion/styled": "*"
40864086
"@mui/material": ">=5.0.0"
40874087
copy-text-to-clipboard: ^3.2.2
4088+
prism-react-renderer: ^2.0.0
40884089
react: "*"
40894090
react-dom: "*"
40904091
react-icons: "*"
4091-
checksum: 10c0/8e88ca4efbc892b01cea5e07f6b46332f32c04008685c7083f52a8f9b0c269f74e6afa2ba5458aae106fcd1ea746a22176f8ec13f5e3823d5405e651e94438ec
4092+
checksum: 10c0/64adad0bcce8856d1855e2da153af9429c8a6ae759fb510933163e523db83a70eeceded9d8e50d108f269f7129f143b5f401509aa3ab0331f5fd14eea3295d66
40924093
languageName: node
40934094
linkType: hard
40944095

@@ -7267,7 +7268,7 @@ __metadata:
72677268
"@emotion/styled": "npm:^11.14.0"
72687269
"@mdx-js/react": "npm:^3.0.0"
72697270
"@mui/material": "npm:^7.1.0"
7270-
"@swmansion/t-rex-ui": "npm:1.3.2"
7271+
"@swmansion/t-rex-ui": "npm:1.3.4"
72717272
clsx: "npm:^2.1.0"
72727273
copy-text-to-clipboard: "npm:3.2.2"
72737274
prettier: "npm:^3.6.2"

0 commit comments

Comments
 (0)