Skip to content

Commit ef413e4

Browse files
authored
Merge pull request #25800 from github/repo-sync
repo sync
2 parents bff658b + cad57ee commit ef413e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+281
-269
lines changed

components/context/TocLandingContext.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import pick from 'lodash/pick'
22
import { createContext, useContext } from 'react'
33
import { LearningTrack } from './ArticleContext'
4-
import { FeaturedLink, getFeaturedLinksFromReq } from './ProductLandingContext'
4+
import {
5+
FeaturedLink,
6+
getFeaturedLinksFromReq,
7+
} from 'src/landings/components/ProductLandingContext'
58

69
export type TocItem = {
710
fullPath: string

components/sidebar/SidebarNav.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import cx from 'classnames'
22

33
import { useMainContext } from 'components/context/MainContext'
4-
import { SidebarProduct } from './SidebarProduct'
5-
import { SidebarHomepage } from './SidebarHomepage'
4+
import { SidebarProduct } from 'src/landings/components/SidebarProduct'
5+
import { SidebarHomepage } from '../../src/landings/components/SidebarHomepage'
66
import { AllProductsLink } from './AllProductsLink'
77
import { ApiVersionPicker } from 'src/rest/components/ApiVersionPicker'
88
import { Link } from 'components/Link'

middleware/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import glossaries from './contextualizers/glossaries.js'
5050
import features from './contextualizers/features.js'
5151
import productExamples from './contextualizers/product-examples.js'
5252
import productGroups from './contextualizers/product-groups.js'
53-
import featuredLinks from './featured-links.js'
53+
import featuredLinks from '../src/landings/middleware/featured-links.js'
5454
import learningTrack from './learning-track.js'
5555
import next from './next.js'
5656
import renderPage from './render-page.js'
Lines changed: 1 addition & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1 @@
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'

pages/index.tsx

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1 @@
1-
import React from 'react'
2-
import type { GetServerSideProps } from 'next'
3-
4-
import { MainContextT, MainContext, getMainContext } from 'components/context/MainContext'
5-
6-
import { DefaultLayout } from 'components/DefaultLayout'
7-
import { useTranslation } from 'components/hooks/useTranslation'
8-
import { ArticleList } from 'components/landing/ArticleList'
9-
import { HomePageHero } from 'components/homepage/HomePageHero'
10-
import type { ProductGroupT } from 'components/homepage/ProductSelections'
11-
import { ProductSelections } from 'components/homepage/ProductSelections'
12-
13-
type FeaturedLink = {
14-
href: string
15-
title: string
16-
intro: string
17-
}
18-
19-
type Props = {
20-
mainContext: MainContextT
21-
popularLinks: Array<FeaturedLink>
22-
gettingStartedLinks: Array<FeaturedLink>
23-
productGroups: Array<ProductGroupT>
24-
}
25-
26-
export default function MainHomePage({
27-
mainContext,
28-
gettingStartedLinks,
29-
popularLinks,
30-
productGroups,
31-
}: Props) {
32-
return (
33-
<MainContext.Provider value={mainContext}>
34-
<DefaultLayout>
35-
<HomePage
36-
gettingStartedLinks={gettingStartedLinks}
37-
popularLinks={popularLinks}
38-
productGroups={productGroups}
39-
/>
40-
</DefaultLayout>
41-
</MainContext.Provider>
42-
)
43-
}
44-
45-
type HomePageProps = {
46-
popularLinks: Array<FeaturedLink>
47-
gettingStartedLinks: Array<FeaturedLink>
48-
productGroups: Array<ProductGroupT>
49-
}
50-
function HomePage(props: HomePageProps) {
51-
const { gettingStartedLinks, popularLinks, productGroups } = props
52-
const { t } = useTranslation(['toc'])
53-
54-
return (
55-
<div>
56-
<HomePageHero />
57-
<ProductSelections productGroups={productGroups} />
58-
<div className="mt-6 px-3 px-md-6 container-xl">
59-
<div className="container-xl">
60-
<div className="gutter gutter-xl-spacious clearfix">
61-
<div className="col-12 col-lg-6 mb-md-4 mb-lg-0 float-left">
62-
<ArticleList title={t('toc:getting_started')} articles={gettingStartedLinks} />
63-
</div>
64-
65-
<div className="col-12 col-lg-6 float-left">
66-
<ArticleList title={t('toc:popular')} articles={popularLinks} />
67-
</div>
68-
</div>
69-
</div>
70-
</div>
71-
</div>
72-
)
73-
}
74-
75-
export const getServerSideProps: GetServerSideProps<Props> = async (context) => {
76-
const req = context.req as any
77-
const res = context.res as any
78-
79-
return {
80-
props: {
81-
mainContext: await getMainContext(req, res),
82-
productGroups: req.context.productGroups,
83-
gettingStartedLinks: req.context.featuredLinks.gettingStarted.map(
84-
({ title, href, intro }: any) => ({ title, href, intro })
85-
),
86-
popularLinks: req.context.featuredLinks.popular.map(({ title, href, intro }: any) => ({
87-
title,
88-
href,
89-
intro,
90-
})),
91-
},
92-
}
93-
}
1+
export { default, getServerSideProps } from 'src/landings/pages/home'

src/landings/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Landing pages
2+
3+
Landing pages include the Docs home page, the product landing pages, and product guides pages.
4+
5+
## What landing pages are for
6+
7+
Landing pages provide a hierarchical view of their area, making navigating the Docs easier.

components/guides/ArticleCard.tsx renamed to src/landings/components/ArticleCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Label } from '@primer/react'
22

3-
import { ArticleGuide } from 'components/context/ProductGuidesContext'
3+
import { ArticleGuide } from 'src/landings/components/ProductGuidesContext'
44
import { Link } from 'components/Link'
55

66
type Props = {

components/guides/ArticleCards.tsx renamed to src/landings/components/ArticleCards.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useEffect, useRef, useState } from 'react'
22

3-
import { ArticleGuide, useProductGuidesContext } from 'components/context/ProductGuidesContext'
3+
import { ArticleGuide, useProductGuidesContext } from 'src/landings/components/ProductGuidesContext'
44
import { useTranslation } from 'components/hooks/useTranslation'
55
import { ArticleCard } from './ArticleCard'
66
import { ActionList, ActionMenu } from '@primer/react'

components/landing/ArticleList.tsx renamed to src/landings/components/ArticleList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ActionList } from '@primer/react'
44
import { useTranslation } from 'components/hooks/useTranslation'
55
import { Link } from 'components/Link'
66
import { ArrowRightIcon } from '@primer/octicons-react'
7-
import { FeaturedLink } from 'components/context/ProductLandingContext'
7+
import { FeaturedLink } from 'src/landings/components/ProductLandingContext'
88
import { useMainContext } from 'components/context/MainContext'
99
import { TruncateLines } from 'components/ui/TruncateLines'
1010
import { BumpLink } from 'components/ui/BumpLink'

components/landing/CommunityExamples.tsx renamed to src/landings/components/CommunityExamples.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useState } from 'react'
22
import { ArrowRightIcon } from '@primer/octicons-react'
33

4-
import { useProductLandingContext } from 'components/context/ProductLandingContext'
4+
import { useProductLandingContext } from 'src/landings/components/ProductLandingContext'
55
import { useTranslation } from 'components/hooks/useTranslation'
6-
import { RepoCard } from 'components/landing/RepoCard'
6+
import { RepoCard } from 'src/landings/components/RepoCard'
77

88
export const CommunityExamples = () => {
99
const { productCommunityExamples } = useProductLandingContext()

0 commit comments

Comments
 (0)