Skip to content

Commit b417e84

Browse files
committed
read template file
1 parent 135dda6 commit b417e84

4 files changed

Lines changed: 19 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ https://tech-docs.deno.dev
1313

1414
```
1515
// start.ts
16-
import "jsr:@focal/docify@1.0.2";
16+
import "jsr:@focal/docify@1.0.6";
1717
```
1818

1919
2. Create `SUMMARY.md` and `README.md` in your document folder root. The

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.5",
3+
"version": "1.0.6",
44
"license": "MIT",
55
"exports": "./mod.ts",
66
"imports": {

mod.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,24 @@ import { Application } from "@focal/cross";
22
import { HttpContext } from "@focal/cross/context";
33
import { Cross } from "@focal/cross/decorators";
44
import { getDocument, getReadme, getSummary, meta } from "./docs.ts";
5+
import { tmpl } from "./tmpl.ts";
56

67
@Cross
78
export default class {
89

910
constructor(app: Application) {
1011
const { engine } = app;
11-
const tmplUrl = new URL(import.meta.resolve('./tmpl.html'));
12-
13-
console.log(tmplUrl)
14-
const tmplText = Deno.readTextFileSync(tmplUrl);
1512

1613
app.get("/", async () => {
1714
const summary = await getSummary();
1815
const content = await getReadme();
19-
return engine.render(tmplText, { meta, summary, content });
16+
return engine.render(tmpl, { meta, summary, content });
2017
});
2118

2219
app.get("/*", async (ctx: HttpContext) => {
2320
const summary = await getSummary();
2421
const content = await getDocument(ctx.request.pathname);
25-
return engine.render(tmplText, { meta, summary, content });
22+
return engine.render(tmpl, { meta, summary, content });
2623
});
2724

2825
app.run();

tmpl.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { dirname } from "@std/path/dirname";
2+
3+
const __dirname = dirname(import.meta.url.replace(/^file:\/\//, ""));
4+
const tmplFile = __dirname + "/tmpl.html";
5+
6+
async function getTmpl() {
7+
if (tmplFile.match(/^https?:\/\//)) {
8+
const response = await fetch(tmplFile);
9+
return await response.text();
10+
}
11+
return await Deno.readTextFile(tmplFile);
12+
}
13+
14+
export const tmpl = await getTmpl();

0 commit comments

Comments
 (0)