From daed502d954ca14ce324c074bbc96794547b8dc0 Mon Sep 17 00:00:00 2001 From: Shu Uesugi Date: Mon, 6 Apr 2020 22:02:55 -0700 Subject: [PATCH] Use matterResult --- api-routes-starter/lib/posts.js | 10 +++++----- basics-final/lib/posts.js | 10 +++++----- dynamic-routes-starter/lib/posts.js | 6 +++--- typescript-starter/lib/posts.js | 10 +++++----- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/api-routes-starter/lib/posts.js b/api-routes-starter/lib/posts.js index db08438..53d8653 100644 --- a/api-routes-starter/lib/posts.js +++ b/api-routes-starter/lib/posts.js @@ -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 } } diff --git a/basics-final/lib/posts.js b/basics-final/lib/posts.js index db08438..53d8653 100644 --- a/basics-final/lib/posts.js +++ b/basics-final/lib/posts.js @@ -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 } } diff --git a/dynamic-routes-starter/lib/posts.js b/dynamic-routes-starter/lib/posts.js index 03af1cf..46d820c 100644 --- a/dynamic-routes-starter/lib/posts.js +++ b/dynamic-routes-starter/lib/posts.js @@ -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 diff --git a/typescript-starter/lib/posts.js b/typescript-starter/lib/posts.js index db08438..53d8653 100644 --- a/typescript-starter/lib/posts.js +++ b/typescript-starter/lib/posts.js @@ -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 } }