ctucx.git: oeffi-web

A fork of oeffisearch that works without javascript [hosted @ oeffi.ctu.cx]

commit 47d021f1ae815a71325d8ee73da72383973bd571
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(-)
A
src/assets.nim
|
16
++++++++++++++++
R
assets/client/css/product_selector.css -> src/assets/client/css/product_selector.css
|
0
R
assets/client/css/style.css -> src/assets/client/css/style.css
|
0
R
assets/client/img/apple-touch-icon.png -> src/assets/client/img/apple-touch-icon.png
|
0
R
assets/client/img/back.svg -> src/assets/client/img/back.svg
|
0
R
assets/client/img/baseline-beenhere-24px.svg -> src/assets/client/img/baseline-beenhere-24px.svg
|
0
R
assets/client/img/baseline-departure_board-24px.svg -> src/assets/client/img/baseline-departure_board-24px.svg
|
0
R
assets/client/img/baseline-directions-24px.svg -> src/assets/client/img/baseline-directions-24px.svg
|
0
R
assets/client/img/baseline-directions-24px_white.svg -> src/assets/client/img/baseline-directions-24px_white.svg
|
0
R
assets/client/img/baseline-directions_walk-24px.svg -> src/assets/client/img/baseline-directions_walk-24px.svg
|
0
R
assets/client/img/baseline-expand_more-24px.svg -> src/assets/client/img/baseline-expand_more-24px.svg
|
0
R
assets/client/img/baseline-import_export-24px.svg -> src/assets/client/img/baseline-import_export-24px.svg
|
0
R
assets/client/img/baseline-navigation-24px.svg -> src/assets/client/img/baseline-navigation-24px.svg
|
0
R
assets/client/img/baseline-place-24px.svg -> src/assets/client/img/baseline-place-24px.svg
|
0
R
assets/client/img/baseline-refresh-24px.svg -> src/assets/client/img/baseline-refresh-24px.svg
|
0
R
assets/client/img/baseline-settings-20px.svg -> src/assets/client/img/baseline-settings-20px.svg
|
0
R
assets/client/img/baseline-swap_vert-24px.svg -> src/assets/client/img/baseline-swap_vert-24px.svg
|
0
R
assets/client/img/bg.webp -> src/assets/client/img/bg.webp
|
0
R
assets/client/img/favicon-16x16.png -> src/assets/client/img/favicon-16x16.png
|
0
R
assets/client/img/favicon-32x32.png -> src/assets/client/img/favicon-32x32.png
|
0
R
assets/client/img/favicon-512x512.png -> src/assets/client/img/favicon-512x512.png
|
0
R
assets/client/img/favicon-64x64.png -> src/assets/client/img/favicon-64x64.png
|
0
R
assets/client/img/help-24px.svg -> src/assets/client/img/help-24px.svg
|
0
R
assets/client/img/info-24px.svg -> src/assets/client/img/info-24px.svg
|
0
R
assets/client/img/product_bus_color.svg -> src/assets/client/img/product_bus_color.svg
|
0
R
assets/client/img/product_bus_grey.svg -> src/assets/client/img/product_bus_grey.svg
|
0
R
assets/client/img/product_call_color.svg -> src/assets/client/img/product_call_color.svg
|
0
R
assets/client/img/product_call_grey.svg -> src/assets/client/img/product_call_grey.svg
|
0
R
assets/client/img/product_ferry_color.svg -> src/assets/client/img/product_ferry_color.svg
|
0
R
assets/client/img/product_ferry_grey.svg -> src/assets/client/img/product_ferry_grey.svg
|
0
R
assets/client/img/product_highspeed_color.svg -> src/assets/client/img/product_highspeed_color.svg
|
0
R
assets/client/img/product_highspeed_grey.svg -> src/assets/client/img/product_highspeed_grey.svg
|
0
R
assets/client/img/product_suburban_color.svg -> src/assets/client/img/product_suburban_color.svg
|
0
R
assets/client/img/product_suburban_grey.svg -> src/assets/client/img/product_suburban_grey.svg
|
0
R
assets/client/img/product_subway_color.svg -> src/assets/client/img/product_subway_color.svg
|
0
R
assets/client/img/product_subway_grey.svg -> src/assets/client/img/product_subway_grey.svg
|
0
R
assets/client/img/product_train_color.svg -> src/assets/client/img/product_train_color.svg
|
0
R
assets/client/img/product_train_grey.svg -> src/assets/client/img/product_train_grey.svg
|
0
R
assets/client/img/product_tram_color.svg -> src/assets/client/img/product_tram_color.svg
|
0
R
assets/client/img/product_tram_grey.svg -> src/assets/client/img/product_tram_grey.svg
|
0
R
assets/client/img/travelynx.svg -> src/assets/client/img/travelynx.svg
|
0
R
assets/client/img/warning-24px.svg -> src/assets/client/img/warning-24px.svg
|
0
R
assets/client/index.html -> src/assets/client/index.html
|
0
R
assets/client/js/api.js -> src/assets/client/js/api.js
|
0
R
assets/client/js/app.js -> src/assets/client/js/app.js
|
0
R
assets/client/js/app_functions.js -> src/assets/client/js/app_functions.js
|
0
R
assets/client/js/canvas.js -> src/assets/client/js/canvas.js
|
0
R
assets/client/js/ds100.js -> src/assets/client/js/ds100.js
|
0
R
assets/client/js/helpers.js -> src/assets/client/js/helpers.js
|
0
R
assets/client/js/journeyView.js -> src/assets/client/js/journeyView.js
|
0
R
assets/client/js/journeysView.js -> src/assets/client/js/journeysView.js
|
0
R
assets/client/js/languages.js -> src/assets/client/js/languages.js
|
0
R
assets/client/js/lit-html.js -> src/assets/client/js/lit-html.js
|
0
R
assets/client/js/overlays.js -> src/assets/client/js/overlays.js
|
0
R
assets/client/js/router.js -> src/assets/client/js/router.js
|
0
R
assets/client/js/searchView.js -> src/assets/client/js/searchView.js
|
0
R
assets/client/js/settingsView.js -> src/assets/client/js/settingsView.js
|
0
R
assets/client/js/sprintf.min.js -> src/assets/client/js/sprintf.min.js
|
0
R
assets/client/manifest.json -> src/assets/client/manifest.json
|
0
R
assets/client/service-worker.js -> src/assets/client/service-worker.js
|
0
R
assets/client/todo.txt -> src/assets/client/todo.txt
|
0
R
assets/favicon-512x512.png -> src/assets/favicon-512x512.png
|
0
R
assets/favicon-64x64.png -> src/assets/favicon-64x64.png
|
0
R
assets/js/canvas.js -> src/assets/js/canvas.js
|
0
R
assets/js/helpers.js -> src/assets/js/helpers.js
|
0
R
assets/js/journey.js -> src/assets/js/journey.js
|
0
R
assets/js/journeys.js -> src/assets/js/journeys.js
|
0
R
assets/js/lit-html.js -> src/assets/js/lit-html.js
|
0
R
assets/js/search.js -> src/assets/js/search.js
|
0
R
assets/manifest.json -> src/assets/manifest.json
|
0
R
assets/style.css -> src/assets/style.css
|
0
R
assets/varela-regular-webfont.woff -> src/assets/varela-regular-webfont.woff
|
0
R
assets/varela-regular-webfont.woff2 -> src/assets/varela-regular-webfont.woff2
|
0
M
src/oeffi.nim
|
46
+++++++++++++++++++++++++++++++++++++++++-----
R
templates/error.tpl -> src/templates/error.tpl
|
0
R
templates/journey.tpl -> src/templates/journey.tpl
|
0
R
templates/journeys.tpl -> src/templates/journeys.tpl
|
0
R
templates/search.tpl -> src/templates/search.tpl
|
0
M
src/utils.nim
|
12
+++++++++++-
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/css/product_selector.css b/src/assets/client/css/product_selector.css
diff --git a/assets/client/css/style.css b/src/assets/client/css/style.css
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/back.svg b/src/assets/client/img/back.svg
diff --git a/assets/client/img/baseline-beenhere-24px.svg b/src/assets/client/img/baseline-beenhere-24px.svg
diff --git a/assets/client/img/baseline-departure_board-24px.svg b/src/assets/client/img/baseline-departure_board-24px.svg
diff --git a/assets/client/img/baseline-directions-24px.svg b/src/assets/client/img/baseline-directions-24px.svg
diff --git a/assets/client/img/baseline-directions-24px_white.svg b/src/assets/client/img/baseline-directions-24px_white.svg
diff --git a/assets/client/img/baseline-directions_walk-24px.svg b/src/assets/client/img/baseline-directions_walk-24px.svg
diff --git a/assets/client/img/baseline-expand_more-24px.svg b/src/assets/client/img/baseline-expand_more-24px.svg
diff --git a/assets/client/img/baseline-import_export-24px.svg b/src/assets/client/img/baseline-import_export-24px.svg
diff --git a/assets/client/img/baseline-navigation-24px.svg b/src/assets/client/img/baseline-navigation-24px.svg
diff --git a/assets/client/img/baseline-place-24px.svg b/src/assets/client/img/baseline-place-24px.svg
diff --git a/assets/client/img/baseline-refresh-24px.svg b/src/assets/client/img/baseline-refresh-24px.svg
diff --git a/assets/client/img/baseline-settings-20px.svg b/src/assets/client/img/baseline-settings-20px.svg
diff --git a/assets/client/img/baseline-swap_vert-24px.svg b/src/assets/client/img/baseline-swap_vert-24px.svg
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/help-24px.svg b/src/assets/client/img/help-24px.svg
diff --git a/assets/client/img/info-24px.svg b/src/assets/client/img/info-24px.svg
diff --git a/assets/client/img/product_bus_color.svg b/src/assets/client/img/product_bus_color.svg
diff --git a/assets/client/img/product_bus_grey.svg b/src/assets/client/img/product_bus_grey.svg
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_call_grey.svg b/src/assets/client/img/product_call_grey.svg
diff --git a/assets/client/img/product_ferry_color.svg b/src/assets/client/img/product_ferry_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_highspeed_color.svg b/src/assets/client/img/product_highspeed_color.svg
diff --git a/assets/client/img/product_highspeed_grey.svg b/src/assets/client/img/product_highspeed_grey.svg
diff --git a/assets/client/img/product_suburban_color.svg b/src/assets/client/img/product_suburban_color.svg
diff --git a/assets/client/img/product_suburban_grey.svg b/src/assets/client/img/product_suburban_grey.svg
diff --git a/assets/client/img/product_subway_color.svg b/src/assets/client/img/product_subway_color.svg
diff --git a/assets/client/img/product_subway_grey.svg b/src/assets/client/img/product_subway_grey.svg
diff --git a/assets/client/img/product_train_color.svg b/src/assets/client/img/product_train_color.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/client/img/product_tram_grey.svg b/src/assets/client/img/product_tram_grey.svg
diff --git a/assets/client/img/travelynx.svg b/src/assets/client/img/travelynx.svg
diff --git a/assets/client/img/warning-24px.svg b/src/assets/client/img/warning-24px.svg
diff --git a/assets/client/index.html b/src/assets/client/index.html
diff --git a/assets/client/js/api.js b/src/assets/client/js/api.js
diff --git a/assets/client/js/app.js b/src/assets/client/js/app.js
diff --git a/assets/client/js/app_functions.js b/src/assets/client/js/app_functions.js
diff --git a/assets/client/js/canvas.js b/src/assets/client/js/canvas.js
diff --git a/assets/client/js/ds100.js b/src/assets/client/js/ds100.js
diff --git a/assets/client/js/helpers.js b/src/assets/client/js/helpers.js
diff --git a/assets/client/js/journeyView.js b/src/assets/client/js/journeyView.js
diff --git a/assets/client/js/journeysView.js b/src/assets/client/js/journeysView.js
diff --git a/assets/client/js/languages.js b/src/assets/client/js/languages.js
diff --git a/assets/client/js/lit-html.js b/src/assets/client/js/lit-html.js
diff --git a/assets/client/js/overlays.js b/src/assets/client/js/overlays.js
diff --git a/assets/client/js/router.js b/src/assets/client/js/router.js
diff --git a/assets/client/js/searchView.js b/src/assets/client/js/searchView.js
diff --git a/assets/client/js/settingsView.js b/src/assets/client/js/settingsView.js
diff --git a/assets/client/js/sprintf.min.js b/src/assets/client/js/sprintf.min.js
diff --git a/assets/client/manifest.json b/src/assets/client/manifest.json
diff --git a/assets/client/service-worker.js b/src/assets/client/service-worker.js
diff --git a/assets/client/todo.txt b/src/assets/client/todo.txt
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/js/canvas.js b/src/assets/js/canvas.js
diff --git a/assets/js/helpers.js b/src/assets/js/helpers.js
diff --git a/assets/js/journey.js b/src/assets/js/journey.js
diff --git a/assets/js/journeys.js b/src/assets/js/journeys.js
diff --git a/assets/js/lit-html.js b/src/assets/js/lit-html.js
diff --git a/assets/js/search.js b/src/assets/js/search.js
diff --git a/assets/manifest.json b/src/assets/manifest.json
diff --git a/assets/style.css b/src/assets/style.css
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/templates/error.tpl b/src/templates/error.tpl
diff --git a/templates/journey.tpl b/src/templates/journey.tpl
diff --git a/templates/journeys.tpl b/src/templates/journeys.tpl
diff --git a/templates/search.tpl b/src/templates/search.tpl
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")]))