Code cleanup; name changes and hiding functions
parent
b9a1657171
commit
e6e53be35b
|
@ -1,9 +1,7 @@
|
|||
#! /usr/bin/env nix-shell
|
||||
#! nix-shell -p "haskellPackages.ghcWithPackages (ps: with ps; [dhall neat-interpolation random])"
|
||||
#! nix-shell -i runghc
|
||||
{-
|
||||
Must be run in folder containing the source code
|
||||
-}
|
||||
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
@ -53,7 +51,7 @@ main = do
|
|||
putStrLn "Validated config successfully"
|
||||
|
||||
createDirectoryIfMissing True postsOutputPath'
|
||||
unsafeGenerateAllBlogs config
|
||||
generateAllBlogPosts config
|
||||
putStrLn $ "Generated blog posts successfully to " <> postsOutputPath'
|
||||
|
||||
|
||||
|
@ -61,14 +59,16 @@ main = do
|
|||
For all the blog posts
|
||||
Write them to file
|
||||
-}
|
||||
unsafeGenerateAllBlogs :: Config -> IO ()
|
||||
unsafeGenerateAllBlogs config =
|
||||
forM_ (allBlogPosts config) (writeToFile config)
|
||||
generateAllBlogPosts :: Config -> IO ()
|
||||
generateAllBlogPosts config = forM_ allBlogPosts' writeToFile'
|
||||
where
|
||||
allBlogPosts' = allBlogPosts config
|
||||
writeToFile' = writeToFile config
|
||||
|
||||
allBlogPosts :: Config -> [(FilePath, Text)]
|
||||
allBlogPosts config = map f zippedDates
|
||||
allBlogPosts config = map createSealText zippedDates
|
||||
where
|
||||
f = uncurry $ sealText config
|
||||
createSealText = uncurry $ sealText config
|
||||
zippedDates = zip [1..] (allDatesSince (startDate config))
|
||||
|
||||
allDatesSince :: Day -> [Day]
|
||||
|
@ -129,6 +129,7 @@ sealText config n date = ( fileName', bp)
|
|||
date' = T.pack . show $ date
|
||||
title = T.pack $ "Seal Post Number " <> show n
|
||||
title' = T.replace " " "-" title
|
||||
sealImagesPath' = sealImagesPath config
|
||||
|
||||
bp = blogPost' (toGregorian date)
|
||||
|
||||
|
@ -141,7 +142,7 @@ sealText config n date = ( fileName', bp)
|
|||
"older"
|
||||
"birthdaySeal.jpg"
|
||||
date
|
||||
(sealImagesPath config)
|
||||
sealImagesPath'
|
||||
|
||||
blogPost' (_, 04, 01) =
|
||||
blogPost
|
||||
|
@ -151,7 +152,7 @@ sealText config n date = ( fileName', bp)
|
|||
"supermodel, singing"
|
||||
"singerSeal.jpg"
|
||||
date
|
||||
(sealImagesPath config)
|
||||
sealImagesPath'
|
||||
|
||||
blogPost' (_, _, _) =
|
||||
blogPost
|
||||
|
@ -159,14 +160,23 @@ sealText config n date = ( fileName', bp)
|
|||
(randomPull $ looks config)
|
||||
(randomPull $ adjectives1 config)
|
||||
(randomPull $ adjectives2 config)
|
||||
(randomPull $ unsafeListDirContents $ sealImagesPath config)
|
||||
(randomPull $ unsafeListDirContents sealImagesPath')
|
||||
date
|
||||
(sealImagesPath config)
|
||||
sealImagesPath'
|
||||
|
||||
|
||||
{-
|
||||
Utils
|
||||
-}
|
||||
{-
|
||||
Given a list, returns a random element
|
||||
-}
|
||||
randomPull :: [a] -> a
|
||||
randomPull lst = lst !! r'
|
||||
where
|
||||
r' = randomNum 0 l
|
||||
l = length lst - 1
|
||||
|
||||
{-
|
||||
Gives a random number between from and to
|
||||
Uses unsafeIO to get the number out of IO
|
||||
|
@ -175,14 +185,6 @@ sealText config n date = ( fileName', bp)
|
|||
randomNum :: Random a => a -> a -> a
|
||||
randomNum from to = unsafePerformIO $ randomRIO (from, to)
|
||||
|
||||
{-
|
||||
Given a list, returns a random element
|
||||
-}
|
||||
randomPull :: [a] -> a
|
||||
randomPull lst = lst !! r'
|
||||
where r' = randomNum 0 l
|
||||
l = length lst - 1
|
||||
|
||||
unsafeListDirContents :: FilePath -> [Text]
|
||||
unsafeListDirContents = map T.pack . sort . unsafePerformIO . listDirectory
|
||||
|
||||
|
|
Loading…
Reference in New Issue