fix(testimonials): group dots by pages on desktop and scroll by two items
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import { getPayload } from 'payload'
|
||||
import configPromise from '../src/payload.config'
|
||||
|
||||
async function run() {
|
||||
const payload = await getPayload({ config: configPromise })
|
||||
const locales = ['pl', 'de']
|
||||
|
||||
const additionalPL = [
|
||||
{
|
||||
quote: "Pełen profesjonalizm! Odzyskałem zwrot, o którym nawet nie wiedziałem, że mi przysługuje.",
|
||||
author: "Marek, Hamburg"
|
||||
},
|
||||
{
|
||||
quote: "Świetny kontakt, bezproblemowe załatwienie sprawy od początku do końca. Zdecydowanie polecam każdemu.",
|
||||
author: "Katarzyna, Frankfurt"
|
||||
},
|
||||
{
|
||||
quote: "Sprawa z Finanzamt załatwiona szybko i bez nerwów. Dziękuję za pomoc i zaangażowanie.",
|
||||
author: "Tomasz, Stuttgart"
|
||||
}
|
||||
]
|
||||
|
||||
const additionalDE = [
|
||||
{
|
||||
quote: "Volle Professionalität! Ich habe eine Rückerstattung erhalten, von der ich gar nicht wusste, dass sie mir zusteht.",
|
||||
author: "Marek, Hamburg"
|
||||
},
|
||||
{
|
||||
quote: "Toller Kontakt, reibungslose Abwicklung von Anfang bis Ende. Ich kann es jedem wärmstens empfehlen.",
|
||||
author: "Katarzyna, Frankfurt"
|
||||
},
|
||||
{
|
||||
quote: "Die Angelegenheit mit dem Finanzamt wurde schnell und ohne Stress geklärt. Vielen Dank für die Hilfe.",
|
||||
author: "Tomasz, Stuttgart"
|
||||
}
|
||||
]
|
||||
|
||||
for (const locale of locales) {
|
||||
const pages = await payload.find({ collection: 'pages', locale: locale as any, where: { slug: { equals: locale === 'pl' ? 'home' : 'home' } } })
|
||||
if (pages.docs.length > 0) {
|
||||
const doc = pages.docs[0]
|
||||
let changed = false
|
||||
const newLayout = doc.layout?.map((block: any) => {
|
||||
if (block.blockType === 'testimonials') {
|
||||
// ensure we have 6 items
|
||||
if (block.testimonials && block.testimonials.length < 6) {
|
||||
const additions = locale === 'pl' ? additionalPL : additionalDE
|
||||
block.testimonials = [...block.testimonials, ...additions.slice(0, 6 - block.testimonials.length)]
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
return block
|
||||
})
|
||||
if (changed) {
|
||||
await payload.update({
|
||||
collection: 'pages',
|
||||
id: doc.id,
|
||||
locale: locale as any,
|
||||
data: { layout: newLayout }
|
||||
})
|
||||
console.log(`Added 3 more testimonials to ${locale} home page.`)
|
||||
}
|
||||
}
|
||||
}
|
||||
process.exit(0)
|
||||
}
|
||||
run().catch(console.error)
|
||||
@@ -0,0 +1,30 @@
|
||||
import { getPayload } from 'payload'
|
||||
import configPromise from '../src/payload.config'
|
||||
|
||||
async function run() {
|
||||
const payload = await getPayload({ config: configPromise })
|
||||
const pages = await payload.find({ collection: 'pages', limit: 100 }) // fetch all locales?
|
||||
|
||||
const plPages = await payload.find({ collection: 'pages', locale: 'pl', limit: 100 })
|
||||
const dePages = await payload.find({ collection: 'pages', locale: 'de', limit: 100 })
|
||||
|
||||
console.log("=== PL ===")
|
||||
plPages.docs.forEach(page => {
|
||||
page.layout?.forEach(block => {
|
||||
if (block.blockType === 'testimonials' || block.blockType === 'testimonialsGrid') {
|
||||
console.log(`Page: ${page.slug}, Block: ${block.blockType}, Items: ${block.testimonials?.length || 0}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
console.log("=== DE ===")
|
||||
dePages.docs.forEach(page => {
|
||||
page.layout?.forEach(block => {
|
||||
if (block.blockType === 'testimonials' || block.blockType === 'testimonialsGrid') {
|
||||
console.log(`Page: ${page.slug}, Block: ${block.blockType}, Items: ${block.testimonials?.length || 0}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
process.exit(0)
|
||||
}
|
||||
run()
|
||||
Reference in New Issue
Block a user