-
Notifications
You must be signed in to change notification settings - Fork 3
/
mod.ts
66 lines (60 loc) · 1.48 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
import type { SmallblogConfig } from "./types.ts";
import { createServer } from "./server.tsx";
import { createCli } from "./cli.ts";
export type { SmallblogConfig };
/**
* The main class of Smallblog instantiating the server and cli from your config.
*/
export class Smallblog {
private server;
private cli;
/**
* Creates your Smallblog instance
* @param config The options to create your blog.
*/
constructor(config: Partial<SmallblogConfig> = {}) {
const {
postsFolder = "data/posts/",
pagesFolder = "data/pages/",
favicon,
siteTitle = "Smallblog",
siteDescription = `The blog: ${siteTitle}`,
indexTitle,
indexSubtitle,
defaultAuthors,
noArticlesMessage,
locale,
customHeaderScript,
customBodyScript,
} = config;
this.server = createServer({
postsFolder,
pagesFolder,
favicon,
siteTitle,
siteDescription,
indexSubtitle,
indexTitle,
defaultAuthors,
noArticlesMessage,
locale,
customBodyScript,
customHeaderScript,
});
this.cli = createCli(postsFolder);
}
/**
* The fetch method to reoslve the HTTP requests
* @param req The input request
*/
fetch = (req: Request): Response | Promise<Response> => {
return this.server.fetch(req);
};
/**
* The method which handles the CLI
* @param args the arguments of the function
*/
run = (args: string[]): void => {
return this.cli(args);
};
}