mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-04 09:57:26 +03:00 
			
		
		
		
	Add model pages
This commit is contained in:
		
							parent
							
								
									5d22487521
								
							
						
					
					
						commit
						e0ca8a0f56
					
				
							
								
								
									
										7
									
								
								website/meta/recordLanguages.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								website/meta/recordLanguages.tsx
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,7 @@
 | 
				
			||||||
 | 
					import models from './languages.json'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const recordLanguages = Object.fromEntries(
 | 
				
			||||||
 | 
					    models.languages.map((language, index) => [language.code, language])
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default recordLanguages
 | 
				
			||||||
| 
						 | 
					@ -17,9 +17,7 @@ type ApiDetails = {
 | 
				
			||||||
    trainable: string | null
 | 
					    trainable: string | null
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type PropsPage = {
 | 
					export type PropsPageBase = {
 | 
				
			||||||
    mdx: MDXRemoteSerializeResult
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * TODO: This is only here for legacy support of the old code base
 | 
					     * TODO: This is only here for legacy support of the old code base
 | 
				
			||||||
     * It should be refactort to pass the file path and page path instead.
 | 
					     * It should be refactort to pass the file path and page path instead.
 | 
				
			||||||
| 
						 | 
					@ -28,10 +26,14 @@ type PropsPage = {
 | 
				
			||||||
    sectionTitle: string | null
 | 
					    sectionTitle: string | null
 | 
				
			||||||
    theme: string | null
 | 
					    theme: string | null
 | 
				
			||||||
    section: string
 | 
					    section: string
 | 
				
			||||||
    apiDetails: ApiDetails
 | 
					 | 
				
			||||||
    isIndex: boolean
 | 
					    isIndex: boolean
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export type PropsPage = PropsPageBase & {
 | 
				
			||||||
 | 
					    mdx: MDXRemoteSerializeResult
 | 
				
			||||||
 | 
					    apiDetails: ApiDetails
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const PostPage = ({ mdx: mdx, ...props }: PropsPage) => {
 | 
					const PostPage = ({ mdx: mdx, ...props }: PropsPage) => {
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
        <Layout {...props}>
 | 
					        <Layout {...props}>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										59
									
								
								website/pages/models/[slug].tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								website/pages/models/[slug].tsx
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,59 @@
 | 
				
			||||||
 | 
					import type { GetStaticPaths, GetStaticProps } from 'next'
 | 
				
			||||||
 | 
					import models from '../../meta/languages.json'
 | 
				
			||||||
 | 
					import recordSection from '../../meta/recordSections'
 | 
				
			||||||
 | 
					import recordLanguages from '../../meta/recordLanguages'
 | 
				
			||||||
 | 
					import Layout from '../../src/components/layout'
 | 
				
			||||||
 | 
					import { PropsPageBase } from '../[...listPath]'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PropsPageModel = PropsPageBase & {
 | 
				
			||||||
 | 
					    next: { title: string; slug: string } | null
 | 
				
			||||||
 | 
					    meta: { models?: ReadonlyArray<string>; example?: string; hasExamples?: boolean }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const PostPageModel = (props: PropsPageModel) => {
 | 
				
			||||||
 | 
					    return <Layout {...props} />
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default PostPageModel
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const getStaticPaths: GetStaticPaths<{ slug: string }> = async () => {
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					        paths: models.languages
 | 
				
			||||||
 | 
					            .filter(({ models }) => models && models.length)
 | 
				
			||||||
 | 
					            .map((language) => `/models/${language.code}`),
 | 
				
			||||||
 | 
					        fallback: false,
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const getStaticProps: GetStaticProps<
 | 
				
			||||||
 | 
					    PropsPageModel,
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        slug: string
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					> = async (args) => {
 | 
				
			||||||
 | 
					    if (args.params === undefined) {
 | 
				
			||||||
 | 
					        return { notFound: true }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const language = recordLanguages[args.params.slug]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					        props: {
 | 
				
			||||||
 | 
					            id: language.code,
 | 
				
			||||||
 | 
					            slug: `/${['models', language.code].join('/')}`,
 | 
				
			||||||
 | 
					            isIndex: false,
 | 
				
			||||||
 | 
					            title: language.name,
 | 
				
			||||||
 | 
					            section: 'models',
 | 
				
			||||||
 | 
					            sectionTitle: recordSection.models.title,
 | 
				
			||||||
 | 
					            theme: recordSection.models.theme,
 | 
				
			||||||
 | 
					            next: language.next
 | 
				
			||||||
 | 
					                ? { title: language.next.name, slug: `/models/${language.next.code}` }
 | 
				
			||||||
 | 
					                : null,
 | 
				
			||||||
 | 
					            meta: {
 | 
				
			||||||
 | 
					                models: language.models || null,
 | 
				
			||||||
 | 
					                example: language.example || null,
 | 
				
			||||||
 | 
					                hasExamples: language.has_examples || null,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user