mirror of
https://github.com/vercel/next-learn.git
synced 2026-06-11 09:51:47 +00:00
Use matterResult
This commit is contained in:
@@ -18,12 +18,12 @@ export function getSortedPostsData() {
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8')
|
||||
|
||||
// Use gray-matter to parse the post metadata section
|
||||
const { data } = matter(fileContents)
|
||||
const matterResult = matter(fileContents)
|
||||
|
||||
// Combine the data with the id
|
||||
return {
|
||||
id,
|
||||
...data
|
||||
...matterResult.data
|
||||
}
|
||||
})
|
||||
// Sort posts by date
|
||||
@@ -52,18 +52,18 @@ export async function getPostData(id) {
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8')
|
||||
|
||||
// Use gray-matter to parse the post metadata section
|
||||
const { data, content } = matter(fileContents)
|
||||
const matterResult = matter(fileContents)
|
||||
|
||||
// Use remark to convert markdown into HTML string
|
||||
const processedContent = await remark()
|
||||
.use(html)
|
||||
.process(content)
|
||||
.process(matterResult.content)
|
||||
const contentHtml = processedContent.toString()
|
||||
|
||||
// Combine the data with the id and contentHtml
|
||||
return {
|
||||
id,
|
||||
contentHtml,
|
||||
...data
|
||||
...matterResult.data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ export function getSortedPostsData() {
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8')
|
||||
|
||||
// Use gray-matter to parse the post metadata section
|
||||
const { data } = matter(fileContents)
|
||||
const matterResult = matter(fileContents)
|
||||
|
||||
// Combine the data with the id
|
||||
return {
|
||||
id,
|
||||
...data
|
||||
...matterResult.data
|
||||
}
|
||||
})
|
||||
// Sort posts by date
|
||||
@@ -52,18 +52,18 @@ export async function getPostData(id) {
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8')
|
||||
|
||||
// Use gray-matter to parse the post metadata section
|
||||
const { data, content } = matter(fileContents)
|
||||
const matterResult = matter(fileContents)
|
||||
|
||||
// Use remark to convert markdown into HTML string
|
||||
const processedContent = await remark()
|
||||
.use(html)
|
||||
.process(content)
|
||||
.process(matterResult.content)
|
||||
const contentHtml = processedContent.toString()
|
||||
|
||||
// Combine the data with the id and contentHtml
|
||||
return {
|
||||
id,
|
||||
contentHtml,
|
||||
...data
|
||||
...matterResult.data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ const postsDirectory = path.join(process.cwd(), 'posts')
|
||||
export function getSortedPostsData() {
|
||||
// Get file names under /posts
|
||||
const fileNames = fs.readdirSync(postsDirectory)
|
||||
const allPostsData = fileNames.map((fileName) => {
|
||||
const allPostsData = fileNames.map(fileName => {
|
||||
// Remove ".md" from file name to get id
|
||||
const id = fileName.replace(/\.md$/, '')
|
||||
|
||||
@@ -16,12 +16,12 @@ export function getSortedPostsData() {
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8')
|
||||
|
||||
// Use gray-matter to parse the post metadata section
|
||||
const { data } = matter(fileContents)
|
||||
const matterResult = matter(fileContents)
|
||||
|
||||
// Combine the data with the id
|
||||
return {
|
||||
id,
|
||||
...data,
|
||||
...matterResult.data
|
||||
}
|
||||
})
|
||||
// Sort posts by date
|
||||
|
||||
@@ -18,12 +18,12 @@ export function getSortedPostsData() {
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8')
|
||||
|
||||
// Use gray-matter to parse the post metadata section
|
||||
const { data } = matter(fileContents)
|
||||
const matterResult = matter(fileContents)
|
||||
|
||||
// Combine the data with the id
|
||||
return {
|
||||
id,
|
||||
...data
|
||||
...matterResult.data
|
||||
}
|
||||
})
|
||||
// Sort posts by date
|
||||
@@ -52,18 +52,18 @@ export async function getPostData(id) {
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8')
|
||||
|
||||
// Use gray-matter to parse the post metadata section
|
||||
const { data, content } = matter(fileContents)
|
||||
const matterResult = matter(fileContents)
|
||||
|
||||
// Use remark to convert markdown into HTML string
|
||||
const processedContent = await remark()
|
||||
.use(html)
|
||||
.process(content)
|
||||
.process(matterResult.content)
|
||||
const contentHtml = processedContent.toString()
|
||||
|
||||
// Combine the data with the id and contentHtml
|
||||
return {
|
||||
id,
|
||||
contentHtml,
|
||||
...data
|
||||
...matterResult.data
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user