~jack/jackkelly-name

04c652107f164d8b1841a55d039abd16b02e486d — Jack Kelly 1 year, 9 months ago 0230f1d
Move slug function from Blog to Site
4 files changed, 14 insertions(+), 15 deletions(-)

M jackkelly-name.cabal
M src/Blog/Posts.hs
M src/Site.hs
R test/{Blog/PostsSpec.hs => SiteSpec.hs}
M jackkelly-name.cabal => jackkelly-name.cabal +1 -1
@@ 56,7 56,7 @@ test-suite test
  hs-source-dirs:     test
  default-language:   Haskell2010
  ghc-options:        -Wall
  other-modules:      Blog.PostsSpec
  other-modules:      SiteSpec
  build-depends:      base >= 4.11.1 && < 4.13
                    , hspec >= 2.5.5 && < 2.7
                    , jackkelly-name

M src/Blog/Posts.hs => src/Blog/Posts.hs +1 -11
@@ 3,13 3,11 @@ module Blog.Posts
  , blogPostCompiler -- Temp for garagesale page
  , blogPostsPattern
  , blogPostContext
  , slug
  ) where

import           Blog.Util (baseBlogContext, parseBlogDate)
import           Control.Applicative (empty)
import           Data.Aeson (Value(..))
import           Data.Char (toLower)
import           Data.Default (def)
import           Data.HashMap.Lazy ((!))
import           Data.List (sort)


@@ 17,7 15,7 @@ import qualified Data.Map as Map
import qualified Data.Text as T
import           Data.Time (defaultTimeLocale, formatTime)
import           Hakyll
import           Site (sectionLabel)
import           Site (sectionLabel, slug)
import           System.FilePath ((</>))
import qualified Text.Pandoc as P



@@ 85,11 83,3 @@ blogPostContext tags = do
    , teaserField "teaser" "content"
    , baseBlogContext
    ]

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 ]

M src/Site.hs => src/Site.hs +10 -1
@@ 1,6 1,7 @@
module Site (Url(..), baseSiteContext, sectionLabel) where
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)


@@ 16,3 17,11 @@ baseSiteContext = field "current_year" currentYear <> defaultContext where

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 ]

R test/Blog/PostsSpec.hs => test/SiteSpec.hs +2 -2
@@ 1,6 1,6 @@
module Blog.PostsSpec where
module SiteSpec where

import Blog.Posts (slug)
import Site (slug)
import Data.Foldable (for_)
import Test.Hspec