beeeeg update
Some checks failed
Test and deploy staging / staging (push) Has been cancelled

This commit is contained in:
2026-09-23 04:15:10 +00:00
parent 487eff5bb2
commit d0c7b6548b
135 changed files with 9531 additions and 1777 deletions

View File

@@ -1,14 +1,14 @@
import { db } from '$lib/server/db';
import { blogArticles } from '$lib/server/db/schema';
import { blogArticles, lists } from '$lib/server/db/schema';
import { eq } from 'drizzle-orm';
export function slugify(title: string): string {
export function slugify(title: string, fallback = 'article'): string {
return (
title
.toLowerCase()
.trim()
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-+|-+$/g, '') || 'article'
.replace(/^-+|-+$/g, '') || fallback
);
}
@@ -27,3 +27,17 @@ export async function uniqueSlug(title: string): Promise<string> {
return slug;
}
export async function uniqueListSlug(name: string): Promise<string> {
const base = slugify(name, 'list');
let slug = base;
let suffix = 2;
while ((await db.select({ id: lists.id }).from(lists).where(eq(lists.slug, slug))).length > 0) {
slug = `${base}-${suffix++}`;
}
return slug;
}
export function validSlug(slug: string): boolean {
return slug.length <= 120 && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug);
}