commit 47d021f1ae815a71325d8ee73da72383973bd571
parent c5a889ce9e216de27d07e79d12500f85d6a89a8b
Author: Leah (ctucx) <leah@ctu.cx>
Date: Sun, 14 Mar 2021 15:36:19 +0100
parent c5a889ce9e216de27d07e79d12500f85d6a89a8b
Author: Leah (ctucx) <leah@ctu.cx>
Date: Sun, 14 Mar 2021 15:36:19 +0100
compile templates and assets into binary
79 files changed, 68 insertions(+), 6 deletions(-)
diff --git a/src/assets.nim b/src/assets.nim @@ -0,0 +1,16 @@ +const + templateError* = staticRead "templates/error.tpl" + templateSearch* = staticRead "templates/search.tpl" + templateJourney* = staticRead "templates/journey.tpl" + templateJourneys* = staticRead "templates/journeys.tpl" + +const + assetStyleCss* = staticRead "assets/style.css" + assetManifestJson* = staticRead "assets/manifest.json" + assetFavicon512* = staticRead "assets/favicon-512x512.png" + assetFavicon64* = staticRead "assets/favicon-64x64.png" + assetLitHtmlJs* = staticRead "assets/js/lit-html.js" + assetHelpersJs* = staticRead "assets/js/helpers.js" + assetSearchJs* = staticRead "assets/js/search.js" + assetJourneysJs* = staticRead "assets/js/journeys.js" + assetJourneyJs* = staticRead "assets/js/journey.js"
diff --git a/assets/client/img/apple-touch-icon.png b/src/assets/client/img/apple-touch-icon.png Binary files differ.
diff --git a/assets/client/img/bg.webp b/src/assets/client/img/bg.webp Binary files differ.
diff --git a/assets/client/img/favicon-16x16.png b/src/assets/client/img/favicon-16x16.png Binary files differ.
diff --git a/assets/client/img/favicon-32x32.png b/src/assets/client/img/favicon-32x32.png Binary files differ.
diff --git a/assets/client/img/favicon-512x512.png b/src/assets/client/img/favicon-512x512.png Binary files differ.
diff --git a/assets/client/img/favicon-64x64.png b/src/assets/client/img/favicon-64x64.png Binary files differ.
diff --git a/assets/client/img/product_call_color.svg b/src/assets/client/img/product_call_color.svg
diff --git a/assets/client/img/product_ferry_grey.svg b/src/assets/client/img/product_ferry_grey.svg
diff --git a/assets/client/img/product_train_grey.svg b/src/assets/client/img/product_train_grey.svg
diff --git a/assets/client/img/product_tram_color.svg b/src/assets/client/img/product_tram_color.svg
diff --git a/assets/favicon-512x512.png b/src/assets/favicon-512x512.png Binary files differ.
diff --git a/assets/favicon-64x64.png b/src/assets/favicon-64x64.png Binary files differ.
diff --git a/assets/varela-regular-webfont.woff b/src/assets/varela-regular-webfont.woff Binary files differ.
diff --git a/assets/varela-regular-webfont.woff2 b/src/assets/varela-regular-webfont.woff2 Binary files differ.
diff --git a/src/oeffi.nim b/src/oeffi.nim @@ -1,9 +1,6 @@ -import json, os, posix +import json, os, posix, options import asyncWebServer -import types -import options - import endpoints/searchHandler import endpoints/journeysHandler import endpoints/journeyHandler @@ -15,7 +12,14 @@ import endpoints/api/refreshJourney import nimhafas -import types, formaters/formaters +import types, assets, formaters/formaters + +const + templateError = staticRead "templates/error.tpl" + templateSearch = staticRead "templates/search.tpl" + templateJourney = staticRead "templates/journey.tpl" + templateJourneys = staticRead "templates/journeys.tpl" + proc removePidFile() = if getEnv("PID_FILE") != "": @@ -103,6 +107,38 @@ proc main = # for gcsafe var json = %* {"suggestions": suggestions} await request.respondJson(Http200, "success", "", json["suggestions"]) + startsWith("/assets/"): + if url == "style.css": + await request.respond(Http200, assetStyleCss, newHttpHeaders([("Content-Type", "text/css; charset=UTF-8")])) + + elif url == "manifest.json": + await request.respond(Http200, assetManifestJson, newHttpHeaders([("Content-Type", "application/json; charset=UTF-8")])) + + elif url == "favicon-512x512.png": + await request.respond(Http200, assetFavicon512, newHttpHeaders([("Content-Type", "image/png")])) + + elif url == "favicon-64x64.png": + await request.respond(Http200, assetFavicon64, newHttpHeaders([("Content-Type", "image/png")])) + + elif url == "js/lit-html.js": + await request.respond(Http200, assetLitHtmlJs, newHttpHeaders([("Content-Type", "text/javascript; charset=UTF-8")])) + + elif url == "js/helpers.js": + await request.respond(Http200, assetHelpersJs, newHttpHeaders([("Content-Type", "text/javascript; charset=UTF-8")])) + + elif url == "js/search.js": + await request.respond(Http200, assetSearchJs, newHttpHeaders([("Content-Type", "text/javascript; charset=UTF-8")])) + + elif url == "js/journeys.js": + await request.respond(Http200, assetJourneysJs, newHttpHeaders([("Content-Type", "text/javascript; charset=UTF-8")])) + + elif url == "js/journey.js": + await request.respond(Http200, assetJourneyJs, newHttpHeaders([("Content-Type", "text/javascript; charset=UTF-8")])) + + else: + await request.respond(Http404, "404 - Not found", newHttpHeaders([("Content-Type", "text/plain")])) + + regex(re"^\/([A-Za-z0-9]+)$"): await journeysHandler(request, server)
diff --git a/src/utils.nim b/src/utils.nim @@ -2,6 +2,7 @@ import json, asyncdispatch, asynchttpserver, options, strutils, httpcore import nimhafas import types, translations import moustachu, moustachu_context +import assets proc getPoint* (name: string): Future[Point] {.async} = let points = (await suggestions(SuggestionsParams( @@ -59,6 +60,15 @@ proc respTemplate* (request: Request, httpCode: HttpCode, name: string, template templateContext = templateContext.addTranslations(translations["global"][lang]) templateContext = templateContext.addTranslations(translations[name][lang]) - let response = render(readFile("templates/" & name & ".tpl"), templateContext) + var response: string + + if name == "search": + response = render(templateSearch , templateContext) + elif name == "journeys": + response = render(templateJourneys, templateContext) + elif name == "journey": + response = render(templateJourney, templateContext) + else: + response = render(templateError, templateContext) await request.respond(httpCode, response, newHttpHeaders([("Content-Type", "text/html; charset=UTF-8")]))