diff --git a/app/Helpers/Database.hs b/app/Helpers/Database.hs index 5af8706..37e2dc9 100644 --- a/app/Helpers/Database.hs +++ b/app/Helpers/Database.hs @@ -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) diff --git a/app/Helpers/Globals.hs b/app/Helpers/Globals.hs deleted file mode 100644 index 86ce393..0000000 --- a/app/Helpers/Globals.hs +++ /dev/null @@ -1,36 +0,0 @@ -module Helpers.Globals where - -import System.Environment (lookupEnv) - - -getDbPath :: IO String -getDbPath = do - result <- lookupEnv "HOMEPAGE_DB" - return $ case result of - (Just a) -> a - Nothing -> "./homepage.db3" - -getPort :: IO Int -getPort = do - result <- lookupEnv "HOMEPAGE_PORT" - return $ case result of - (Just a) -> read a :: Int - Nothing -> 8000 - -data LogLevel = Error | Warning | Info - -getLogLevel :: IO LogLevel -getLogLevel = do - result <- lookupEnv "HOMEPAGE_LOGLEVEL" - return $ case result of - (Just "info") -> Info - (Just "warning") -> Warning - (Just "error") -> Error - _ -> Error - -getCliState :: IO Bool -getCliState = do - result <- lookupEnv "HOMEPAGE_CLI" - case result of - (Just "1") -> return True - _ -> return False \ No newline at end of file diff --git a/app/Helpers/Logger.hs b/app/Helpers/Logger.hs index ec568f6..2ee99f3 100644 --- a/app/Helpers/Logger.hs +++ b/app/Helpers/Logger.hs @@ -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) diff --git a/app/Helpers/Settings.hs b/app/Helpers/Settings.hs new file mode 100644 index 0000000..dccc2ac --- /dev/null +++ b/app/Helpers/Settings.hs @@ -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" \ No newline at end of file diff --git a/app/Helpers/Utils.hs b/app/Helpers/Utils.hs index 129799e..5776661 100644 --- a/app/Helpers/Utils.hs +++ b/app/Helpers/Utils.hs @@ -22,12 +22,12 @@ linkImage label image url = [hsx| |] -items :: [String] -> Html -items values = forEach [1..length values] (\i -> [hsx| - {values !! (i-1)} -|]) +items :: [Html] -> Html +items values = mconcat $ map (\value -> [hsx| + {value} +|]) values -row :: [String] -> Html +row :: [Html] -> Html row values = [hsx| {items values} diff --git a/app/Main.hs b/app/Main.hs index 4e173dc..f992f35 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -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| diff --git a/app/Pages/Contact/Contact.hs b/app/Pages/Contact/Contact.hs index 3b46971..18ce960 100644 --- a/app/Pages/Contact/Contact.hs +++ b/app/Pages/Contact/Contact.hs @@ -11,15 +11,26 @@ contact = [hsx| Here's my various contact addresses
- {row ["Type", "Address"]} - {row ["Email", "mast3r@skade.dev"]} - {row ["University Email", "tjen19@student.aau.dk"]} - {row ["Matrix", "@mast3r:skade.dev"]} - {row ["Discord", "mast3r_waf1z"]} + {mconcat rows}

Socials

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

University

+ +
+ +

Where to find me:
Jægerstuen - Selma Lagerløfs Vej 300, 9220 Aalborg Øst


+

|] + where + rows = [ + row [[hsx|Type|], [hsx|Address|]], + row [[hsx|Email|], [hsx|mast3r@skade.dev|]], + row [[hsx|University Email|], [hsx|tjen19@student.aau.dk|]], + row [[hsx|Matrix|], [hsx|@mast3r:skade.dev|]], + row [[hsx|Discord|], [hsx|mast3r_waf1z|]] + ] diff --git a/flake.nix b/flake.nix index ffd96c4..a662db8 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; diff --git a/homepage.cabal b/homepage.cabal index e8b55af..cb4d2f6 100644 --- a/homepage.cabal +++ b/homepage.cabal @@ -14,7 +14,7 @@ executable homepage Helpers.Tree, Helpers.Utils, Helpers.Database, - Helpers.Globals, + Helpers.Settings, Helpers.Tables, Helpers.Logger, Helpers.Cli @@ -40,7 +40,8 @@ executable homepage time, uuid, directory, - aeson + aeson, + split hs-source-dirs: app default-language: Haskell2010 diff --git a/static/contact/fspinner.gif b/static/contact/fspinner.gif new file mode 100644 index 0000000..c463a5d Binary files /dev/null and b/static/contact/fspinner.gif differ