|
1 | 1 | import { getFile, putFile, listFiles } from './github'; |
2 | | -import { parseFrontmatter, stringifyFrontmatter, generateId, transliterate, normalizeText } from './utils'; |
| 2 | +import { parseFrontmatter, stringifyFrontmatter, generateId, transliterate, normalizeText, slugify } from './utils'; |
3 | 3 |
|
4 | 4 | export interface Forum { |
5 | 5 | slug: string; |
@@ -69,12 +69,13 @@ export async function getForum(slug: string): Promise<Forum | null> { |
69 | 69 | return { ...data, slug }; |
70 | 70 | } |
71 | 71 |
|
72 | | -export async function createForum(data: Omit<Forum, 'slug'> & {slug: string}): Promise<Forum> { |
| 72 | +export async function createForum(data: Omit<Forum, 'slug'>): Promise<Forum> { |
| 73 | + const slug = slugify(data.title); |
73 | 74 | const content = stringifyFrontmatter(data, ''); |
74 | | - await putFile(`forums/${data.slug}.md`, content, `Create forum ${data.title}`); |
| 75 | + await putFile(`forums/${slug}.md`, content, `Create forum ${data.title}`); |
75 | 76 |
|
76 | 77 | return { |
77 | | - slug: data.slug, |
| 78 | + slug, |
78 | 79 | title: data.title, |
79 | 80 | description: data.description, |
80 | 81 | order: data.order, |
@@ -120,7 +121,7 @@ export async function getTopic(id: string): Promise<Topic | null> { |
120 | 121 |
|
121 | 122 | export async function createTopic(data: Omit<Topic, 'id' | 'createdAt' | 'titleTranslit'>): Promise<Topic> { |
122 | 123 | const id = generateId(); |
123 | | - const titleTranslit = transliterate(data.title); |
| 124 | + const titleTranslit = transliterate(data.title) || `topic-${generateId()}`; |
124 | 125 | const createdAt = new Date().toISOString(); |
125 | 126 | const frontmatterData = { |
126 | 127 | title: data.title, |
|
0 commit comments