Skip to content

Commit 72b06e3

Browse files
committed
✨ Add url slug to workbook (#2020)
1 parent 7113fcb commit 72b06e3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/lib/types/workbook.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type WorkBookBase = {
88
isOfficial: boolean;
99
isReplenished: boolean; // カリキュラムの【補充】を識別するために使用
1010
workBookType: WorkBookType;
11+
urlSlug?: string; // 問題集(カリキュラムと解法別)をURLで識別するためのオプション。a-z、0-9、(-)ハイフンのみ使用可能。例: bfs、dfs、dp、union-find、2-sat。
1112
workBookTasks: WorkBookTaskBase[];
1213
};
1314

src/lib/zod/schema.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const workBookTaskSchema = z.object({
5151
.max(50, { message: '50文字になるまで削除してください' }), // FIXME: 上限は暫定値。
5252
});
5353

54+
// TODO: URL用のカラムとバリデーションを追加
5455
export const workBookSchema = z.object({
5556
authorId: z.string(),
5657
title: z
@@ -70,6 +71,15 @@ export const workBookSchema = z.object({
7071
isOfficial: z.boolean(),
7172
isReplenished: z.boolean(), // カリキュラムの【補充】を識別するために使用
7273
workBookType: z.nativeEnum(WorkBookType),
74+
urlSlug: z
75+
.string()
76+
.min(0, { message: '' })
77+
.max(30, { message: '30文字になるまで削除してください' }) // 問題集(カリキュラムと解法別)をURLで識別するためのオプション。a-z、0-9、(-)ハイフンのみ使用可能。例: bfs、dfs、dp、union-find、2-sat。
78+
.transform((value) => (value === '' ? undefined : value))
79+
.refine((value) => value === undefined || /^[a-z0-9]+(-[a-z0-9]+)*$/.test(value), {
80+
message: '半角英小文字、数字、ハイフンのみ使用可能です',
81+
})
82+
.optional(),
7383
workBookTasks: z
7484
.array(workBookTaskSchema)
7585
.min(1, { message: '1問以上登録してください' })

0 commit comments

Comments
 (0)