-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e297320
commit 89b3853
Showing
2 changed files
with
19 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
import { serveDir } from "https://deno.land/[email protected]/http/file_server.ts"; | ||
|
||
async function updateIndexHtml() { | ||
const indexHtmlText = await Deno.readTextFile("index.html"); | ||
|
||
const currentTime = new Date().toLocaleString(); | ||
|
||
const updatedIndexHtmlText = indexHtmlText.replace( | ||
"{{ LAST_UPDATED }}", | ||
currentTime, | ||
); | ||
|
||
await Deno.writeTextFile("index.html", updatedIndexHtmlText); | ||
} | ||
// Create the initial index.html | ||
await generateIndexHtml(); | ||
|
||
// Serve the static files | ||
Deno.serve(async (req) => { | ||
return await serveDir(req, { | ||
fsRoot: "./static/", | ||
fsRoot: Deno.cwd() + "/static/", | ||
}); | ||
}); | ||
|
||
Deno.cron("Update last updated", "*/10 * * * *", async () => { | ||
await updateIndexHtml(); | ||
// Generate index.html every minute with latest data | ||
Deno.cron("Update last updated", "* */1 * * *", async () => { | ||
await generateIndexHtml(); | ||
}); | ||
|
||
async function generateIndexHtml() { | ||
const currentTime = new Date().toLocaleString(); | ||
const htmlTemplate = await Deno.readTextFile( | ||
Deno.cwd() + "/static/.template.html", | ||
); | ||
|
||
const indexHtml = htmlTemplate.replace("{{ LAST_UPDATED }}", currentTime); | ||
|
||
await Deno.writeTextFile(Deno.cwd() + "/static/index.html", indexHtml); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89b3853
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failed to deploy: