Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Created October 10, 2025 22:06
Show Gist options
  • Save james2doyle/62da26fdb006fde0faf08b31d02926b1 to your computer and use it in GitHub Desktop.
Save james2doyle/62da26fdb006fde0faf08b31d02926b1 to your computer and use it in GitHub Desktop.
Generate nested URLs using Groq functions in Sanity
// since the argument variable can only be referenced once, we need this function repeated
fn ex::p($p) = $p->{"c":url.current};
fn ex::pp($p) = $p->{"c": ex::p(parentPage).c};
fn ex::ppp($p) = $p->{"c": ex::pp(parentPage).c};
// will output `level-4/level-3/level-2/level-1`
// usage: { "href": ex::slug(@) }
fn ex::slug($d) = $d{"slug":array::join(
array::compact([
ex::ppp(parentPage).c,
ex::pp(parentPage).c,
ex::p(parentPage).c,
url.current
]),
'/'
)};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment