Skip to content

Instantly share code, notes, and snippets.

@dcsaszar
Created March 10, 2025 09:56
Show Gist options
  • Save dcsaszar/e902032520286eda3954ab3b140a301d to your computer and use it in GitHub Desktop.
Save dcsaszar/e902032520286eda3954ab3b140a301d to your computer and use it in GitHub Desktop.
Update Scrivito Links by Search & Replace
search = "https://example.com"
replace = "https://example.com"
contents = await Scrivito.load(() => Scrivito.Obj.onAllSites().all().toArray().flatMap((o) => [o, ...o.widgets()]))
links = await Scrivito.load(() => contents.flatMap((c) => Object.entries(c.attributeDefinitions()).map(([name, [type]]) => (type === "link" && c.get(name) ? [c, name, c.get(name)] : null))).filter((v) => v?.[2].url()?.includes(search)))
links.forEach(([c, name, l]) => c.update({ [name]: l.copy({ url: replace }) }))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment