"/" `append`
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
+
i2t :: Integer -> Text
i2t = (fromString . show)
Nothing -> []
Just a -> [("video", a)]
-wrapInTags tag text = intercalate "" $ map ((`append` close) . (open `append`)) text where
- close = "</" `append` tag `append` ">"
- open = "<" `append` tag `append` ">"
+wrapInTags :: Text -> [Text] -> Text
+wrapInTags tag = foldMap $ (<> close) . (open <>)
+ where close = "</" `append` tag `append` ">"
+ open = "<" `append` tag `append` ">"
paragraphs = wrapInTags "p"
+unorderedList :: Maybe Text -> [Text] -> Text
+unorderedList heading items = case heading of
+ Just x -> x `append` unorderedList Nothing items
+ Nothing -> "<ul>" `append` (wrapInTags "li" items) `append` "</ul>"
+
rawTextToEntry rawEntry = BlogEntry (posixSecondsToUTCTime (fromInteger (read (unpack $ meta !! 0)))) (meta !! 1) (paragraphs (snd (splitAt 1 fileLines))) (lookup 2 metaMap)
where
metaMap = zip [0..] meta
meta = splitOn "::" (fileLines !! 0)
fileLines = lines rawEntry
-allFilesIn dir = filter (/= "..")<$>(filter(/= "."))<$>(getDirectoryContents dir)
+allFilesIn dir = filter (/= "..")<$>(filter(/= "."))<$>(filter(/= ".gitignore"))<$>(getDirectoryContents dir)
exportEntry entry = do
rawTemplateNormal <- readFile "templates/entry.html"
format (postDate entry) "%B",
slugify (title entry) `append` ".html"]) $ unpack $ entryToMarkup entry entryTemplate
+exportIndex :: EntryList -> IO()
+exportIndex entryList = do
+ rawTemplate <- readFile "templates/index.html"
+
+ let indexTemplate = template . pack $ rawTemplate
+ let indexContext = context [("index", entryListToIndex entryList)]
+
+ writeFile "build/index.html" $ unpack $ toStrict $ render indexTemplate indexContext
+
someFunc = do
- files <- allFilesIn "./entries"
+ files <- 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
- mapM_ (putStrLn . unpack) entryPaths
mapM_ (createDirectoryIfMissing True . ("build/" ++) . unpack) entryPaths
mapM_ exportEntry entryList
+ exportIndex $ stampsToEntryList entryList
context :: [(Text, Text)] -> Context
context assocs x = case lookup x $ assocs of