Use a spotlight frontmatter property for category landing pages (#53443)
This commit is contained in:
@@ -14,4 +14,11 @@ children:
|
|||||||
- /documenting-code
|
- /documenting-code
|
||||||
- /testing-code
|
- /testing-code
|
||||||
- /security-analysis
|
- /security-analysis
|
||||||
|
spotlight:
|
||||||
|
- article: /testing-code/generate-unit-tests
|
||||||
|
image: /assets/images/copilot-landing/generating_unit_tests.png
|
||||||
|
- article: /refactoring-code/improving-code-readability-and-maintainability
|
||||||
|
image: /assets/images/copilot-landing/improving_code_readability.png
|
||||||
|
- article: /debugging-errors/debugging-invalid-json
|
||||||
|
image: /assets/images/copilot-landing/debugging_invalid_json.png
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
FeaturedLink,
|
FeaturedLink,
|
||||||
getFeaturedLinksFromReq,
|
getFeaturedLinksFromReq,
|
||||||
} from 'src/landings/components/ProductLandingContext'
|
} from 'src/landings/components/ProductLandingContext'
|
||||||
import { TocItem } from '#src/landings/types.ts'
|
import { TocItem, Spotlight } from '#src/landings/types.ts'
|
||||||
|
|
||||||
export type CategoryLandingContextT = {
|
export type CategoryLandingContextT = {
|
||||||
title: string
|
title: string
|
||||||
@@ -18,6 +18,7 @@ export type CategoryLandingContextT = {
|
|||||||
renderedPage: string
|
renderedPage: string
|
||||||
currentLearningTrack?: LearningTrack
|
currentLearningTrack?: LearningTrack
|
||||||
currentLayout: string
|
currentLayout: string
|
||||||
|
currentSpotlight: Array<Spotlight>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CategoryLandingContext = createContext<CategoryLandingContextT | null>(null)
|
export const CategoryLandingContext = createContext<CategoryLandingContextT | null>(null)
|
||||||
@@ -48,5 +49,6 @@ export const getCategoryLandingContextFromRequest = (req: any): CategoryLandingC
|
|||||||
renderedPage: req.context.renderedPage,
|
renderedPage: req.context.renderedPage,
|
||||||
currentLearningTrack: req.context.currentLearningTrack,
|
currentLearningTrack: req.context.currentLearningTrack,
|
||||||
currentLayout: req.context.currentLayoutName,
|
currentLayout: req.context.currentLayoutName,
|
||||||
|
currentSpotlight: req.context.page.spotlight,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,6 +262,22 @@ export const schema = {
|
|||||||
octicon: {
|
octicon: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
},
|
},
|
||||||
|
spotlight: {
|
||||||
|
type: 'array',
|
||||||
|
minItems: 3,
|
||||||
|
maxItems: 3,
|
||||||
|
items: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
article: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
image: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
// END category landing tags
|
// END category landing tags
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,12 @@ import { DefaultLayout } from 'src/frame/components/DefaultLayout'
|
|||||||
import { ArticleTitle } from 'src/frame/components/article/ArticleTitle'
|
import { ArticleTitle } from 'src/frame/components/article/ArticleTitle'
|
||||||
import { Lead } from 'src/frame/components/ui/Lead'
|
import { Lead } from 'src/frame/components/ui/Lead'
|
||||||
import { useCategoryLandingContext } from 'src/frame/components/context/CategoryLandingContext'
|
import { useCategoryLandingContext } from 'src/frame/components/context/CategoryLandingContext'
|
||||||
import { ClientSideRedirects } from 'src/rest/components/ClientSideRedirects'
|
|
||||||
import { RestRedirect } from 'src/rest/components/RestRedirect'
|
|
||||||
import { Breadcrumbs } from 'src/frame/components/page-header/Breadcrumbs'
|
import { Breadcrumbs } from 'src/frame/components/page-header/Breadcrumbs'
|
||||||
import { ArticleCardItems } from 'src/landings/types'
|
import { ArticleCardItems } from 'src/landings/types'
|
||||||
|
|
||||||
export const CategoryLanding = () => {
|
export const CategoryLanding = () => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { title, intro, tocItems } = useCategoryLandingContext()
|
const { title, intro, tocItems, currentSpotlight } = useCategoryLandingContext()
|
||||||
|
|
||||||
// tocItems contains directories and its children, we only want the child articles
|
// tocItems contains directories and its children, we only want the child articles
|
||||||
const onlyFlatItems: ArticleCardItems = tocItems.flatMap((item) => item.childTocItems || [])
|
const onlyFlatItems: ArticleCardItems = tocItems.flatMap((item) => item.childTocItems || [])
|
||||||
@@ -72,11 +70,6 @@ export const CategoryLanding = () => {
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<DefaultLayout>
|
<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="container-xl px-3 px-md-6 my-4">
|
||||||
<div className={cx('d-none d-xl-block mt-3 mr-auto width-full')}>
|
<div className={cx('d-none d-xl-block mt-3 mr-auto width-full')}>
|
||||||
<Breadcrumbs />
|
<Breadcrumbs />
|
||||||
@@ -86,36 +79,39 @@ export const CategoryLanding = () => {
|
|||||||
|
|
||||||
<h2 className="py-5">Spotlight</h2>
|
<h2 className="py-5">Spotlight</h2>
|
||||||
<div className="d-md-flex d-sm-block col-md-12">
|
<div className="d-md-flex d-sm-block col-md-12">
|
||||||
<div className="col-md-4">
|
{
|
||||||
<CookBookArticleCard
|
// The articles in the spotlight should be contained within the page's children. If not, we throw.
|
||||||
image={'/assets/images/copilot-landing/generating_unit_tests.png'}
|
currentSpotlight.map((spotlightItem, index) => {
|
||||||
title="Generate unit tests"
|
const matchedItem = onlyFlatItems.find((item) =>
|
||||||
description="Copilot Chat can help with generating unit tests for a function."
|
item.fullPath.endsWith(spotlightItem.article),
|
||||||
spotlight={true}
|
)
|
||||||
url="/en/copilot/example-prompts-for-github-copilot-chat/testing-code/generate-unit-tests"
|
if (
|
||||||
tags={[]}
|
!matchedItem ||
|
||||||
/>
|
!matchedItem.title ||
|
||||||
</div>
|
!matchedItem.intro ||
|
||||||
<div className="col-md-4">
|
!matchedItem.fullPath
|
||||||
<CookBookArticleCard
|
) {
|
||||||
image={'/assets/images/copilot-landing/improving_code_readability.png'}
|
throw new Error(
|
||||||
title="Improving code readability and maintainability"
|
`Couldn't find the articles defined in the spotlight region defined for ${router.asPath}. Check that page's spotlight frontmater property.`,
|
||||||
description="Learn how to improve your code readability and maintainability."
|
)
|
||||||
spotlight={true}
|
}
|
||||||
url="/en/copilot/example-prompts-for-github-copilot-chat/refactoring-code/improving-code-readability-and-maintainability"
|
|
||||||
tags={[]}
|
// A missing image is possible, in that case the CookBookArticleCard component can handle a placeholder at a future iteration.
|
||||||
/>
|
return (
|
||||||
</div>
|
<div className="col-md-4">
|
||||||
<div className="col-md-4">
|
<CookBookArticleCard
|
||||||
<CookBookArticleCard
|
key={index}
|
||||||
image={'/assets/images/copilot-landing/debugging_invalid_json.png'}
|
image={spotlightItem.image}
|
||||||
title="Debugging invalid JSON"
|
title={matchedItem.title}
|
||||||
description="Copilot can identify and resolve syntax errors or structural issues in JSON data."
|
description={matchedItem.intro}
|
||||||
spotlight={true}
|
spotlight={true}
|
||||||
tags={[]}
|
url={matchedItem.fullPath}
|
||||||
url="/en/copilot/example-prompts-for-github-copilot-chat/debugging-errors/debugging-invalid-json"
|
tags={[]}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="pt-8">
|
<div className="pt-8">
|
||||||
|
|||||||
@@ -27,3 +27,8 @@ export type TocItem = BaseTocItem & {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type ArticleCardItems = ChildTocItem[]
|
export type ArticleCardItems = ChildTocItem[]
|
||||||
|
|
||||||
|
export type Spotlight = {
|
||||||
|
article: string
|
||||||
|
image: string
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user