Skip to content

Commit

Permalink
some more settings and env vars, updated contact page
Browse files Browse the repository at this point in the history
  • Loading branch information
Mast3rwaf1z committed Aug 30, 2024
1 parent 19d931e commit 30ee0e7
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 52 deletions.
2 changes: 1 addition & 1 deletion app/Helpers/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Helpers.Database where

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

import Helpers.Globals (getDbPath)
import Helpers.Settings (getDbPath)

import Data.List (intercalate, inits)
import Data.Text (pack, Text)
Expand Down
36 changes: 0 additions & 36 deletions app/Helpers/Globals.hs

This file was deleted.

2 changes: 1 addition & 1 deletion app/Helpers/Logger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Data.Text (unpack)
import Network.HTTP.Types (Status(statusCode))

import Helpers.Utils (unpackBS)
import Helpers.Globals (LogLevel (..), getLogLevel, getCliState)
import Helpers.Settings (LogLevel (..), getLogLevel, getCliState)
import System.IO (hFlush, stdout)
import Control.Monad (when)

Expand Down
53 changes: 53 additions & 0 deletions app/Helpers/Settings.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{-# LANGUAGE OverloadedStrings #-}

module Helpers.Settings where

import System.Environment (lookupEnv, getArgs)
import Data.List (find)
import Data.Text (isInfixOf, pack, unpack)
import Data.List.Split (splitOn)

argOrEnvOrDefault :: String -> String -> String -> IO String
argOrEnvOrDefault arg env def = do
args <- getArgs
case find (isInfixOf (pack arg)) [pack arg | arg <- args] of
(Just x) -> return $ splitOn "=" (unpack x) !! 1
_ -> do
var <- lookupEnv env
return $ case var of
(Just a) -> a
_ -> def

argOrEnvOrBool :: String -> String -> IO Bool
argOrEnvOrBool arg env = do
args <- getArgs
case find (== arg) args of
(Just _) -> return True
_ -> do
var <- lookupEnv env
return $ case var of
(Just "1") -> True
_ -> False


getDbPath :: IO String
getDbPath = argOrEnvOrDefault "--db" "HOMEPAGE_DB" "./homrpage.db3"

getPort :: IO Int
getPort = do
var <- argOrEnvOrDefault "--port" "HOMEPAGE_PORT" "8000"
return $ read var

data LogLevel = Error | Warning | Info

getLogLevel :: IO LogLevel
getLogLevel = do
var <- argOrEnvOrDefault "--loglevel" "HOMEPAGE_LOGLEVEL" "error"
return $ case var of
"info" -> Info
"warning" -> Warning
"error" -> Error
_ -> Error

getCliState :: IO Bool
getCliState = argOrEnvOrBool "--cli" "HOMEPAGE_CLI"
10 changes: 5 additions & 5 deletions app/Helpers/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ linkImage label image url = [hsx|
</div>
|]

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

row :: [String] -> Html
row :: [Html] -> Html
row values = [hsx|
<tr>
{items values}
Expand Down
3 changes: 2 additions & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ import Pages.Guestbook.Guestbook (guestbook)

import Helpers.Database (initDb)
import Helpers.Utils (unpackBS)
import Helpers.Globals (getPort, getCliState)
import Helpers.Settings (getPort, getCliState)
import Helpers.Logger (logger, tableify, info, warning)
import Api.Api (api)
import Control.Concurrent (forkIO, ThreadId)
import Helpers.Cli (cli)
import System.Environment (getArgs)

page404 :: [String] -> Response
page404 args = responseBuilder status404 [("Content-Type", "text/html")] $ copyByteString (fromString (renderHtml (layout [hsx|
Expand Down
21 changes: 16 additions & 5 deletions app/Pages/Contact/Contact.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@ contact = [hsx|
Here's my various contact addresses
<br>
<table style="display:inline-block;border:1px solid white; padding:5px;">
{row ["Type", "Address"]}
{row ["Email", "[email protected]"]}
{row ["University Email", "[email protected]"]}
{row ["Matrix", "@mast3r:skade.dev"]}
{row ["Discord", "mast3r_waf1z"]}
{mconcat rows}
</table>

<h2>Socials</h2>
Links to my socials
<br>
{linkImage "LinkedIn" "/static/contact/LinkedIn.png" "https://www.linkedin.com/in/thomas-m%C3%B8ller-j-a76601a6/"}

<h2>University</h2>

<div style="border:1px solid white; border-radius: 10px; margin: 0% 30% 0% 30%">
<img src="/static/contact/fspinner.gif" style="width:150px; height:150px;">
<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>
</div><br>
|]
where
rows = [
row [[hsx|Type|], [hsx|Address|]],
row [[hsx|Email|], [hsx|<a href="mailto://[email protected]">[email protected]</a>|]],
row [[hsx|University Email|], [hsx|<a href="mailto://[email protected]">[email protected]</a>|]],
row [[hsx|Matrix|], [hsx|@mast3r:skade.dev|]],
row [[hsx|Discord|], [hsx|mast3r_waf1z|]]
]
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
executableHaskellDepends = with pkgs.haskellPackages; [
base blaze-builder blaze-html bytestring http-types ihp-hsx
sqlite-simple text time utf8-string uuid wai warp directory
aeson
aeson split
];
license = "unknown";
mainProgram = "homepage";
Expand Down
5 changes: 3 additions & 2 deletions homepage.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ executable homepage
Helpers.Tree,
Helpers.Utils,
Helpers.Database,
Helpers.Globals,
Helpers.Settings,
Helpers.Tables,
Helpers.Logger,
Helpers.Cli
Expand All @@ -40,7 +40,8 @@ executable homepage
time,
uuid,
directory,
aeson
aeson,
split

hs-source-dirs: app
default-language: Haskell2010
Expand Down
Binary file added static/contact/fspinner.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 30ee0e7

Please sign in to comment.