Skip to content

Commit

Permalink
Merge pull request #3844 from owid/redirect-creation
Browse files Browse the repository at this point in the history
🐛 fix redirects from draft gdoc deletion
  • Loading branch information
ikesau authored Aug 5, 2024
2 parents 0fca7e2 + 75edba8 commit 5f7b971
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions adminSiteServer/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2279,13 +2279,19 @@ deleteRouteWithRWTransaction(apiRouter, "/gdocs/:id", async (req, res, trx) => {
// Assets have TTL of one week in Cloudflare. Add a redirect to make sure
// the page is no longer accessible.
// https://developers.cloudflare.com/pages/configuration/serving-pages/#asset-retention
await db.knexRawInsert(
trx,
`INSERT INTO redirects (source, target, ttl)
VALUES (?, ?, DATE_ADD(NOW(), INTERVAL 8 DAY))`,
[getCanonicalUrl("", gdoc), "/"]
)
await triggerStaticBuild(res.locals.user, `Deleting ${gdoc.slug}`)
const gdocSlug = getCanonicalUrl("", gdoc)
if (gdoc.published) {
if (gdocSlug && gdocSlug !== "/") {
console.log(`Creating redirect for "${gdocSlug}" to "/"`)
await db.knexRawInsert(
trx,
`INSERT INTO redirects (source, target, ttl)
VALUES (?, ?, DATE_ADD(NOW(), INTERVAL 8 DAY))`,
[gdocSlug, "/"]
)
}
await triggerStaticBuild(res.locals.user, `Deleting ${gdocSlug}`)
}
return {}
})

Expand Down

0 comments on commit 5f7b971

Please sign in to comment.