Skip to content

Commit

Permalink
remove IO current time dependence and so now derivation is pure
Browse files Browse the repository at this point in the history
  • Loading branch information
mstksg committed Dec 29, 2023
1 parent f1cdddd commit f68adef
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 15 deletions.
7 changes: 3 additions & 4 deletions app/site.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import Blog.App
import Blog.Types
import Data.Time.LocalTime
import Dhall
import Dhall.Pretty
import Hakyll
import Data.Time.Zones
import System.IO
import qualified Data.Text as T
import qualified Prettyprinter as PP
Expand All @@ -20,8 +20,6 @@ configPath = "./config/site-data.dhall"

main :: IO ()
main = do
znow <- getZonedTime

c <- input interpretConfig configPath
let ?config = c

Expand All @@ -33,4 +31,5 @@ main = do

putStrLn ""

hakyllWith (defaultConfiguration { inMemoryCache = False}) $ app znow
tz <- loadTZFromDB (T.unpack $ confEntryTZ ?config)
hakyllWith (defaultConfiguration { inMemoryCache = False}) $ app tz
1 change: 1 addition & 0 deletions config/site-data.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
''
, authorInfo =
./site-data/author-info.dhall
, entryTZ = "America/Los_Angeles"
, copyright =
"2020 Justin Le"
, license =
Expand Down
1 change: 0 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
purescript = pkgs.purifix { src = ./purescript; };
haskell = haskellFlake.packages."inCode:exe:inCode-build";
web = pkgs.stdenv.mkDerivation {
impure = true;
name = "inCode";
buildInputs = [ haskell ] ++ lib.attrValues purescript;
srcs = [
Expand Down
4 changes: 3 additions & 1 deletion inCode.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ library
, text
, time
, transformers
, tz
, xml-conduit
, xml-types
, yaml
Expand All @@ -85,20 +86,21 @@ executable inCode-build
build-depends:
aeson
, base ==4.*
, inCode
, bytestring
, containers
, data-default
, dhall
, filepath
, hakyll >=4.8
, inCode
, lens
, pandoc
, prettyprinter
, prettyprinter-ansi-terminal
, text
, time
, transformers
, tz
, yaml
default-language: Haskell2010

Expand Down
5 changes: 3 additions & 2 deletions src/Blog/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ import qualified Data.List.NonEmpty as NE
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Encoding as TL
import Data.Time.Zones


app :: (?config :: Config)
=> ZonedTime
=> TZ
-> Rules ()
app (ZonedTime _ tz) = do
app tz = do
match "static/**" $ do
route $ gsubRoute "static/" (const "")
compile copyFileCompiler
Expand Down
1 change: 1 addition & 0 deletions src/Blog/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ data Config = Config
{ confTitle :: !T.Text
, confDesc :: !T.Text
, confAuthorInfo :: !AuthorInfo
, confEntryTZ :: !T.Text -- ^ ie: America/Los_Angeles
, confCopyright :: !T.Text
, confLicense :: !T.Text
, confLicenseLink :: !T.Text
Expand Down
2 changes: 1 addition & 1 deletion src/Blog/Util/Tag.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Control.Monad
import Control.Monad.Trans.Class
import Control.Monad.Trans.Maybe
import Data.Char
import Data.List
import Data.List (sortBy)
import Data.Maybe
import Data.Ord
import Data.String
Expand Down
2 changes: 1 addition & 1 deletion src/Blog/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Blog.View where
import Blog.Types
import Blog.Util
import Data.Foldable
import Data.List
import Data.List (intersperse)
import Data.Maybe
import Text.Blaze.Html5 ((!))
import qualified Data.Text as T
Expand Down
2 changes: 1 addition & 1 deletion src/Blog/View/Archive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Blog.Util.Tag
import Blog.View
import Control.Monad
import Data.Foldable
import Data.List
import Data.List (intersperse)
import Data.String
import Data.Time.LocalTime
import System.FilePath
Expand Down
14 changes: 10 additions & 4 deletions src/Blog/View/Feed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import Data.Default
import Data.Maybe
import Data.Time.Clock
import Data.Time.Format
import qualified Data.Time.Format.ISO8601 as ISO8601
import Data.Time.LocalTime
import Text.DublinCore.Types
import Data.Foldable (toList)
import Text.RSS.Export
import Data.Time.Zones
import Text.RSS.Syntax
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
Expand All @@ -24,7 +26,7 @@ import Data.List.NonEmpty (NonEmpty)
viewFeed
:: (?config :: Config)
=> NonEmpty Entry
-> TimeZone
-> TZ
-> TL.Text
viewFeed entries tz = renderElement . xmlRSS $ feedRss entries tz

Expand All @@ -37,7 +39,7 @@ renderElement e = X.renderText def $
feedRss
:: (?config :: Config)
=> NonEmpty Entry
-> TimeZone
-> TZ
-> RSS
feedRss entries tz = (nullRSS feedTitle feedLink)
{ rssChannel = channel
Expand Down Expand Up @@ -70,9 +72,13 @@ feedRss entries tz = (nullRSS feedTitle feedLink)
]
makeUrl = renderUrl
formatDateRfc :: LocalTime -> T.Text
formatDateRfc = T.pack . formatTime defaultTimeLocale rfc822DateFormat . localTimeToUTC tz
formatDateRfc = T.pack . formatTime defaultTimeLocale rfc822DateFormat
. localTimeToUTCTZ tz
formatDateIso :: LocalTime -> T.Text
formatDateIso = T.pack . formatTime defaultTimeLocale (iso8601DateFormat Nothing) . localTimeToUTC tz
formatDateIso = T.pack
. ISO8601.iso8601Show
. utctDay
. localTimeToUTCTZ tz
feedTitle = confTitle <> " — Entries"
feedLink = makeUrl "/"
feedDescription = confDesc
Expand Down

0 comments on commit f68adef

Please sign in to comment.