mirror of
https://github.com/Hackdex-App/hackdex-website.git
synced 2026-08-22 08:34:13 -05:00
Unify slugify function and remove common punctuation
This commit is contained in:
@@ -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<ReturnType<typeof createClient>>) {
|
||||
let candidate = base;
|
||||
let suffix = 2;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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, "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user