Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull isULID into the utils file #46

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions scripts/ob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 2 additions & 6 deletions src/pages/[...slug].astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
import { isULID } from "../utils.ts";

export const prerender = false;

/** 1 month in seconds */
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Loading