From 4e1eeb524207ef09f0c5b5e17b2c424e4e351e72 Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Wed, 13 Mar 2019 02:53:53 +0800 Subject: [PATCH] Get build command working and fix ordering of blog posts --- app/Main.hs | 2 +- src/Lib.hs | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 601f13f..21dfb7e 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -44,7 +44,7 @@ usage = putStr . ununlines $ [ ] parse ["init"] = init >> exit -parse ["build"] = putStrLn "would do a build" >> exit +parse ["build"] = someFunc >> exit parse [_] = usage >> exit parse [] = usage >> exit diff --git a/src/Lib.hs b/src/Lib.hs index a0f089e..1954a89 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -5,7 +5,7 @@ module Lib ) where import Data.Function (on) -import Data.List (sortBy, groupBy) +import Data.List (sort, sortBy, groupBy) import Data.Ord (comparing) import Data.String hiding (lines) import Data.Text hiding (groupBy, map, concat, foldl, head, splitAt, filter, zip, length, reverse) @@ -33,10 +33,13 @@ format t format = fromString $ formatTime defaultTimeLocale format $ utcToLocalT myGroup :: (Eq a, Ord a) => [(a, b)] -> [(a, [b])] myGroup = map (\l -> (fst . head $ l, map snd l)) . groupBy ((==) `on` fst) . sortBy (comparing fst) +myGroupNoSort :: (Eq a, Ord a) => [(a, b)] -> [(a, [b])] +myGroupNoSort = map (\l -> (fst . head $ l, map snd l)) . groupBy ((==) `on` fst) + stampsToEntryList :: [BlogEntry] -> EntryList -stampsToEntryList stamps = reverse $ map (\(a,b) -> (a, reverse $ map (\(c,d) -> (c, map (\(x, y) -> ("0" `append` (fromString . show) x, y)) $ zip [1..] d)) b)) $ - map (\(a, b) -> (a, myGroup b)) $ - map (\(a, b) -> (a, concat b)) $ myGroup $ +stampsToEntryList stamps = map (\(a,b) -> (a, reverse $ map (\(c,d) -> (c, reverse $ map (\(x, y) -> ("0" `append` (fromString . show) x, y)) $ zip [1..] d)) b)) $ + map (\(a, b) -> (a, myGroupNoSort b)) $ + map (\(a, b) -> (a, concat b)) $ myGroupNoSort $ foldl (\c -> \v -> c ++ [(format (postDate v) "%Y", [(format (postDate v) "%B", v)])]) [] stamps @@ -110,7 +113,7 @@ exportIndex entryList = do writeFile "build/index.html" $ unpack $ toStrict $ render indexTemplate indexContext someFunc = do - files <- allFilesIn "entries" + files <- fmap (reverse . sort) $ allFilesIn "entries" rawEntries <- mapM (\x -> (readFile ("entries/" ++ x)) >>= (\y -> (return . fromString) y)) files entryList <- mapM (\raw -> return $ rawTextToEntry raw) rawEntries entryPaths <- return $ entryListToPaths $ stampsToEntryList entryList -- 2.11.0