generated from ryanatkn/fuz_template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtome.ts
33 lines (27 loc) · 962 Bytes
/
tome.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import {base} from '$app/paths';
import {slugify} from '@ryanatkn/belt/path.js';
import {z} from 'zod';
import {create_context} from '$lib/context_helpers.js';
import {DEFAULT_LIBRARY_PATH} from '$lib/library_helpers.svelte.js';
export const Tome = z.object({
name: z.string(),
// TODO ? summary: z.string(),
category: z.string(),
// TODO uppercase this
component: z.any(), // TODO type
related: z.array(z.string()),
});
export type Tome = z.infer<typeof Tome>;
export const to_tome_pathname = (
item: Tome,
library_path = DEFAULT_LIBRARY_PATH,
base_path = base,
): string => base_path + library_path + '/' + slugify(item.name);
export const tomes_context = create_context<Map<string, Tome>>();
export const get_tome_by_name = (name: string): Tome => {
const tomes = tomes_context.get();
const tome = tomes.get(name);
if (!tome) throw Error(`unable to find tome "${name}"`);
return tome;
};
export const tome_context = create_context<Tome>();