File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1717 "web-vitals" : " ^2.1.0"
1818 },
1919 "scripts" : {
20- "start" : " react-scripts start" ,
20+ "start" : " set PORT=8000 && react-scripts start" ,
2121 "build" : " react-scripts build" ,
2222 "gen-assets" : " rimraf static-assets && mkdir -p static-assets && cp build/static/js/*.js static-assets/main-v1.js" ,
2323 "test" : " react-scripts test" ,
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import Link from 'components/Link'
66import SkipLink from 'components/Link/Skip'
77import MainNav from 'components/nav/MainNav'
88import DrawerNav from 'components/nav/DrawerNav'
9+ import useDocWhizzScript from './useDocWhizzScript'
910
1011const Nav = styled ( FaencyNav ) `
1112 position: fixed;
@@ -120,6 +121,7 @@ const Header = ({ product }: { product?: string }) => {
120121 const [ isDrawerOpen , setIsDrawerOpen ] = useState ( false )
121122 const [ isHeaderScrolled , setHeaderScrolled ] = useState ( false )
122123
124+ useDocWhizzScript ( )
123125 const demoLink = useMemo ( ( ) => {
124126 if ( product === 'hub' ) return 'https://info.traefik.io/traefik-hub-signup'
125127
Original file line number Diff line number Diff line change 1+ import { useEffect , useMemo } from 'react'
2+
3+ const WHITELISTED_HOSTNAME = [ 'localhost' , 'doc.traefik.io' ]
4+
5+ const useDocWhizzScript = ( ) => {
6+ const { pathname, hostname } = window . location
7+ const product = pathname . split ( '/' ) [ 1 ]
8+
9+ const clientId = useMemo ( ( ) => {
10+ if ( WHITELISTED_HOSTNAME . includes ( hostname ) ) {
11+ // if (product === 'traefik') return '65e8267d7714e3b11a5ce139'
12+ if ( product === 'traefik-enterprise' ) return '65f0e20984bd4dfcfe7e58a6'
13+
14+ return null
15+ }
16+ return null
17+ } , [ hostname , product ] )
18+
19+ useEffect ( ( ) => {
20+ if ( ! ! clientId ) {
21+ const t = document . createElement ( 'script' )
22+ t . setAttribute ( 'data-id' , 'docwhizz-script' )
23+ t . setAttribute ( 'data-client' , clientId )
24+ t . crossOrigin = 'anonymous'
25+ t . src = 'https://widget.docwhizz.com/index.js'
26+ t . type = 'module'
27+ document . head . appendChild ( t )
28+
29+ return ( ) => {
30+ document . head . removeChild ( t )
31+ }
32+ }
33+ } , [ clientId ] )
34+ }
35+
36+ export default useDocWhizzScript
You can’t perform that action at this time.
0 commit comments