ref: 3088d06a8c6a12db3c784003d823220e168905d6 jackkelly-name/src/Site.hs -rw-r--r-- 982 bytes View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Site (Url(..), baseSiteContext, sectionLabel, slug) where

import Control.Lens (_1, view)
import Data.Char (toLower)
import Data.List (intercalate)
import Data.Time.Calendar (toGregorian)
import Data.Time.Clock (getCurrentTime)
import Data.Time.LocalTime (getCurrentTimeZone, localDay, utcToLocalTime)
import Hakyll

newtype Url = Url { unUrl :: String } deriving Show

baseSiteContext :: Context String
baseSiteContext = field "current_year" currentYear <> defaultContext where
  currentYear = const . unsafeCompiler $ show . view _1 . toGregorian . localDay
    <$> (utcToLocalTime <$> getCurrentTimeZone <*> getCurrentTime)

sectionLabel :: [String] -> String
sectionLabel = intercalate " | " . reverse . ("jackkelly.name":)

slug :: String -> String
slug = filter (not . (`elem` ("',!?()+:" :: String)))
  . replace "&. " '_'
  . map toLower
  where
    replace :: String -> Char -> String -> String
    replace from to xs = [ if x `elem` from then to else x | x <- xs ]