Browse Source

Making lenses for hakyll config types

image-sizing
Logan McGrath 11 months ago
parent
commit
a4886e0857
  1. 7
      logans-site.cabal
  2. 1
      package.yaml
  3. 4
      src/Site/Common.hs
  4. 15
      src/Site/Config.hs
  5. 10
      src/Site/Lens.hs
  6. 7
      src/Site/Lens/Hakyll.hs
  7. 2
      test/Site/Spec/Common.hs

7
logans-site.cabal

@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 9a35c08a9d6989bc59e76bcec423a66ecb6b9ef0cc57cce3fc5d7b1376e0b0cc
-- hash: d9716e3f43d029a60421af48f4fd6f80d43ac0f2e0166a7fad8275eb0a98e5a9
name: logans-site
version: 0.1.0.0
@ -36,6 +36,8 @@ library
Site.Context.GitCommits
Site.Context.Post
Site.Context.Tag
Site.Lens
Site.Lens.Hakyll
Site.Route
Site.Rule
Site.Rule.Blog
@ -113,6 +115,7 @@ library
, pandoc-types ==1.22.*
, process ==1.6.*
, tagsoup ==0.14.*
, template-haskell ==2.16.*
, text ==1.2.*
, time ==1.9.*
, transformers ==0.5.*
@ -232,6 +235,7 @@ executable logans-site-exe
, pandoc-types ==1.22.*
, process ==1.6.*
, tagsoup ==0.14.*
, template-haskell ==2.16.*
, text ==1.2.*
, time ==1.9.*
, transformers ==0.5.*
@ -358,6 +362,7 @@ test-suite logans-site-test
, pandoc-types ==1.22.*
, process ==1.6.*
, tagsoup ==0.14.*
, template-haskell ==2.16.*
, text ==1.2.*
, time ==1.9.*
, transformers ==0.5.*

1
package.yaml

@ -32,6 +32,7 @@ dependencies:
- pandoc-types == 1.22.*
- process == 1.6.*
- tagsoup == 0.14.*
- template-haskell == 2.16.*
- text == 1.2.*
- time == 1.9.*
- transformers == 0.5.*

4
src/Site/Common.hs

@ -15,6 +15,8 @@ module Site.Common
module Site.Compiler.Pandoc,
module Site.Context.Field,
module Site.Context,
module Site.Lens,
module Site.Lens.Hakyll,
module Site.Route,
module Site.Util,
module System.Directory,
@ -38,6 +40,8 @@ import Site.Compiler.Pandoc
import Site.Config
import Site.Context
import Site.Context.Field
import Site.Lens
import Site.Lens.Hakyll
import Site.Route
import Site.Util
import System.Directory (copyFile, createDirectoryIfMissing, doesFileExist)

15
src/Site/Config.hs

@ -10,6 +10,7 @@ import Hakyll
import Hakyll.Core.Configuration as HC
import Lens.Micro
import Lens.Micro.TH
import Site.Lens.Hakyll
import System.FilePath
data SiteConfig = SiteConfig
@ -30,23 +31,17 @@ data SiteConfig = SiteConfig
makeLenses ''SiteConfig
makeHakyllConfigLens :: (Configuration -> a) -> (Configuration -> a -> Configuration) -> Lens' SiteConfig a
makeHakyllConfigLens getter setter = lens getter' setter'
where
getter' siteConfig = getter (siteConfig ^. siteHakyllConfiguration)
setter' siteConfig val = siteConfig & siteHakyllConfiguration %~ flip setter val
siteDestinationDirectory :: Lens' SiteConfig FilePath
siteDestinationDirectory = makeHakyllConfigLens destinationDirectory (\h v -> h {destinationDirectory = v})
siteDestinationDirectory = siteHakyllConfiguration . destinationDirectoryL
siteProviderDirectory :: Lens' SiteConfig FilePath
siteProviderDirectory = makeHakyllConfigLens providerDirectory (\h v -> h {providerDirectory = v})
siteProviderDirectory = siteHakyllConfiguration . providerDirectoryL
siteStoreDirectory :: Lens' SiteConfig FilePath
siteStoreDirectory = makeHakyllConfigLens storeDirectory (\h v -> h {storeDirectory = v})
siteStoreDirectory = siteHakyllConfiguration . storeDirectoryL
siteInMemoryCache :: Lens' SiteConfig Bool
siteInMemoryCache = makeHakyllConfigLens inMemoryCache (\h v -> h {inMemoryCache = v})
siteInMemoryCache = siteHakyllConfiguration . inMemoryCacheL
hasEnvFlag :: String -> [(String, String)] -> Bool
hasEnvFlag f e = isJust (lookup f e)

10
src/Site/Lens.hs

@ -0,0 +1,10 @@
module Site.Lens where
import Language.Haskell.TH
import Lens.Micro
import Lens.Micro.TH
makeLensesWithL :: Name -> DecsQ
makeLensesWithL = makeLensesWith $ lensRules & lensField .~ lensFieldL
where
lensFieldL _ _ n = [TopName (mkName (nameBase n ++ "L"))]

7
src/Site/Lens/Hakyll.hs

@ -0,0 +1,7 @@
module Site.Lens.Hakyll where
import Hakyll
import Site.Lens
makeLensesWithL ''Configuration
makeLensesWithL ''FeedConfiguration

2
test/Site/Spec/Common.hs

@ -52,7 +52,7 @@ defaultFeedConfig =
{ feedTitle = "This Old Feed",
feedDescription = "Feeding the old worm the good stuff",
feedAuthorName = "Slurms McKenzie",
feedAuthorEmail = "slurms@wormitup.net",
feedAuthorEmail = "slurms@thisold.blog",
feedRoot = "https://thisold.blog"
}

Loading…
Cancel
Save