From 57f7967936e51677092f6becb11bde2837cb661a Mon Sep 17 00:00:00 2001 From: Shu Uesugi Date: Thu, 2 Apr 2020 08:07:50 -0700 Subject: [PATCH] Use id instead of slug --- dynamic-routes-starter/lib/posts.js | 12 ++++++------ dynamic-routes-starter/pages/index.js | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dynamic-routes-starter/lib/posts.js b/dynamic-routes-starter/lib/posts.js index cdcc027..03af1cf 100644 --- a/dynamic-routes-starter/lib/posts.js +++ b/dynamic-routes-starter/lib/posts.js @@ -7,9 +7,9 @@ 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 => { - // Remove ".md" from file name to get slug - const slug = fileName.replace(/\.md$/, '') + const allPostsData = fileNames.map((fileName) => { + // Remove ".md" from file name to get id + const id = fileName.replace(/\.md$/, '') // Read markdown file as string const fullPath = path.join(postsDirectory, fileName) @@ -18,10 +18,10 @@ export function getSortedPostsData() { // Use gray-matter to parse the post metadata section const { data } = matter(fileContents) - // Combine the data with the slug + // Combine the data with the id return { - slug, - ...data + id, + ...data, } }) // Sort posts by date diff --git a/dynamic-routes-starter/pages/index.js b/dynamic-routes-starter/pages/index.js index f2dd00e..63a0257 100644 --- a/dynamic-routes-starter/pages/index.js +++ b/dynamic-routes-starter/pages/index.js @@ -24,11 +24,11 @@ const Home = ({ allPostsData }) => (

Blog