Something went wrong. Try again.
🌿 Collaborative wiki on ATProto forked from juprodh.me/lichen.wiki
Something went wrong. Try again.
1234567891011121314151617181920212223242526import { getNoteBySlug } from "../server/db/queries/index.ts";import type { Messages } from "./i18n/index.ts";import { fmt } from "./i18n/index.ts";import { LIMITS } from "./limits.ts";import { isValidSlug, slugify } from "./slug.ts";
/** Validates title and generates a unique slug for a new note. */export function validateNewNote( wikiAtUri: string, title: string, msg: Messages,): { noteSlug: string } | { error: string } { if (!title.trim()) return { error: msg.error.titleRequired }; if (title.length > LIMITS.note.title) { return { error: fmt(msg.error.titleTooLong, { max: String(LIMITS.note.title) }), }; } const noteSlug = slugify(title); if (!isValidSlug(noteSlug)) return { error: fmt(msg.error.invalidSlug, { title }) }; const existing = getNoteBySlug(wikiAtUri, noteSlug); if (existing) return { error: fmt(msg.error.slugExists, { slug: noteSlug }) }; return { noteSlug };}