Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: inline all static files #112

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

module Main
( main
)
where
) where

import Control.Concurrent ( MVar
, newMVar
Expand All @@ -19,7 +18,6 @@ import Control.Monad.Log ( defaultBatchingOptio
)
import Control.Monad.Reader ( runReaderT )
import Control.Monad.Trans ( liftIO )
import Data.FileEmbed ( embedDir )
import Data.IORef ( IORef
, readIORef
)
Expand All @@ -33,7 +31,6 @@ import Lens.Micro.Platform ( (<&>)
)
import Network.HTTP.Client.TLS ( newTlsManager )
import Network.Wai.Middleware.RequestLogger ( logStdout )
import Network.Wai.Middleware.StaticEmbedded ( static )
import System.Console.GetOpt ( ArgDescr(..)
, ArgOrder(..)
, OptDescr(..)
Expand Down Expand Up @@ -115,7 +112,5 @@ serve
-> IO ()
serve conf viewRef upd = scotty (view cPort conf) $ do
middleware logStdout
middleware (static $(embedDir "static"))
get "/" ((html . render) =<< liftIO (readIORef viewRef))
get "/r" (liftIO (tryPutMVar upd ()) >> redirect "/") -- force update

6 changes: 0 additions & 6 deletions mat-chalmers.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ maintainer: [email protected]
category: Web
build-type: Simple
cabal-version: >=1.10
data-files:
static/style.css
static/icon.png

library
default-language: Haskell2010
Expand Down Expand Up @@ -41,7 +38,6 @@ library
, tagsoup == 0.14.8
, text == 1.2.4.1
, bytestring == 0.10.12.0
, file-embed
, thyme
, word8 == 0.1.3

Expand All @@ -52,15 +48,13 @@ executable mat-chalmers
build-depends: mat-chalmers
, base >= 4.7
, bytestring
, file-embed
, http-client-tls == 0.3.5.3
, microlens-platform
, logging-effect
, mtl
, scotty
, time == 1.9.3
, wai-extra
, wai-middleware-static-embedded == 0.1.0.0
, async >= 2.1.1
default-language: Haskell2010

Expand Down
8 changes: 3 additions & 5 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ let
inherit (nixpkgs) pkgs;

f = { mkDerivation, aeson, base, bytestring, css-text, errors
, exceptions, file-embed, heredoc, http-client, http-client-tls
, exceptions, heredoc, http-client, http-client-tls
, logging-effect, lucid, microlens-platform, mtl, old-locale
, prettyprinter, safe, scotty, stdenv, text, thyme, time, wai-extra
, wai-middleware-static-embedded
}:
mkDerivation {
pname = "mat-chalmers";
Expand All @@ -19,14 +18,13 @@ let
buildTools = [ haskellPackages.cabal-install ];
enableSeparateDataOutput = true;
libraryHaskellDepends = [
aeson base bytestring css-text errors exceptions file-embed heredoc
aeson base bytestring css-text errors exceptions heredoc
http-client logging-effect lucid microlens-platform mtl old-locale
prettyprinter safe text thyme
];
executableHaskellDepends = [
base bytestring file-embed http-client-tls logging-effect
base bytestring http-client-tls logging-effect
microlens-platform mtl scotty time wai-extra
wai-middleware-static-embedded
];
license = stdenv.lib.licenses.mit;
};
Expand Down
130 changes: 124 additions & 6 deletions src/View.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{-# LANGUAGE OverloadedStrings, TemplateHaskell, RecordWildCards #-}
{-# LANGUAGE OverloadedStrings, QuasiQuotes, RecordWildCards #-}

module View
( View(..)
, render
)
where

import Data.FileEmbed
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.Builder as T
import Data.Thyme
Expand All @@ -18,6 +17,7 @@ import Lucid
import System.Locale ( defaultTimeLocale )
import qualified Text.CSS.Parse as CSS
import qualified Text.CSS.Render as CSS
import Text.Heredoc ( str )

import Model
import Model.Types ( NoMenu(..) )
Expand Down Expand Up @@ -69,7 +69,7 @@ sitehead = head_
(do
meta_ [charset_ "utf-8"]
meta_ [name_ "viewport", content_ "width=device-width, initial-scale=1"]
link_ [rel_ "icon", type_ "image/png", href_ "icon.png"]
link_ [rel_ "shortcut icon", id_ "icon", type_ "image/png", href_ "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAbcSURBVHic7ZpriFVVFMd/y8ZHqahjNupooUWW0QszU7M0tCeVpUmhvYPwg1RmGlhRUJH00KgQLUQhKopMk6TStMKKsrCUNB9p4viecjTDR+PsPqx9vXv2Pefcc+7c65G8f9jc/VhrnbXXWWvvtfe5YozhREaztBVIG2UDpK1A2igbIG0F0kbZAGkrkDbKBkhbgbRRNkDaCqSNsgHSVuBYQER6ikiHoLFmHuFAEam29d4iMkNErrftQSLypoj0te0RIjJdRM4s9QSaAhEZA6wHtorIuTkExhjskXgcYIADQCdgiW3/DbQFamx7tR0/ZNtzMzKOtwJc7uhpgIk+jesBV9nfVsAAoKdttwGqbcH2VwMtnPZxBxHpCXxEVk+AU3y6CpcnpF5SiEhLoDPqebtNEW5oRKQCWACc6g218Gkr/I5SQkSaAQOBm4GhQHeg0iGpF5EdwBrgY2C+MWZLAY+6C+gd0N8yp8eJl3lkY2U48IfTPsepHwQucto/x4jFVsDjwC6HL25ZBlyZIO4rgA0hsl736UvuASJyJ/Ac+rZdbAJWAjtsORkNhWqgP9l4HQh8KSILgAnGmHV5Hnk9ELYzHbsQEJEWwAzgHqe71vZ9CGwBLkUn3MWOrUQ9bxUaIqOBW9A16UZgsIiMMcZ8HPHogRFjxyYE0G3yG4fmb+AZoCMwFvgaqCfc7f8C3kZ3o4uBz5yxBmByRAh8FSH3vRz6YhsAdeXlzvg6oBdwO7AxQrmwMhfdasd5RpsQMHkB9kfJisoDXJxG4/CoduoCdA3hA5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wF9EGv1V2D1gOP5tPB6tErQPZNSQwwNEBA35gPrwCme7x16OXpIHTRvAq4E5iIfvgYYSd9qu331489/hvMo0O/AP1vc2nyfRsMSn3DkqFGMMbUA2NFZAnwArqetEOPqePRuF6F5vPb0C9KQ1B3v5Dc75YfAJOMMZviPN/CT4LAPxHmseBoci14Q9w34MhpgV6VJ70rPIJ+WLks6TPtc0cFyLwviQcEve0gr4iEMeYwME1EXkXvDN0/SFShV/KgWed2sn+QWGCM2Zn0eQ6CPKBRKlyyEAiC0dey3JYn4Oi/RjoBB4wx+wqVHQL/IAReCBTiAQUbIAhGT5NNectRCPpQ2uA28p0GNwQwh527j0dMA74gm1MsQNPzoxC7WIRCRK4GrkEXpE+MMWHHzuMWIlIFHDHG1OaM5TPA/x0nxH+Fo1A2QNoKpI2yAdJWIG2UDZC2AmnjP4d/p142yV/iAAAAAElFTkSuQmCC"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this line need to be that long? It feels difficult for a maintainer to see its use.

link_
[ rel_ "stylesheet"
, href_ "//fonts.googleapis.com/css?family=Anonymous+Pro:400,700"
Expand All @@ -90,9 +90,127 @@ sitefooter = footer_
a_ [href_ "https://kortladdning3.chalmerskonferens.se/"] "Top-up your card"
)

-- brittany-disable-next-binding
css :: T.Text
css =
(either error (T.toLazyText . CSS.renderNestedBlocks) . CSS.parseNestedBlocks)
$(embedStringFile "static/style.css")

inlineCSS
where
inlineCSS = [str| * {
| box-sizing: border-box;
| }
|
| html {
| font-size: 10px;
| }
|
| body {
| font-family: "Anonymous Pro";
| font-size: 14px;
| line-height: 1.42857143;
| background: #fdf7e2;
| color: #333;
| margin: 0;
| }
|
| h1,
| h2,
| h3 {
| line-height: 1.1;
| font-weight: 500;
| margin: 0;
| margin-bottom: 10px;
| }
|
| h1 {
| padding-left: 15px;
| font-size: 36px;
| margin-top: 20px;
| }
|
| h2 {
| font-size: 140%;
| font-weight: bold;
| }
|
| h3 {
| margin-right: 10px;
| margin-bottom: 0;
| display: inline-block;
| font-size: 100%;
| font-weight: bold;
| color: #bd3613;
| }
|
| p {
| font-size: 10vh;
| }
|
| a {
| color: #428bca;
| text-decoration: none;
| }
|
| ul {
| padding: 0;
| list-style-type: none;
| margin-top: 0;
| margin-bottom: 10px;
| }
| li {
| width: 100%;
| font-weight: 400;
| padding-bottom: 5px;
| }
|
| .food {
| position: relative;
| margin-top: 20px;
| }
|
| footer {
| font-size: 0.9em;
| margin-top: 20px;
| }
|
| /* Emulate Bootstrap Grid layout */
| .container-fluid {
| padding-left: 15px;
| padding-right: 15px;
| margin-left: auto;
| margin-right: auto;
| }
| .row {
| margin-left: -15px;
| margin-right: -15px;
| display: flex;
| flex-wrap: wrap;
| }
| .col-xs-12,
| .col-sm-12,
| .col-md-12,
| .col-sm-6,
| .col-md-3 {
| padding-left: 15px;
| padding-right: 15px;
| position: relative;
| }
| .col-xs-12 {
| width: 100%;
| }
| @media (min-width: 768px) {
| .col-sm-12 {
| width: 100%;
| }
| .col-sm-6 {
| width: 50%;
| }
| }
| @media (min-width: 992px) {
| .col-md-3 {
| width: 25%;
| }
| .col-md-12 {
| width: 100%;
| }
| }
|]
1 change: 0 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ resolver: lts-18.28
packages:
- "."
extra-deps:
- wai-middleware-static-embedded-0.1.0.0@sha256:036b7823a5e69452d1fe1e270ef3d4988063caa5bb00b6dfc356e1c21b7433e3
- logging-effect-1.3.12@sha256:72d168dd09887649ba9501627219b6027cbec2d5541931555b7885b133785ce3,1679

ghc-options: { "$locals": -ddump-to-file -ddump-hi }
Binary file removed static/icon.png
Binary file not shown.
108 changes: 0 additions & 108 deletions static/style.css

This file was deleted.