Skip to content

Commit

Permalink
Merge pull request #131 from tinloof/tin-2756
Browse files Browse the repository at this point in the history
definePathname uniqueness
  • Loading branch information
stilyan-tinloof authored Feb 5, 2025
2 parents c477989 + 09bd0cd commit 0ebb14c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/six-queens-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tinloof/sanity-studio": patch
---

definePathname uniqueness check updated
5 changes: 4 additions & 1 deletion packages/sanity-studio/src/utils/definePathname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ async function isUnique(
draft: `drafts.${id}`,
published: id,
slug,
// Remove slash from end of slug if it exists
// Handle cases where there is a page with /blog but a new page is created with /blog/
slugWithoutSlash: slug.replace(/\/$/, ""),
locale: document?.locale ?? null,
};
const query = `*[!(_id in [$draft, $published]) && pathname.current == $slug && locale == $locale]`;
const query = `*[!(_id in [$draft, $published]) && (pathname.current == $slug || pathname.current == $slugWithoutSlash) && locale == $locale]`;
const result = await client.fetch(query, params);
return result.length === 0;
}

0 comments on commit 0ebb14c

Please # to comment.