mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-07 13:44:55 +03:00
Add necessary meta data to pages
This commit is contained in:
parent
5d3826fb55
commit
90fdaf420e
5
website/meta/recordSections.tsx
Normal file
5
website/meta/recordSections.tsx
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import siteMetadata from './site.json'
|
||||||
|
|
||||||
|
const recordSections = Object.fromEntries(siteMetadata.sections.map((s) => [s.id, s]))
|
||||||
|
|
||||||
|
export default recordSections
|
|
@ -6,13 +6,30 @@ import path from 'path'
|
||||||
import Layout from '../components/layout'
|
import Layout from '../components/layout'
|
||||||
import remarkPlugins from '../plugins/index.mjs'
|
import remarkPlugins from '../plugins/index.mjs'
|
||||||
|
|
||||||
type PropsPage = {
|
import recordSection from '../meta/recordSections'
|
||||||
mdx: MDXRemoteSerializeResult
|
|
||||||
|
type ApiDetails = {
|
||||||
|
stringName: string | null
|
||||||
|
baseClass: {
|
||||||
|
title: string
|
||||||
|
slug: string
|
||||||
|
} | null
|
||||||
|
trainable: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
const PostPage = ({ mdx: mdx }: PropsPage) => {
|
type PropsPage = {
|
||||||
|
mdx: MDXRemoteSerializeResult
|
||||||
|
slug: ReadonlyArray<string>
|
||||||
|
sectionTitle: string | null
|
||||||
|
theme: string | null
|
||||||
|
section: string
|
||||||
|
apiDetails: ApiDetails
|
||||||
|
isIndex: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const PostPage = ({ mdx: mdx, ...props }: PropsPage) => {
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout {...props}>
|
||||||
<MDXRemote {...mdx} />
|
<MDXRemote {...mdx} />
|
||||||
</Layout>
|
</Layout>
|
||||||
)
|
)
|
||||||
|
@ -75,10 +92,35 @@ export const getStaticProps: GetStaticProps<PropsPage, ParsedUrlQuery> = async (
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!mdx.frontmatter) {
|
||||||
|
throw new Error(`Frontmatter missing for ${getPathWithExtension(pathFull)}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const parentFolder = pathFull.length > 1 ? pathFull[pathFull.length - 2] : null
|
||||||
|
const section = mdx.frontmatter.section ?? parentFolder
|
||||||
|
const sectionMeta = section ? recordSection[section] ?? null : null
|
||||||
|
const baseClass = null
|
||||||
|
const apiDetails: ApiDetails = {
|
||||||
|
stringName: mdx.frontmatter.api_string_name ?? null,
|
||||||
|
baseClass: baseClass
|
||||||
|
? {
|
||||||
|
title: mdx.frontmatter.title,
|
||||||
|
slug: mdx.frontmatter.api_base_class,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
trainable: mdx.frontmatter.api_trainable ?? null,
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
|
...mdx.frontmatter,
|
||||||
slug: args.params.slug,
|
slug: args.params.slug,
|
||||||
mdx,
|
mdx,
|
||||||
|
sectionTitle: sectionMeta?.title ?? null,
|
||||||
|
theme: sectionMeta?.theme ?? null,
|
||||||
|
section: section,
|
||||||
|
apiDetails: apiDetails,
|
||||||
|
isIndex: getIsIndex(args.params.slug),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user