From 7628e8c32346134aa12c9087c0d64bf9acf831a2 Mon Sep 17 00:00:00 2001 From: Eduardo Trujillo <ed@chromabits.com> Date: Mon, 1 Aug 2016 14:11:52 -0700 Subject: [PATCH] feat(site): Use Hackage version of kawaii --- app/site.hs | 61 ++++++++++++++++++++++++++--------------------------- stack.yaml | 6 ++---- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/app/site.hs b/app/site.hs index 64405bf..8a7ed28 100644 --- a/app/site.hs +++ b/app/site.hs @@ -94,8 +94,7 @@ main = hakyllServeWith serveConf $ do matchMetadata "posts/*" (HM.member "legacy") $ version "legacy" $ do route $ legacyRoute `composeRoutes` setExtension "html" compile $ do - color <- unsafeCompiler (randomRIO (0, length colors - 1) - >>= \selection -> pure (colors !! selection)) + color <- unsafeCompiler pickColor identifier <- getUnderlying let ctx @@ -117,8 +116,7 @@ main = hakyllServeWith serveConf $ do match "posts/*" $ do route $ directorizeDate "/index" `composeRoutes` setExtension "html" compile $ do - color <- unsafeCompiler (randomRIO (0, length colors - 1) - >>= \selection -> pure (colors !! selection)) + color <- unsafeCompiler pickColor identifier <- getUnderlying let ctx @@ -216,31 +214,27 @@ main = hakyllServeWith serveConf $ do >>= relativizeUrls >>= deIndexUrls - paginateRules pag $ \pageNum pattern -> do - route idRoute - compile $ do - tpl <- loadBody "templates/post-item-full.html" - - let paginateCtx = paginateContext pag pageNum - let ctx - = paginateCtx - <> constField "title" ("Page " ++ show pageNum) - <> indexCtx - - loadAllSnapshots pattern "content" - >>= recentFirst - >>= applyTemplateList tpl ctx - >>= makeItem - >>= loadAndApplyTemplate - "templates/paginated.html" - (ctx <> bodyField "posts") - >>= loadAndApplyTemplate - "templates/default.html" - (ctx <> bodyField "posts") - >>= relativizeUrls - >>= deIndexUrls - - match "templates/*" $ compile templateCompiler + paginateRules pag $ \pageNum patterns -> do + route idRoute + compile $ do + template <- loadBody "templates/post-item-full.html" + + let context + = paginateContext pag pageNum + <> constField "title" ("Page " <> show pageNum) + <> indexCtx + bodyContext = context <> bodyField "posts" + + loadAllSnapshots patterns "content" + >>= recentFirst + >>= applyTemplateList template context + >>= makeItem + >>= loadAndApplyTemplate "templates/paginated.html" bodyContext + >>= loadAndApplyTemplate "templates/default.html" bodyContext + >>= relativizeUrls + >>= deIndexUrls + + match "templates/*" $ compile templateCompiler -- CONTEXTS ------------------------------------------------------------------- @@ -272,7 +266,7 @@ directorizeDate postfix = customRoute (directorize . toFilePath) (date, rest) = splitAt 3 $ splitOn "-" path indexify :: Routes -indexify = customRoute (\i -> addIndex $ toFilePath i) +indexify = customRoute (addIndex . toFilePath) where addIndex path = original ++ "/index" ++ ext where @@ -302,13 +296,18 @@ matchAndCopy (path, extension) = match path $ do -- IDENTIFIER HELPERS --------------------------------------------------------- grouper :: MonadMetadata m => [Identifier] -> m [[Identifier]] -grouper ids = (liftM (paginateEvery 3) . sortRecentFirst) ids +grouper = fmap (paginateEvery 3) . sortRecentFirst makeId :: PageNumber -> Identifier makeId pageNum = fromFilePath $ "page/" ++ show pageNum ++ "/index.html" -- UTILITIES ------------------------------------------------------------------ +pickColor :: IO String +pickColor = do + selection <- randomRIO (0, length colors - 1) + pure $ colors !! selection + stripIndex :: String -> String stripIndex url = if "index.html" `isSuffixOf` url && elem (head url) ("/." :: String) diff --git a/stack.yaml b/stack.yaml index 8fc031e..6a6d792 100644 --- a/stack.yaml +++ b/stack.yaml @@ -6,12 +6,10 @@ resolver: lts-6.7 # Local packages, usually specified by relative directory name packages: - '.' -- location: - git: https://phabricator.chromabits.com/diffusion/KWAI/kawaii.git - commit: 50bf3ff2edeeb8a68b585fee19d255af377e37b3 # Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) -extra-deps: [] +extra-deps: +- kawaii-0.0.1.0 # Override default flag values for local packages and extra-deps flags: {} -- GitLab