Fix bug in sorting of entryList
authorCameron Ball <cameron@cameron1729.xyz>
Sat, 16 Feb 2019 16:43:12 +0000 (00:43 +0800)
committerCameron Ball <cameron@cameron1729.xyz>
Sat, 16 Feb 2019 16:43:12 +0000 (00:43 +0800)
src/Lib.hs

index 80cf44f..a0f089e 100644 (file)
@@ -31,10 +31,10 @@ type EntryList = [(Text, [(Text, [(Text, BlogEntry)])])]
 format t format = fromString $ formatTime defaultTimeLocale format $ utcToLocalTime (hoursToTimeZone 8) t
 
 myGroup :: (Eq a, Ord a) => [(a, b)] -> [(a, [b])]
-myGroup = map (\l -> (fst . head $ l, map snd l)) . groupBy ((==) `on` fst)
+myGroup = map (\l -> (fst . head $ l, map snd l)) . groupBy ((==) `on` fst) . sortBy (comparing fst)
 
 stampsToEntryList :: [BlogEntry] -> EntryList
-stampsToEntryList stamps = map (\(a,b) -> (a, reverse $ map (\(c,d) -> (c, map (\(x, y) -> ("0" `append` (fromString . show) x, y)) $ zip [1..] d)) b)) $
+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 $
                            foldl (\c -> \v ->
@@ -49,12 +49,13 @@ entryListToPaths el = concat $ concat $ map (\(year, months)
                                                        month) entries) months) el
 
 entryListToIndex :: EntryList -> Text
-entryListToIndex el = unorderedList Nothing $ map (\(year, monthList) -> unorderedList (Just year) $ map (\(month, entryList) -> unorderedList (Just month) $ map (\x -> "<a href=\"" <> year <> "/" <> month <> "/" <> ((slugify . title . snd) x) <>  ".html\">" <> (title . snd) x <> "</a>") entryList) monthList) el
+entryListToIndex el = unorderedList Nothing $ map (\(year, monthList) -> unorderedList (Just year) $ map (\(month, entryList) -> unorderedList (Just month) $ map (\x -> "<a href=\"" <> year <> "/" <> month <> "/" <> ((urlify . title . snd) x) <>  ".html\">" <> (title . snd) x <> "</a>") entryList) monthList) el
 
 i2t :: Integer -> Text
 i2t = (fromString . show)
 
 slugify = toLower. replace " " "-"
+urlify = slugify . replace "?" ""
 
 timeStampToDateString = fromString . formatTime defaultTimeLocale "%d %B %Y" . utcToLocalTime (hoursToTimeZone 8)
 
@@ -97,7 +98,7 @@ exportEntry entry = do
                 "build",
                 format (postDate entry) "%Y",
                 format (postDate entry) "%B",
-                slugify (title entry) `append` ".html"]) $ unpack $ entryToMarkup entry entryTemplate
+                urlify (title entry) `append` ".html"]) $ unpack $ entryToMarkup entry entryTemplate
 
 exportIndex :: EntryList -> IO()
 exportIndex entryList = do