forked from github/docs
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow a category landing page for Copilot Cookbook (#53002)
- Loading branch information
1 parent
90e0168
commit 2d14549
Showing
5 changed files
with
162 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import pick from 'lodash/pick' | ||
import { createContext, useContext } from 'react' | ||
import { LearningTrack } from './ArticleContext' | ||
import { | ||
FeaturedLink, | ||
getFeaturedLinksFromReq, | ||
} from 'src/landings/components/ProductLandingContext' | ||
|
||
export type TocItem = { | ||
fullPath: string | ||
title: string | ||
intro?: string | ||
childTocItems?: Array<{ | ||
fullPath: string | ||
title: string | ||
intro: string | ||
}> | ||
} | ||
|
||
export type CategoryLandingContextT = { | ||
title: string | ||
intro: string | ||
productCallout: string | ||
permissions: string | ||
tocItems: Array<TocItem> | ||
variant?: 'compact' | 'expanded' | ||
featuredLinks: Record<string, Array<FeaturedLink>> | ||
renderedPage: string | ||
currentLearningTrack?: LearningTrack | ||
currentLayout: string | ||
} | ||
|
||
export const CategoryLandingContext = createContext<CategoryLandingContextT | null>(null) | ||
|
||
export const useCategoryLandingContext = (): CategoryLandingContextT => { | ||
const context = useContext(CategoryLandingContext) | ||
|
||
if (!context) { | ||
throw new Error( | ||
'"useCategoryLandingContext" may only be used inside "CategoryLandingContext.Provider"', | ||
) | ||
} | ||
|
||
return context | ||
} | ||
|
||
export const getCategoryLandingContextFromRequest = (req: any): CategoryLandingContextT => { | ||
return { | ||
title: req.context.page.title, | ||
productCallout: req.context.page.product || '', | ||
permissions: req.context.page.permissions || '', | ||
intro: req.context.page.intro, | ||
tocItems: (req.context.genericTocFlat || req.context.genericTocNested || []).map((obj: any) => | ||
pick(obj, ['fullPath', 'title', 'intro', 'childTocItems']), | ||
), | ||
variant: req.context.genericTocFlat ? 'expanded' : 'compact', | ||
featuredLinks: getFeaturedLinksFromReq(req), | ||
renderedPage: req.context.renderedPage, | ||
currentLearningTrack: req.context.currentLearningTrack, | ||
currentLayout: req.context.currentLayoutName, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ const layoutNames = [ | |
'product-guides', | ||
'release-notes', | ||
'inline', | ||
'category-landing', | ||
false, | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { useRouter } from 'next/router' | ||
import cx from 'classnames' | ||
|
||
import { useCategoryLandingContext } from 'src/frame/components/context/CategoryLandingContext' | ||
import { DefaultLayout } from 'src/frame/components/DefaultLayout' | ||
import { ArticleTitle } from 'src/frame/components/article/ArticleTitle' | ||
import { Lead } from 'src/frame/components/ui/Lead' | ||
import { ClientSideRedirects } from 'src/rest/components/ClientSideRedirects' | ||
import { RestRedirect } from 'src/rest/components/RestRedirect' | ||
import { Breadcrumbs } from 'src/frame/components/page-header/Breadcrumbs' | ||
|
||
export const CategoryLanding = () => { | ||
const router = useRouter() | ||
const { title, intro, tocItems } = useCategoryLandingContext() | ||
|
||
// tocItems contains directories and its children, we only want the child articles | ||
const onlyFlatItems = tocItems.flatMap((item) => item.childTocItems || []) | ||
|
||
return ( | ||
<DefaultLayout> | ||
{router.route === '/[versionId]/rest/[category]' && <RestRedirect />} | ||
{/* Doesn't matter *where* this is included because it will | ||
never render anything. It always just return null. */} | ||
<ClientSideRedirects /> | ||
|
||
<div className="container-xl px-3 px-md-6 my-4"> | ||
<div className={cx('d-none d-xl-block mt-3 mr-auto width-full')}> | ||
<Breadcrumbs /> | ||
</div> | ||
<ArticleTitle>{title}</ArticleTitle> | ||
|
||
{intro && <Lead data-search="lead">{intro}</Lead>} | ||
|
||
<h2 className="py-5">Spotlight</h2> | ||
<div className="container-lg clearfix"> | ||
<div className="col-4 float-left border p-4">Spotlight 1</div> | ||
<div className="col-4 float-left border p-4">Spotlight 2</div> | ||
<div className="col-4 float-left border p-4">Spotlight 3</div> | ||
</div> | ||
|
||
<div className="pt-8"> | ||
<div className="py-5 clearfix border-bottom"> | ||
<div className="col-5 float-left p-3"> | ||
<h2>Explore {onlyFlatItems.length} prompt articles</h2> | ||
</div> | ||
<div className="col-3 float-left p-4">Searchbar</div> | ||
<div className="col-1 float-left p-4">Category</div> | ||
<div className="col-1 float-left p-4">Complexity</div> | ||
<div className="col-1 float-left p-4">Industry</div> | ||
<div className="col-1 float-left p-4">Reset</div> | ||
</div> | ||
<div className="clearfix gutter-md-spacious"> | ||
{/* TODO: replace with card components */} | ||
{onlyFlatItems.map((item, index) => ( | ||
<div key={index} className="col-4 float-left p-4"> | ||
<div className="px-3 pb-3 border-bottom"> | ||
<div>{item.title}</div> | ||
<div>{item.intro}</div> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
</DefaultLayout> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters