Skip to content

Commit 497a58b

Browse files
committed
add utils
1 parent d2e3fcf commit 497a58b

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎apps/codingcatdev/src/lib/utils.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
/** @param {string} name */
1+
import { ContentType, type Content } from './types';
2+
23
export function get_depth(name: string) {
34
return name.split('/').length - 1;
45
}
6+
7+
export const contentLists = [
8+
...Object.values(ContentType)
9+
.filter((t) => ![ContentType.post, ContentType.page].includes(t))
10+
.map((t) => `${t}s`),
11+
'blog'
12+
];
13+
14+
export const pluralize = (content: Content) => {
15+
return `${content.type === ContentType.post ? 'blog' : content.type + 's'}`;
16+
};
17+
18+
export const unpluralize = (slug: string) => {
19+
return `${slug === 'blog' ? ContentType.post : slug.slice(0, -1)}` as ContentType;
20+
};

0 commit comments

Comments
 (0)