-
Notifications
You must be signed in to change notification settings - Fork 0
/
home_resource.js
82 lines (79 loc) · 2.9 KB
/
home_resource.js
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Index page
import { Drash } from "../dependencies.js";
export class HomeResource extends Drash.Http.Resource {
static paths = ["/"];
async GET() {
try {
this.response.body = await this.response.render(
Deno.cwd() + "/public/views/index",
{
page_title: "Home",
tutorials: [
{
title: "How to install Linux",
description: "A tutorial on how to install Linux on your computer.",
slug: "how-to-install-linux",
date: new Date().toLocaleDateString('en-US', {year: 'numeric', month: 'long', day: '2-digit'}),
},
{
title: "How to install Windows",
description: "A tutorial on how to install Windows on your computer.",
slug: "how-to-install-windows",
date: new Date().toLocaleDateString('en-US', {year: 'numeric', month: 'long', day: '2-digit'}),
},
{
title: "How to install ChromiumOS",
description: "A tutorial on how to install ChromiumOS on your computer.",
slug: "how-to-install-chromiumos",
date: new Date().toLocaleDateString('en-US', {year: 'numeric', month: 'long', day: '2-digit'}),
},
]
},
);
} catch (error) {
throw new Drash.Exceptions.HttpException(
400,
`Error reading ETA template.`
);
}
return this.response;
}
async POST() {
try {
let renderedHtmlOutput = await this.response.render(
Deno.cwd() + "/public/views/index",
{
page_title: "Home",
tutorials: [
{
title: "How to install Linux",
description: "A tutorial on how to install Linux on your computer.",
slug: "how-to-install-linux",
date: new Date().toLocaleDateString('en-US', {year: 'numeric', month: 'long', day: '2-digit'}),
},
{
title: "How to install Windows",
description: "A tutorial on how to install Windows on your computer.",
slug: "how-to-install-windows",
date: new Date().toLocaleDateString('en-US', {year: 'numeric', month: 'long', day: '2-digit'}),
},
{
title: "How to install ChromiumOS",
description: "A tutorial on how to install ChromiumOS on your computer.",
slug: "how-to-install-chromiumos",
date: new Date().toLocaleDateString('en-US', {year: 'numeric', month: 'long', day: '2-digit'}),
},
]
},
);
Deno.writeTextFileSync(`${Deno.cwd()}/dist/index.html`, renderedHtmlOutput);
this.response.body = "successfully rendered file!";
} catch (error) {
throw new Drash.Exceptions.HttpException(
400,
`Error reading ETA template.`
);
}
return this.response;
}
}