Skip to content

Commit 30ee0e7

Browse files
committed
some more settings and env vars, updated contact page
1 parent 19d931e commit 30ee0e7

File tree

10 files changed

+82
-52
lines changed

10 files changed

+82
-52
lines changed

app/Helpers/Database.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Helpers.Database where
44

55
import Database.SQLite.Simple (close, execute, open, query, Only(Only), ToRow, Query (Query), Connection)
66

7-
import Helpers.Globals (getDbPath)
7+
import Helpers.Settings (getDbPath)
88

99
import Data.List (intercalate, inits)
1010
import Data.Text (pack, Text)

app/Helpers/Globals.hs

Lines changed: 0 additions & 36 deletions
This file was deleted.

app/Helpers/Logger.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Data.Text (unpack)
66
import Network.HTTP.Types (Status(statusCode))
77

88
import Helpers.Utils (unpackBS)
9-
import Helpers.Globals (LogLevel (..), getLogLevel, getCliState)
9+
import Helpers.Settings (LogLevel (..), getLogLevel, getCliState)
1010
import System.IO (hFlush, stdout)
1111
import Control.Monad (when)
1212

app/Helpers/Settings.hs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
3+
module Helpers.Settings where
4+
5+
import System.Environment (lookupEnv, getArgs)
6+
import Data.List (find)
7+
import Data.Text (isInfixOf, pack, unpack)
8+
import Data.List.Split (splitOn)
9+
10+
argOrEnvOrDefault :: String -> String -> String -> IO String
11+
argOrEnvOrDefault arg env def = do
12+
args <- getArgs
13+
case find (isInfixOf (pack arg)) [pack arg | arg <- args] of
14+
(Just x) -> return $ splitOn "=" (unpack x) !! 1
15+
_ -> do
16+
var <- lookupEnv env
17+
return $ case var of
18+
(Just a) -> a
19+
_ -> def
20+
21+
argOrEnvOrBool :: String -> String -> IO Bool
22+
argOrEnvOrBool arg env = do
23+
args <- getArgs
24+
case find (== arg) args of
25+
(Just _) -> return True
26+
_ -> do
27+
var <- lookupEnv env
28+
return $ case var of
29+
(Just "1") -> True
30+
_ -> False
31+
32+
33+
getDbPath :: IO String
34+
getDbPath = argOrEnvOrDefault "--db" "HOMEPAGE_DB" "./homrpage.db3"
35+
36+
getPort :: IO Int
37+
getPort = do
38+
var <- argOrEnvOrDefault "--port" "HOMEPAGE_PORT" "8000"
39+
return $ read var
40+
41+
data LogLevel = Error | Warning | Info
42+
43+
getLogLevel :: IO LogLevel
44+
getLogLevel = do
45+
var <- argOrEnvOrDefault "--loglevel" "HOMEPAGE_LOGLEVEL" "error"
46+
return $ case var of
47+
"info" -> Info
48+
"warning" -> Warning
49+
"error" -> Error
50+
_ -> Error
51+
52+
getCliState :: IO Bool
53+
getCliState = argOrEnvOrBool "--cli" "HOMEPAGE_CLI"

app/Helpers/Utils.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ linkImage label image url = [hsx|
2222
</div>
2323
|]
2424

25-
items :: [String] -> Html
26-
items values = forEach [1..length values] (\i -> [hsx|
27-
<th style="width:100px">{values !! (i-1)}</th>
28-
|])
25+
items :: [Html] -> Html
26+
items values = mconcat $ map (\value -> [hsx|
27+
<th style="width:100px">{value}</th>
28+
|]) values
2929

30-
row :: [String] -> Html
30+
row :: [Html] -> Html
3131
row values = [hsx|
3232
<tr>
3333
{items values}

app/Main.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ import Pages.Guestbook.Guestbook (guestbook)
2929

3030
import Helpers.Database (initDb)
3131
import Helpers.Utils (unpackBS)
32-
import Helpers.Globals (getPort, getCliState)
32+
import Helpers.Settings (getPort, getCliState)
3333
import Helpers.Logger (logger, tableify, info, warning)
3434
import Api.Api (api)
3535
import Control.Concurrent (forkIO, ThreadId)
3636
import Helpers.Cli (cli)
37+
import System.Environment (getArgs)
3738

3839
page404 :: [String] -> Response
3940
page404 args = responseBuilder status404 [("Content-Type", "text/html")] $ copyByteString (fromString (renderHtml (layout [hsx|

app/Pages/Contact/Contact.hs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,26 @@ contact = [hsx|
1111
Here's my various contact addresses
1212
<br>
1313
<table style="display:inline-block;border:1px solid white; padding:5px;">
14-
{row ["Type", "Address"]}
15-
{row ["Email", "[email protected]"]}
16-
{row ["University Email", "[email protected]"]}
17-
{row ["Matrix", "@mast3r:skade.dev"]}
18-
{row ["Discord", "mast3r_waf1z"]}
14+
{mconcat rows}
1915
</table>
2016

2117
<h2>Socials</h2>
2218
Links to my socials
2319
<br>
2420
{linkImage "LinkedIn" "/static/contact/LinkedIn.png" "https://www.linkedin.com/in/thomas-m%C3%B8ller-j-a76601a6/"}
21+
22+
<h2>University</h2>
23+
24+
<div style="border:1px solid white; border-radius: 10px; margin: 0% 30% 0% 30%">
25+
<img src="/static/contact/fspinner.gif" style="width:150px; height:150px;">
26+
<p>Where to find me: <br><a href="https://fklub.dk/jaegerstuen">Jægerstuen</a> - Selma Lagerløfs Vej 300, 9220 Aalborg Øst</p><br>
27+
</div><br>
2528
|]
29+
where
30+
rows = [
31+
row [[hsx|Type|], [hsx|Address|]],
32+
row [[hsx|Email|], [hsx|<a href="mailto://[email protected]">[email protected]</a>|]],
33+
row [[hsx|University Email|], [hsx|<a href="mailto://[email protected]">[email protected]</a>|]],
34+
row [[hsx|Matrix|], [hsx|@mast3r:skade.dev|]],
35+
row [[hsx|Discord|], [hsx|mast3r_waf1z|]]
36+
]

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
executableHaskellDepends = with pkgs.haskellPackages; [
2626
base blaze-builder blaze-html bytestring http-types ihp-hsx
2727
sqlite-simple text time utf8-string uuid wai warp directory
28-
aeson
28+
aeson split
2929
];
3030
license = "unknown";
3131
mainProgram = "homepage";

homepage.cabal

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ executable homepage
1414
Helpers.Tree,
1515
Helpers.Utils,
1616
Helpers.Database,
17-
Helpers.Globals,
17+
Helpers.Settings,
1818
Helpers.Tables,
1919
Helpers.Logger,
2020
Helpers.Cli
@@ -40,7 +40,8 @@ executable homepage
4040
time,
4141
uuid,
4242
directory,
43-
aeson
43+
aeson,
44+
split
4445

4546
hs-source-dirs: app
4647
default-language: Haskell2010

static/contact/fspinner.gif

166 KB
Loading

0 commit comments

Comments
 (0)