[site/docs][m]: refactor docs section to live at docs and use dynamic routes.
* This way adding new pages is just adding new markdown in markdowns folder (rather than having to create both markdown and a js file). * Also renamed markdowns subfolder for docs stuff from api-doc to docs.
This commit is contained in:
parent
bb202e1828
commit
5185349829
@ -1,31 +0,0 @@
|
||||
import Link from 'next/link'
|
||||
import path from 'path'
|
||||
|
||||
import Layout from '../components/layout'
|
||||
import Prose from '../components/prose'
|
||||
import { formatMD } from '../lib/utils'
|
||||
|
||||
export default function Docs({ mdFile }) {
|
||||
return (
|
||||
<Layout title="Portal.js API Documentation">
|
||||
<Prose mdFile={mdFile}>
|
||||
<p className="text-center">
|
||||
<Link href="/components">
|
||||
<button>Next Page</button>
|
||||
</Link>
|
||||
</p>
|
||||
</Prose>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
export async function getStaticProps() {
|
||||
const mdFilePath = path.join(process.cwd(), "markdowns/api-doc/installation.md")
|
||||
const mdFile = await formatMD(mdFilePath)
|
||||
return {
|
||||
props: {
|
||||
mdFile
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
import Link from 'next/link'
|
||||
import path from 'path'
|
||||
|
||||
import Layout from '../components/layout'
|
||||
import Prose from '../components/prose'
|
||||
import { formatMD } from '../lib/utils'
|
||||
|
||||
export default function Docs({ mdFile }) {
|
||||
return (
|
||||
<Layout title="Portal.js API Documentation">
|
||||
<Prose mdFile={mdFile}>
|
||||
<p className="text-center">
|
||||
<Link href="/installation">
|
||||
<button>Next Page</button>
|
||||
</Link>
|
||||
</p>
|
||||
</Prose>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
export async function getStaticProps() {
|
||||
const mdFilePath = path.join(process.cwd(), "markdowns/api-doc/introduction.md")
|
||||
const mdFile = await formatMD(mdFilePath)
|
||||
return {
|
||||
props: {
|
||||
mdFile
|
||||
}
|
||||
}
|
||||
}
|
||||
57
docs/pages/docs/[[...id]].js
Normal file
57
docs/pages/docs/[[...id]].js
Normal file
@ -0,0 +1,57 @@
|
||||
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}>
|
||||
<p className="text-center">
|
||||
<Link href="/installation">
|
||||
<button>Next Page</button>
|
||||
</Link>
|
||||
</p>
|
||||
</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
|
||||
}
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
import Link from 'next/link'
|
||||
import path from 'path'
|
||||
|
||||
import Layout from '../components/layout'
|
||||
import Prose from '../components/prose'
|
||||
import { formatMD } from '../lib/utils'
|
||||
|
||||
export default function Docs({ mdFile }) {
|
||||
return (
|
||||
<Layout title="Portal.js Installation">
|
||||
<Prose mdFile={mdFile}>
|
||||
<p className="text-center">
|
||||
<Link href="/references">
|
||||
<button>Next Page</button>
|
||||
</Link>
|
||||
</p>
|
||||
</Prose>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
export async function getStaticProps() {
|
||||
const mdFilePath = path.join(process.cwd(), "markdowns/api-doc/installation.md")
|
||||
const mdFile = await formatMD(mdFilePath)
|
||||
return {
|
||||
props: {
|
||||
mdFile
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
import Link from 'next/link'
|
||||
import path from 'path'
|
||||
|
||||
import Layout from '../components/layout'
|
||||
import Prose from '../components/prose'
|
||||
import { formatMD } from '../lib/utils'
|
||||
|
||||
export default function Docs({ mdFile }) {
|
||||
return (
|
||||
<Layout title="Portal.js Reference Documentation">
|
||||
<Prose mdFile={mdFile}>
|
||||
</Prose>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function getStaticProps() {
|
||||
const mdFilePath = path.join(process.cwd(), "markdowns/api-doc/references.md")
|
||||
const mdFile = await formatMD(mdFilePath)
|
||||
return {
|
||||
props: {
|
||||
mdFile
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user