Skip to content

Commit

Permalink
fix: isUniqueSlug with draft
Browse files Browse the repository at this point in the history
  • Loading branch information
blushi committed Nov 14, 2024
1 parent 43ee488 commit 6ede7ff
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions utils/isUniqueSlug.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ export default function isUniqueSlug(slug, context) {
const language = document.language || 'en';

const query = `
*[_type == $docType && language == $language && iri.current == $iri && _id != $id][0]
*[_type == $docType && language == $language && iri.current == $iri && _id != $idWithDraftPrefix && _id != $idWithoutDraftPrefix][0]
`;

const idWithoutDraftPrefix = document._id.replace(/^drafts\./, '');
const params = {
docType,
language,
iri: slug,
id: document._id,
idWithoutDraftPrefix,
idWithDraftPrefix: `drafts.${idWithoutDraftPrefix}`,
};

return getClient({ apiVersion: '2023-01-01' })
Expand Down

0 comments on commit 6ede7ff

Please sign in to comment.