-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
18 changed files
with
300 additions
and
213 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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { render } from "../render.ts"; | ||
import * as dagsen from "./api.ts"; | ||
|
||
export async function dagsenHandler(params: URLSearchParams): Promise<Response> { | ||
let lang = params.get("lang") as dagsen.Language | null; | ||
|
||
if (lang !== null) { | ||
const renderData = await fetchRenderData(lang); | ||
return render("/dagsen/menu", renderData); | ||
} | ||
|
||
lang = lang ?? "sv"; | ||
if (!dagsen.LANGUAGES.includes(lang)) { | ||
lang = "sv"; | ||
} | ||
|
||
const renderData = await fetchRenderData(lang); | ||
return render("/dagsen/index", renderData); | ||
} | ||
|
||
type RenderData = { | ||
date: string; | ||
menuItems: string[]; | ||
openTime: string; | ||
nextPage: string; | ||
pageTimeout: string; | ||
}; | ||
|
||
async function fetchRenderData(language: dagsen.Language): Promise<RenderData> { | ||
const now = new Date(); | ||
|
||
const date = now.toLocaleDateString("en-GB", { year: "2-digit", month: "2-digit", "day": "2-digit" }) | ||
.split("/") | ||
.slice(0, 2) | ||
.join("/"); | ||
|
||
const menuItems = (await dagsen.fetchMenuText(language))?.split("\r\n") ?? []; | ||
|
||
return { | ||
date, | ||
menuItems: menuItems, | ||
openTime: dagsen.openTime(now), | ||
nextPage: nextDagsenPage(dagsen.LANGUAGES, language), | ||
pageTimeout: "5s", | ||
}; | ||
} | ||
|
||
function nextDagsenPage(languages: readonly dagsen.Language[], currentLanguage: dagsen.Language): string { | ||
const languagesLength = languages.length; | ||
const nextIndex = languages.indexOf(currentLanguage) + 1; | ||
return `/dagsen?lang=${languages[nextIndex % languagesLength]}`; | ||
} |
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,11 +1,16 @@ | ||
{ | ||
"deno.enable": true, | ||
"deno.lint": true, | ||
"deno.unstable": true, | ||
"fmt": { | ||
"lineWidth": 120 | ||
}, | ||
"tasks": { | ||
"dev": "deno run --watch --allow-read --allow-env --allow-net main.ts" | ||
} | ||
"deno.enable": true, | ||
"deno.lint": true, | ||
"deno.unstable": true, | ||
"fmt": { | ||
"lineWidth": 120 | ||
}, | ||
"tasks": { | ||
"dev": "deno run --watch --allow-read --allow-env --allow-net main.ts" | ||
}, | ||
"imports": { | ||
"@std/http": "https://deno.land/[email protected]/http/mod.ts", | ||
"@std/dotenv": "https://deno.land/[email protected]/dotenv/load.ts", | ||
"eta": "https://deno.land/x/[email protected]/src/index.ts", | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export type Env = { | ||
camUrl: string; | ||
ylonzDate: Date; | ||
votesUrl: string; | ||
pageTimeout: string; | ||
refreshTime: string; | ||
}; | ||
|
||
const { | ||
CAM_URL, | ||
YLONZ_DATE, | ||
VOTES_URL, | ||
PAGE_TIMEOUT = "10s", | ||
REFRESH_TIME = "04:00", | ||
} = Deno.env.toObject(); | ||
|
||
export const env: Env = { | ||
camUrl: CAM_URL, | ||
ylonzDate: new Date(YLONZ_DATE), | ||
votesUrl: VOTES_URL, | ||
pageTimeout: PAGE_TIMEOUT, | ||
refreshTime: REFRESH_TIME, | ||
}; |
Oops, something went wrong.