Use matterResult

This commit is contained in:
Shu Uesugi
2020-04-06 22:02:55 -07:00
parent 7ce1ffdf9d
commit daed502d95
4 changed files with 18 additions and 18 deletions

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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

View File

@@ -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
}
}