diff --git a/src/app/submit/actions.ts b/src/app/submit/actions.ts index 1746ade..6127ff6 100644 --- a/src/app/submit/actions.ts +++ b/src/app/submit/actions.ts @@ -5,22 +5,10 @@ import type { TablesInsert } from "@/types/db"; import { getMinioClient, PATCHES_BUCKET } from "@/utils/minio/server"; import { sendDiscordMessageEmbed } from "@/utils/discord"; import { APIEmbed } from "discord-api-types/v10"; +import { slugify } from "@/utils/format"; type HackInsert = TablesInsert<"hacks">; -function slugify(text: string) { - return text - .normalize("NFD") - .replace(/[\u0300-\u036f]/g, "") // strip combining diacritics - .replace(/ß/g, "ss") - .replace(/æ/g, "ae") - .replace(/œ/g, "oe") - .toLowerCase() - .trim() - .replace(/[^a-z0-9]+/g, "-") - .replace(/^-+|-+$/g, ""); -} - async function ensureUniqueSlug(base: string, supabase: Awaited>) { let candidate = base; let suffix = 2; diff --git a/src/components/Hack/HackSubmitForm.tsx b/src/components/Hack/HackSubmitForm.tsx index 0d72d90..034dd32 100644 --- a/src/components/Hack/HackSubmitForm.tsx +++ b/src/components/Hack/HackSubmitForm.tsx @@ -20,6 +20,7 @@ import BinFile from "rom-patcher-js/rom-patcher-js/modules/BinFile.js"; import BPS from "rom-patcher-js/rom-patcher-js/modules/RomPatcher.format.bps.js"; import { sha1Hex } from "@/utils/hash"; import { platformAccept, setDraftCovers, getDraftCovers, deleteDraftCovers } from "@/utils/idb"; +import { slugify } from "@/utils/format"; function SortableCoverItem({ id, index, url, filename, onRemove }: { id: string; index: number; url: string; filename: string; onRemove: () => void }) { const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id }); @@ -241,18 +242,6 @@ export default function HackSubmitForm({ dummy = false }: HackSubmitFormProps) { return () => cancelAnimationFrame(raf1); }, [step, isDummy, isHydrating]); - const slugify = (text: string) => - text - .normalize("NFD") - .replace(/[\u0300-\u036f]/g, "") // strip combining diacritics - .replace(/ß/g, "ss") - .replace(/æ/g, "ae") - .replace(/œ/g, "oe") - .toLowerCase() - .trim() - .replace(/[^a-z0-9]+/g, "-") - .replace(/^-+|-+$/g, ""); - const slug = slugify(title || ""); // Draft load after user is known (covers case where user id wasn't ready at first render) diff --git a/src/utils/format.ts b/src/utils/format.ts index 7596f9b..950a078 100644 --- a/src/utils/format.ts +++ b/src/utils/format.ts @@ -3,4 +3,16 @@ export function formatCompactNumber(value: number): string { return new Intl.NumberFormat("en", { notation: "compact", maximumFractionDigits: 1 }).format(value); } - +export function slugify(text: string) { + return text + .normalize("NFD") + .replace(/[\u0300-\u036f]/g, "") // strip combining diacritics + .replace(/[.,!?'"\*\(\)]/g, "") // remove common punctuation + .replace(/ß/g, "ss") + .replace(/æ/g, "ae") + .replace(/œ/g, "oe") + .toLowerCase() + .trim() + .replace(/[^a-z0-9]+/g, "-") + .replace(/^-+|-+$/g, ""); +}