未验证 提交 5b1be2bb 编写于 作者: G Greg Rickaby 提交者: GitHub

(docs) Fixes for "Migrating from Gatsby" doc (#17858)

Noticed there's an extra backslash in the example which causes an error. 

**EDIT:**

Also the promise needs to be resolved using `.toString()` before it can be returned as `content` in props.
上级 7f798215
......@@ -84,10 +84,10 @@ import { getPostBySlug, getAllPosts } from '../lib/blog'
export async function getStaticProps({ params }) {
const post = getPostBySlug(params.slug)
const content = await remark()
const markdown = await remark()
.use(html)
.process(post.content || '')
.toString()
const content = markdown.toString()
return {
props: {
......@@ -128,7 +128,7 @@ import { join } from 'path'
const postsDirectory = join(process.cwd(), 'src', 'content', 'blog')
export function getPostBySlug(slug) {
const realSlug = slug.replace(/\\.md$/, '')
const realSlug = slug.replace(/\.md$/, '')
const fullPath = join(postsDirectory, `${realSlug}.md`)
const fileContents = fs.readFileSync(fullPath, 'utf8')
const { data, content } = matter(fileContents)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册