Browse Source

Trying to get image manipulation set up

image-sizing
Logan McGrath 7 months ago
parent
commit
f64d3c2c87
  1. 1
      config.ini
  2. 5
      green.cabal
  3. 4
      package.yaml
  4. 6
      src/Green/Compiler/Image.hs
  5. 12
      src/Green/Config.hs
  6. 12
      src/Green/Rule.hs
  7. 7
      stack.yaml
  8. 26
      stack.yaml.lock

1
config.ini

@ -11,6 +11,7 @@ gitWebUrl = https://bitsof.thisfieldwas.green/keywordsalad/thisfieldwas.green/sr
dateShortFormat = %B %e, %Y
dateLongFormat = %B %e, %Y %l:%M %P %EZ
timeFormat = %l:%M %p %EZ
imageWidths = 320, 768, 1024, 1920, 3840
[Hakyll]
providerDirectory = site

5
green.cabal

@ -8,7 +8,7 @@ name: green
version: 0.1.0.0
description: Please see the README at <https://bitsof.thisfieldwas.green/keywordsalad/thisfieldwas.green#readme>
author: Logan McGrath
maintainer: website@thisfieldwas.green
maintainer: logan.mcgrath@thisfieldwas.green
copyright: Copyright (C) 2012-2021 Logan McGrath
license: BSD3
build-type: Simple
@ -25,6 +25,7 @@ library
Green.Command
Green.Common
Green.Compiler
Green.Compiler.Image
Green.Config
Green.Lens
Green.Lens.Hakyll
@ -105,7 +106,7 @@ library
ViewPatterns
ghc-options: -fprint-potential-instances -Wall -Werror -Wcompat -Widentities -Wincomplete-patterns -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-deriving-strategies -Wmissing-home-modules -Wname-shadowing -Wpartial-fields -Wredundant-constraints -Wunused-packages -Wunused-type-patterns
build-depends:
MissingH
JuicyPixels
, aeson
, base >=4.14 && <5
, binary

4
package.yaml

@ -3,7 +3,7 @@ version: 0.1.0.0
git: https://bitsof.thisfieldwas.green/keywordsalad/thisfieldwas.green
license: BSD3
author: Logan McGrath
maintainer: "website@thisfieldwas.green"
maintainer: "logan.mcgrath@thisfieldwas.green"
copyright: "Copyright (C) 2012-2021 Logan McGrath"
extra-source-files:
@ -26,9 +26,9 @@ library:
- filepath
- hakyll
- hjsmin
- JuicyPixels
- microlens
- microlens-th
- MissingH
- mtl
- optparse-applicative
- pandoc

6
src/Green/Compiler/Image.hs

@ -0,0 +1,6 @@
module Green.Compiler.Image where
import Green.Common
imageCompiler :: [Int] -> Item a
imageCompiler sizes = do

12
src/Green/Config.hs

@ -24,7 +24,8 @@ defaultSiteDebug =
data SiteDisplayFormat = SiteDisplayFormat
{ _displayDateLongFormat :: String,
_displayDateShortFormat :: String,
_displayTimeFormat :: String
_displayTimeFormat :: String,
_displayImageWidths :: String
}
makeLenses ''SiteDisplayFormat
@ -42,7 +43,7 @@ data SiteConfig = SiteConfig
_siteHakyllConfiguration :: Configuration,
_siteTime :: ZonedTime,
_siteTimeLocale :: TimeLocale,
_siteDisplayFormat :: SiteDisplayFormat
_siteDisplayFormat :: SiteDisplayFormat,
}
makeLenses ''SiteConfig
@ -79,7 +80,7 @@ parseConfigIni env timeLocale time iniText = parseIniFile iniText do
hakyllConfiguration <- section "Hakyll" do
providerDirectory' <- fieldOf "providerDirectory" string
destinationDirectory' <- fieldOf "destinationDirectory" string
allowedFiles <- fieldOfStrings "allowedFiles"
allowedFiles <- fieldListOf "allowedFiles" string
return
HC.defaultConfiguration
{ providerDirectory = providerDirectory',
@ -97,6 +98,7 @@ parseConfigIni env timeLocale time iniText = parseIniFile iniText do
<$> fieldOf "dateLongFormat" string
<*> fieldOf "dateShortFormat" string
<*> fieldOf "timeFormat" string
<*> fieldListOf "imageWidths" number
section "Site" do
SiteConfig env
@ -117,8 +119,8 @@ parseConfigIni env timeLocale time iniText = parseIniFile iniText do
ignoreFile defaultConfiguration path
&& takeFileName path `notElem` allowedFiles
fieldOfStrings :: Text -> SectionParser [String]
fieldOfStrings k = fieldDefOf k (listWithSeparator "," string) []
fieldListOf :: Text -> (Text -> Either String a) -> SectionParser [String]
fieldListOf k p = fieldDefOf k (listWithSeparator "," p) []
configEnvFlag :: String -> String -> Bool -> [(String, String)] -> SectionParser Bool
configEnvFlag configKey envKey defaultValue env =

12
src/Green/Rule.hs

@ -47,11 +47,17 @@ codeRules = do
compile getResourceBody
makePatternDependency path
imageRules :: Rules ()
imageRules =
imageRules :: SiteConfig -> Rules ()
imageRules config = do
let x =
config .^ siteDisplayFormat . displayImageWidths <&> \width ->
group ("images-" ++ show width) do
match "images/**" do
route $ gsubRoute ".\\w+$" (\s -> "-" ++ show width ++ s)
compile $ imageCompiler width
match "images/**" do
route idRoute
compile H.copyFileCompiler
compile $ imageCompiler (config .^ siteDisplayFormat . displayImageWidths)
templateRules :: Rules ()
templateRules = do

7
stack.yaml

@ -17,8 +17,7 @@
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-18.2
compiler: ghc-8.10.4
resolver: nightly-2021-10-12
# User packages to be built.
# Various formats can be used as shown in the example below.
@ -41,9 +40,7 @@ packages:
# - git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
#
extra-deps:
- hakyll-4.14.0.0
- MissingH-1.4.3.0
extra-deps: []
# Override default flag values for local packages and extra-deps
# flags: {}

26
stack.yaml.lock

@ -3,24 +3,10 @@
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files
packages:
- completed:
hackage: hakyll-4.14.0.0@sha256:28aab547aa94202d486328aa4bbcd02ecbefc4e5d42dfa15e8137b731a4f5d55,9059
pantry-tree:
size: 8272
sha256: b5dff3f9f3c9bc32b154d8f5b30f88fc12f88a32dd7a10ac7f16584af5059b3f
original:
hackage: hakyll-4.14.0.0
- completed:
hackage: MissingH-1.4.3.0@sha256:32f9892ec98cd21df4f4d3ed8d95a3831ae74287ea0641d6f09b2dc6ef061d39,4859
pantry-tree:
size: 5271
sha256: 6cd6a7213615d72a7db3234c7fcd4346ceb4889bc8fb14b302b5878768018fcd
original:
hackage: MissingH-1.4.3.0
snapshots:
- completed:
size: 585392
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/2.yaml
sha256: 7abb45c0cc5eb349448b66d8753655542d45d387ad26970419282eab3d860724
original: lts-18.2
- original: nightly-2021-10-12
completed:
sha256: 16f87f3537744b964b3d924e9e9a4a51fafdd93d31822ddd21a5663475f995ee
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2021/10/12.yaml
size: 585552
packages: []

Loading…
Cancel
Save