diff --git a/scripts/ob.ts b/scripts/ob.ts index 1cf7ee8..b9ef1d8 100644 --- a/scripts/ob.ts +++ b/scripts/ob.ts @@ -7,20 +7,7 @@ import { basename, dirname, join, extname } from "jsr:@std/path"; import { move } from "jsr:@std/fs"; import { extractYaml } from "jsr:@std/front-matter"; import { contentType } from "jsr:@std/media-types"; - -// async function write(text: string) { -// const encoder = new TextEncoder(); -// const data = encoder.encode(text); - -// // Write the data to stdout without a newline -// await Deno.stdout.write(data); -// } - -function isULID(str: string) { - // ULID regex to validate the format - const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i; - return ulidRegex.test(str); -} +import { isULID, slugify } from "../src/utils.ts"; const rename = new Command() .description("Renames a note with a ULID") diff --git a/src/pages/[...slug].astro b/src/pages/[...slug].astro index ee61902..db84e14 100644 --- a/src/pages/[...slug].astro +++ b/src/pages/[...slug].astro @@ -1,4 +1,6 @@ --- +import { isULID } from "../utils.ts"; + export const prerender = false; /** 1 month in seconds */ @@ -10,12 +12,6 @@ const CACHE_TTL = 60 * 60 * 24 * 30; // simpler for now. const HOME_SLUG = "01J4CPMJ91NF1DNQPE3TZ50HH0"; -const ulidRegex = /^[0-9A-HJ-NP-TV-Z]{26}$/i; - -function isULID(ulid: string) { - return ulidRegex.test(ulid); -} - /** * If a `get` KV request returns null and it was requested with a cacheTTL, * the empty result will be cached. That's usually not what we want, so this diff --git a/src/utils.ts b/src/utils.ts index 8fcf2dd..2beafea 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -6,3 +6,5 @@ export const slugify = (s: string) => export const isValidSha256 = (hashString: string) => /^[a-fA-F0-9]{64}$/.test(hashString); + +export const isULID = (str: string) => /^[0-9A-HJKMNP-TV-Z]{26}$/i.test(str);