[refactor][xs]: rename docs directory to site reflecting fact this is the full website.
This commit is contained in:
52
site/pages/docs/[[...id]].js
Normal file
52
site/pages/docs/[[...id]].js
Normal file
@@ -0,0 +1,52 @@
|
||||
import path from 'path'
|
||||
import * as fs from 'fs'
|
||||
import Link from 'next/link'
|
||||
|
||||
import Layout from '../../components/layout'
|
||||
import Prose from '../../components/prose'
|
||||
import { formatMD } from '../../lib/utils'
|
||||
|
||||
export default function Docs({ title, mdFile }) {
|
||||
return (
|
||||
<Layout title="Portal.js Documentation - {title}">
|
||||
<Prose mdFile={mdFile}>
|
||||
</Prose>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
const postsDirectory = 'markdowns/docs'
|
||||
|
||||
export async function getStaticProps({params}) {
|
||||
const postId = params.id ? params.id : 'index'
|
||||
const mdFilePath = path.join(postsDirectory, postId + '.md')
|
||||
const mdFile = await formatMD(mdFilePath)
|
||||
return {
|
||||
props: {
|
||||
mdFile
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const fileNames = fs.readdirSync(postsDirectory)
|
||||
const paths = fileNames.map(fileName => {
|
||||
if (fileName == 'index.md') {
|
||||
return {
|
||||
params: {
|
||||
id: null
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
params: {
|
||||
id: [ fileName.replace(/\.md$/, '') ]
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
return {
|
||||
paths: paths,
|
||||
fallback: false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user