import fs from "fs" ; import path from "path" ; import matter from "gray-matter" ; import { generateReadingTime } from "./helpers" ; const FILENAME_SUBSTRING = 11 ; const postDirectory = path . join ( process . cwd ( ) , "_blog" ) ; export const getAllPostSlugs = ( directory ) => { const directoryProcess = path . join ( process . cwd ( ) , directory ) ; const fileNames = fs . readdirSync ( directoryProcess ) ; return fileNames . map ( ( filename ) => { return { params : { slug : filename . replace ( ".mdx" , "" ) , } , } ; } ) ; } ; export const getPostdata = async ( slug , directory ) => { const fullPath = path . join ( postDirectory , `${ slug }.mdx` ) ; const postContent = fs . readFileSync ( fullPath , "utf8" ) ; return postContent ; } ; const getDatesFromFileName = ( filename ) => { const year = filename . substring ( 0 , 4 ) ; const month = filename . substring ( 5 , 7 ) ; const day = filename . substring ( 8 , 10 ) ; return { year , month , day , } ; } ;