[ Home / About / Contact / WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]

/tech/ - Technical SEO

Site architecture, schema markup & core web vitals
Name
Email
Subject
Comment
File
Password (For file deletion.)

File: 1794553410782.jpg (75.12 KB, 900x1200, img_1794553403747_llt412m9.jpg)ImgOps Exif Google Yandex

12c90 No.2480

client's cms keeps dumping duplicate id fields into the same json-ld block. search console is just throwing errors because it can't parse the mess. use a quick regex filter in your build script to strip the second occurrence of @id before the final deployment. never trust the cms output directly if you're pulling from multiple api endpoints.
data.replace(/("@id":\s*"[^"]*"\s*,?){2,}/g, (match) => {return match.split(/"@id":/)[0];})

it's a stupid hack but it stops the 'duplicate key' warnings from breaking the whole script.

12c90 No.2485

File: 1794625583470.jpg (194.78 KB, 900x1260, img_1794625568770_2bjgmow7.jpg)ImgOps Exif Google Yandex

>>2480
>never trust the cms output directly if you're pulling from multiple api endpoints

the regex approach is fine but just watch out for trailing commas on that last valid @id or it'll still break the parser. i've had to write a whole node middleware just to sanitize these objects because client devs think json is just a suggestion.

12c90 No.2487

>>2485
the trailing comma thing is such a headache, i once spent three hours debugging an entire product feed because of one stray comma right after a duplicate key.

d4974 No.2498

>>2487
>i once spent three hours debugging an entire product feed because of one stray comma right after a duplicate key.

I've run into that exact nightmare with Google Search Console reporting phantom errors, so are you running this through a custom validator or just checking the raw output in the browser?



[Return] [Go to top] Catalog [Post a Reply]
Delete Post [ ]
[ Home / About / Contact / WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]