|
1 | | -import { GetStaticProps } from 'next' |
| 1 | +import path from 'path' |
2 | 2 |
|
3 | | -import TermPage, { PageProps, getStaticProps as getStaticPropsForSlug } from './[...slug]' |
| 3 | +import { GetStaticProps, NextPage } from 'next' |
| 4 | +import { MDXRemote, MDXRemoteSerializeResult } from 'next-mdx-remote' |
4 | 5 |
|
5 | | -export const getStaticProps: GetStaticProps<PageProps> = async context => |
6 | | - getStaticPropsForSlug({ ...context, params: { slug: ['index'] } }) |
| 6 | +import { Layout, Badge, HubSpotForm, TableWrapper } from '../../components' |
| 7 | +import { Page } from '../../interfaces/posts' |
| 8 | +import { loadMarkdownFile, serializeMdxSource } from '../../lib' |
| 9 | + |
| 10 | +export type Components = import('mdx/types').MDXComponents |
| 11 | + |
| 12 | +export interface PageProps { |
| 13 | + page?: Page |
| 14 | + content?: MDXRemoteSerializeResult |
| 15 | +} |
| 16 | + |
| 17 | +const CONTENT_PARENT_DIRECTORY = './content/' |
| 18 | + |
| 19 | +const components = { Badge, HubSpotForm, TableWrapper } |
| 20 | + |
| 21 | +const TermPage: NextPage<PageProps> = ({ page, content }) => { |
| 22 | + const title = page?.frontmatter.title |
| 23 | + const description = page?.frontmatter.description |
| 24 | + const image = page?.frontmatter.socialImage |
| 25 | + const videoID = page?.frontmatter.videoID |
| 26 | + const canonical = page?.frontmatter.canonical |
| 27 | + const externalTitle = page?.frontmatter.externalTitle |
| 28 | + const externalDescription = page?.frontmatter.externalDescription |
| 29 | + const meta = { |
| 30 | + title, |
| 31 | + image, |
| 32 | + videoID, |
| 33 | + description, |
| 34 | + externalTitle, |
| 35 | + externalDescription, |
| 36 | + canonical, |
| 37 | + } |
| 38 | + |
| 39 | + if (title) { |
| 40 | + meta.title = `Sourcegraph - ${title}` |
| 41 | + } |
| 42 | + |
| 43 | + return ( |
| 44 | + <Layout meta={meta}> |
| 45 | + <section className="bg-gray-200 py-8 text-center">{page && <h1>{title}</h1>}</section> |
| 46 | + <section className="mx-auto my-12 max-w-3xl"> |
| 47 | + {content && <MDXRemote {...content} components={components as Components} />} |
| 48 | + </section> |
| 49 | + </Layout> |
| 50 | + ) |
| 51 | +} |
7 | 52 |
|
8 | 53 | export default TermPage |
| 54 | + |
| 55 | +export const getStaticProps: GetStaticProps = async () => { |
| 56 | + const filePath = 'terms/cloud.md' |
| 57 | + const page = (await loadMarkdownFile(path.resolve(CONTENT_PARENT_DIRECTORY, filePath))) as Page |
| 58 | + const content = await serializeMdxSource(page.content) |
| 59 | + |
| 60 | + return { |
| 61 | + props: { |
| 62 | + page, |
| 63 | + content, |
| 64 | + }, |
| 65 | + } |
| 66 | +} |
0 commit comments