feat: implement SEO enhancements, automatic slug generation, and font optimizations
All checks were successful
Build and Push App / build (push) Successful in 9m12s
All checks were successful
Build and Push App / build (push) Successful in 9m12s
This commit is contained in:
46
scripts/backfill-slugs.ts
Normal file
46
scripts/backfill-slugs.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import prisma from '../lib/prisma'
|
||||
import { generateSlug } from '../lib/utils'
|
||||
|
||||
async function main() {
|
||||
const posts = await prisma.blogPost.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{ slug: null },
|
||||
{ slug: '' }
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
console.log(`Found ${posts.length} posts without slug.`)
|
||||
|
||||
for (const post of posts) {
|
||||
const newSlug = generateSlug(post.title)
|
||||
|
||||
// Handle potential duplicates
|
||||
let slug = newSlug
|
||||
let count = 1
|
||||
let unique = false
|
||||
|
||||
while (!unique) {
|
||||
const existing = await prisma.blogPost.findUnique({ where: { slug } })
|
||||
if (!existing || existing.id === post.id) {
|
||||
unique = true
|
||||
} else {
|
||||
slug = `${newSlug}-${count}`
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.blogPost.update({
|
||||
where: { id: post.id },
|
||||
data: { slug }
|
||||
})
|
||||
console.log(`Updated post: ${post.title} -> ${slug}`)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.catch(console.error)
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect()
|
||||
})
|
||||
Reference in New Issue
Block a user