diff --git a/src/schemas/slug.ts b/src/schemas/slug.ts index 75e6772..0306fa7 100644 --- a/src/schemas/slug.ts +++ b/src/schemas/slug.ts @@ -1,7 +1,6 @@ +import { cache } from '../cache' import { string } from './zod' -const cache = new Map() - /** * generate a slug schema * @param by unique by this, used to create a unique set of slugs @@ -14,20 +13,9 @@ export const slug = (by: string = 'global', reserved: string[] = []) => .max(200) .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/i, 'Invalid slug') .refine(value => !reserved.includes(value), 'Reserved slug') - .superRefine((value, ctx) => { - const key = `schemas:slug:${by}:${value}` - const path = ctx.meta.file.path + ':' + ctx.path.join('.') - if (cache.has(key)) { - if (path !== cache.get(key)) { - ctx.addIssue({ code: 'custom', message: 'Slug already exists in ' + cache.get(key) }) - } - } else { - cache.set(key, path) - } - }) -// rebuild cache cause not every file is processed -// .refine(value => { -// if (cache.has(`schemas:slug:${by}:${value}`)) return false -// cache.set(`schemas:slug:${by}:${value}`, true) -// return true -// }, 'Slug already exists') + .refine(value => { + // TODO: not working in rebuild + if (cache.has(`schemas:slug:${by}:${value}`)) return false + cache.set(`schemas:slug:${by}:${value}`, true) + return true + }, 'Slug already exists')