|
1 |
| -import { GetServerSideProps } from 'next' |
2 |
| -import { useRouter } from 'next/router' |
3 |
| - |
4 |
| -// "legacy" javascript needed to maintain existing functionality |
5 |
| -// typically operating on elements **within** an article. |
6 |
| -import copyCode from 'components/lib/copy-code' |
7 |
| -import localization from 'components/lib/localization' |
8 |
| -import wrapCodeTerms from 'components/lib/wrap-code-terms' |
9 |
| - |
10 |
| -import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext' |
11 |
| - |
12 |
| -import { |
13 |
| - getProductLandingContextFromRequest, |
14 |
| - ProductLandingContextT, |
15 |
| - ProductLandingContext, |
16 |
| -} from 'components/context/ProductLandingContext' |
17 |
| -import { |
18 |
| - getProductGuidesContextFromRequest, |
19 |
| - ProductGuidesContextT, |
20 |
| - ProductGuidesContext, |
21 |
| -} from 'components/context/ProductGuidesContext' |
22 |
| - |
23 |
| -import { |
24 |
| - getArticleContextFromRequest, |
25 |
| - ArticleContextT, |
26 |
| - ArticleContext, |
27 |
| -} from 'components/context/ArticleContext' |
28 |
| -import { ArticlePage } from 'components/article/ArticlePage' |
29 |
| - |
30 |
| -import { ProductLanding } from 'components/landing/ProductLanding' |
31 |
| -import { ProductGuides } from 'components/guides/ProductGuides' |
32 |
| -import { TocLanding } from 'components/landing/TocLanding' |
33 |
| -import { |
34 |
| - getTocLandingContextFromRequest, |
35 |
| - TocLandingContext, |
36 |
| - TocLandingContextT, |
37 |
| -} from 'components/context/TocLandingContext' |
38 |
| -import { useEffect } from 'react' |
39 |
| - |
40 |
| -function initiateArticleScripts() { |
41 |
| - copyCode() |
42 |
| - localization() |
43 |
| - wrapCodeTerms() |
44 |
| -} |
45 |
| - |
46 |
| -type Props = { |
47 |
| - mainContext: MainContextT |
48 |
| - productLandingContext?: ProductLandingContextT |
49 |
| - productGuidesContext?: ProductGuidesContextT |
50 |
| - tocLandingContext?: TocLandingContextT |
51 |
| - articleContext?: ArticleContextT |
52 |
| -} |
53 |
| -const GlobalPage = ({ |
54 |
| - mainContext, |
55 |
| - productLandingContext, |
56 |
| - productGuidesContext, |
57 |
| - tocLandingContext, |
58 |
| - articleContext, |
59 |
| -}: Props) => { |
60 |
| - const router = useRouter() |
61 |
| - |
62 |
| - useEffect(() => { |
63 |
| - // https://stackoverflow.com/a/67063998 |
64 |
| - initiateArticleScripts() // on initiate page |
65 |
| - router.events.on('routeChangeComplete', initiateArticleScripts) // on client side route |
66 |
| - return () => { |
67 |
| - router.events.off('routeChangeComplete', initiateArticleScripts) |
68 |
| - } |
69 |
| - }, [router.events]) |
70 |
| - |
71 |
| - let content |
72 |
| - if (productLandingContext) { |
73 |
| - content = ( |
74 |
| - <ProductLandingContext.Provider value={productLandingContext}> |
75 |
| - <ProductLanding /> |
76 |
| - </ProductLandingContext.Provider> |
77 |
| - ) |
78 |
| - } else if (productGuidesContext) { |
79 |
| - content = ( |
80 |
| - <ProductGuidesContext.Provider value={productGuidesContext}> |
81 |
| - <ProductGuides /> |
82 |
| - </ProductGuidesContext.Provider> |
83 |
| - ) |
84 |
| - } else if (tocLandingContext) { |
85 |
| - content = ( |
86 |
| - <TocLandingContext.Provider value={tocLandingContext}> |
87 |
| - <TocLanding /> |
88 |
| - </TocLandingContext.Provider> |
89 |
| - ) |
90 |
| - } else if (articleContext) { |
91 |
| - content = ( |
92 |
| - <ArticleContext.Provider value={articleContext}> |
93 |
| - <ArticlePage /> |
94 |
| - </ArticleContext.Provider> |
95 |
| - ) |
96 |
| - } else { |
97 |
| - throw new Error('No context provided to page') |
98 |
| - } |
99 |
| - |
100 |
| - return <MainContext.Provider value={mainContext}>{content}</MainContext.Provider> |
101 |
| -} |
102 |
| - |
103 |
| -export default GlobalPage |
104 |
| - |
105 |
| -export const getServerSideProps: GetServerSideProps<Props> = async (context) => { |
106 |
| - const req = context.req as any |
107 |
| - const res = context.res as any |
108 |
| - |
109 |
| - const props: Props = { |
110 |
| - mainContext: await getMainContext(req, res), |
111 |
| - } |
112 |
| - const { currentLayoutName, relativePath } = props.mainContext |
113 |
| - |
114 |
| - // This looks a little funky, but it's so we only send one context's data to the client |
115 |
| - if (currentLayoutName === 'product-landing') { |
116 |
| - props.productLandingContext = await getProductLandingContextFromRequest(req) |
117 |
| - } else if (currentLayoutName === 'product-guides') { |
118 |
| - props.productGuidesContext = getProductGuidesContextFromRequest(req) |
119 |
| - } else if (relativePath?.endsWith('index.md')) { |
120 |
| - props.tocLandingContext = getTocLandingContextFromRequest(req) |
121 |
| - } else { |
122 |
| - props.articleContext = getArticleContextFromRequest(req) |
123 |
| - } |
124 |
| - |
125 |
| - return { |
126 |
| - props, |
127 |
| - } |
128 |
| -} |
| 1 | +export { default, getServerSideProps } from 'src/landings/pages/product' |
0 commit comments