apophis51 / next-js-Portfolio

https://next-js-portfolio-mauve.vercel.app
2 stars 2 forks source link

Blog URls need to end in the /title and not the /# #113

Closed apophis51 closed 11 months ago

apophis51 commented 11 months ago

We need to generate urls as /ProgrammingBlogs/how-to-edit-your-css-with-react-markdown instead of /ProgrammingBlogs/3

apophis51 commented 11 months ago

we fixed by changing the old ProgrammingBlogs.page code from:

// async function generateStaticParams(params) {
//   const res = await fetch(`https://malcmind-strapi-cms-production.up.railway.app/api/programming-blogs/${params.id}`)
//   const post = await res.json()
//   console.log(post)

//   return post
// }

to

async function generateStaticParams(params) {
  let res = await fetch(`https://malcmind-strapi-cms-production.up.railway.app/api/programming-blogs/`)
  let post = await res.json()
  let blogID = ''
  for (let x of post.data){
    if (x.attributes.Title.toLowerCase().split(' ').join('-').includes(params.id)){
      blogID = x.id
    }
  }
   res = await fetch(`https://malcmind-strapi-cms-production.up.railway.app/api/programming-blogs/${blogID}`)
    post = await res.json()
  return post
}

Also the calling function in BlogCollection was changed from blogLink = {"/ProgrammingBlogs/${item.id}"} to blogLink = {/ProgrammingBlogs/${(item.attributes.Title).toLowerCase().split(' ').join('-')}}