From de0b6d7c117f96d4a913f9421d35455de83015a3 Mon Sep 17 00:00:00 2001 From: zce Date: Fri, 8 Dec 2023 19:32:07 +0800 Subject: [PATCH] chore: remove global config --- src/schemas/slug.ts | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) 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')