Feat/sub-route (#38)
* blog subroute support * docs: update readme and blog Co-authored-by: mrhut10 <ahut10@gmail.com>
This commit is contained in:
@ -1,18 +1,17 @@
|
||||
import fs from 'fs'
|
||||
import hydrate from 'next-mdx-remote/hydrate'
|
||||
import { getFiles, getFileBySlug, getAllFilesFrontMatter, formatSlug } from '@/lib/mdx'
|
||||
import PostLayout from '@/layouts/PostLayout'
|
||||
import MDXComponents from '@/components/MDXComponents'
|
||||
import PageTitle from '@/components/PageTitle'
|
||||
import PostLayout from '@/layouts/PostLayout'
|
||||
import generateRss from '@/lib/generate-rss'
|
||||
import { formatSlug, getAllFilesFrontMatter, getFileBySlug, getFiles } from '@/lib/mdx'
|
||||
import fs from 'fs'
|
||||
import hydrate from 'next-mdx-remote/hydrate'
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await getFiles('blog')
|
||||
|
||||
const posts = getFiles('blog')
|
||||
return {
|
||||
paths: posts.map((p) => ({
|
||||
params: {
|
||||
slug: formatSlug(p),
|
||||
slug: formatSlug(p).split('/'),
|
||||
},
|
||||
})),
|
||||
fallback: false,
|
||||
@ -21,7 +20,7 @@ export async function getStaticPaths() {
|
||||
|
||||
export async function getStaticProps({ params }) {
|
||||
const allPosts = await getAllFilesFrontMatter('blog')
|
||||
const postIndex = allPosts.findIndex((post) => post.slug === params.slug)
|
||||
const postIndex = allPosts.findIndex((post) => formatSlug(post.slug) === params.slug.join('/'))
|
||||
const prev = allPosts[postIndex + 1] || null
|
||||
const next = allPosts[postIndex - 1] || null
|
||||
const post = await getFileBySlug('blog', params.slug)
|
@ -1,9 +1,9 @@
|
||||
import siteMetadata from '@/data/siteMetadata'
|
||||
import { kebabCase } from '@/lib/utils'
|
||||
import { getAllTags } from '@/lib/tags'
|
||||
import Tag from '@/components/Tag'
|
||||
import Link from '@/components/Link'
|
||||
import { PageSeo } from '@/components/SEO'
|
||||
import Tag from '@/components/Tag'
|
||||
import siteMetadata from '@/data/siteMetadata'
|
||||
import { getAllTags } from '@/lib/tags'
|
||||
import kebabCase from '@/lib/utils/kebabCase'
|
||||
|
||||
export async function getStaticProps() {
|
||||
const tags = await getAllTags('blog')
|
||||
|
@ -1,12 +1,12 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { kebabCase } from '@/lib/utils'
|
||||
import { getAllFilesFrontMatter } from '@/lib/mdx'
|
||||
import { getAllTags } from '@/lib/tags'
|
||||
import { PageSeo } from '@/components/SEO'
|
||||
import siteMetadata from '@/data/siteMetadata'
|
||||
import ListLayout from '@/layouts/ListLayout'
|
||||
import { PageSeo } from '@/components/SEO'
|
||||
import generateRss from '@/lib/generate-rss'
|
||||
import { getAllFilesFrontMatter } from '@/lib/mdx'
|
||||
import { getAllTags } from '@/lib/tags'
|
||||
import kebabCase from '@/lib/utils/kebabCase'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
const root = process.cwd()
|
||||
|
||||
|
Reference in New Issue
Block a user