The getStaticPaths() keeps throwing the 404 page and I'm guessing that is because of the function getAllPostIds() which is meant to return an array of objects. I'm making use of typescript, I've declared the array of objects but I'm not sure how to use the replace method on the id
interface ArrObj {
params: {
id: string;
}
}
let arrObj: ArrObj[];
export function getAllPostIds() {
const fileNames = fs.readdirSync(postsDirectory);
return fileNames.map(fileName => {
return {
params: {
id: fileName.replace(/\.md$/, '')
}
}
})
}
export function getPostData(id) {
const fullPath = path.join(postsDirectory, `${id}.md`)
const fileContents = fs.readFileSync(fullPath, 'utf8')
const matterResult = matter(fileContents)
return {
id,
...matterResult.data
}
}
export async function getStaticPaths(){
const paths = getAllPostIds();
return{
paths,
fallback: false
}
}
export async function getStaticProps({ params }) {
const postData = getPostData(params.id)
return {
props: {
postData
}
}
}