Get build command working and fix ordering of blog posts
authorCameron Ball <cameron@cameron1729.xyz>
Tue, 12 Mar 2019 18:53:53 +0000 (02:53 +0800)
committerCameron Ball <cameron@cameron1729.xyz>
Tue, 12 Mar 2019 18:53:53 +0000 (02:53 +0800)
app/Main.hs
src/Lib.hs

index 601f13f..21dfb7e 100644 (file)
@@ -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
 
index a0f089e..1954a89 100644 (file)
@@ -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