Skip to content

Commit dbeef33

Browse files
committed
read template file
1 parent b417e84 commit dbeef33

3 files changed

Lines changed: 6 additions & 14 deletions

File tree

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@focal/docify",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"license": "MIT",
55
"exports": "./mod.ts",
66
"imports": {

mod.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@ import { tmpl } from "./tmpl.ts";
88
export default class {
99

1010
constructor(app: Application) {
11-
const { engine } = app;
12-
13-
app.get("/", async () => {
14-
const summary = await getSummary();
15-
const content = await getReadme();
16-
return engine.render(tmpl, { meta, summary, content });
17-
});
1811

1912
app.get("/*", async (ctx: HttpContext) => {
13+
const { pathname } = ctx.request;
2014
const summary = await getSummary();
21-
const content = await getDocument(ctx.request.pathname);
22-
return engine.render(tmpl, { meta, summary, content });
15+
const content = pathname === "/" ? await getReadme() : await getDocument(pathname);
16+
return app.engine.render(tmpl, { meta, summary, content });
2317
});
2418

2519
app.run();

tmpl.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import { dirname } from "@std/path/dirname";
33
const __dirname = dirname(import.meta.url.replace(/^file:\/\//, ""));
44
const tmplFile = __dirname + "/tmpl.html";
55

6-
async function getTmpl() {
6+
export const tmpl = await (async function () {
77
if (tmplFile.match(/^https?:\/\//)) {
88
const response = await fetch(tmplFile);
99
return await response.text();
1010
}
1111
return await Deno.readTextFile(tmplFile);
12-
}
13-
14-
export const tmpl = await getTmpl();
12+
})();

0 commit comments

Comments
 (0)