Skip to content

Commit

Permalink
✨ Revalidate newsroom pages #2657
Browse files Browse the repository at this point in the history
  • Loading branch information
padms committed Dec 9, 2024
1 parent 5bdfff1 commit 9ac3b26
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions web/pages/api/revalidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export default async function handler(req, res) {
})
}

const revalidateNewsroomPages = async () => {
console.log(new Date(), 'Revalidating: /news')
res.revalidate(`/news`)
console.log(new Date(), 'Revalidating: /no/nyheter')
res.revalidate('/no/nyheter')
}

if (['page', 'landingPage', 'event'].includes(data._type)) {
const routes = await sanityClient.fetch(
groq`*[_type match "route_*" && content._ref == $id]{"slug": slug.current}`,
Expand All @@ -53,6 +60,8 @@ export default async function handler(req, res) {
console.log(new Date(), 'Revalidating: ', data?.slug)
if (data.slug) await res.revalidate(data.slug)
await revalidateHomePages()
// revalidate newsroom pages
if (data._type === 'news') await revalidateNewsroomPages()
return res.json({ revalidated: true, slug: data.slug })
}
} catch (err) {
Expand Down

0 comments on commit 9ac3b26

Please sign in to comment.