-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod.ts
67 lines (57 loc) · 1.62 KB
/
mod.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { config, paths } from './config.ts';
import { jsxHtml, caller, urlJoin } from './deps.ts';
import { getRoutePath } from './generatePages/getRoutePath.ts';
import { applyPropsToPath } from './generatePages/applyPropsToPath.ts';
export { asset } from './components/utils/asset.ts';
export { css, cssSync } from './components/css.ts';
export { script } from './components/script.ts';
export {
NodePropsType,
ComponentFunctionType,
NullableChildType,
} from './deps.ts';
export { jsx, React } from './jsx.ts';
const { Fragment } = jsxHtml;
export { Fragment };
export interface Start {
config: typeof config;
paths: typeof paths;
}
export type LinkProps = {
[key: string]: string | number;
};
export type Props = {
[key: string]: any;
};
type PropsList = Props[] | undefined;
export interface GetterPropsList {
propsList: PropsList;
next?: GetPropsList;
}
export type GetPropsList = () => GetterPropsList | Promise<GetterPropsList>;
export interface Page {
getPropsList: GetPropsList | undefined;
component: Function;
file: string;
url: string;
link: (props?: LinkProps) => string;
}
export function page(
component: Function,
propsList?: GetPropsList | PropsList,
): Page {
const file = caller.default()!;
const url = urlJoin(
config.baseUrl,
getRoutePath(file, urlJoin).replace(/\/index.html$/g, '') || '/',
);
return {
getPropsList: Array.isArray(propsList)
? () => ({ propsList })
: propsList,
component,
file,
url,
link: (props?: LinkProps) => applyPropsToPath(url, props),
};
}