import Development.Shake import Development.Shake.Command import Development.Shake.FilePath import Development.Shake.Util main :: IO () main = do let shOpts = shakeOptions { shakeVerbosity = Chatty, shakeLintInside = ["\\"] } shakeArgsForward shOpts buildRules buildRules :: Action () buildRules = do allPosts <- buildPosts buildIndex allPosts buildFeed allPosts copyStaticFiles -- | Find and build all posts buildPosts :: Action [Post] buildPosts = do pPaths <- getDirectoryFiles "." ["site/posts//*.md"] forP pPaths buildPost -- | Load a post, process metadata, write it to output, then return the post object -- Detects changes to either post content or template buildPost :: FilePath -> Action Post buildPost srcPath = cacheAction ("build" :: T.Text, srcPath) $ do liftIO . putStrLn $ "Rebuilding post: " <> srcPath postContent <- readFile' srcPath -- load post content and metadata as JSON blob postData <- markdownToHTML . T.pack $ postContent let postUrl = T.pack . dropDirectory1 $ srcPath -<.> "html" withPostUrl = _Object . at "url" ?~ String postUrl -- Add additional metadata we've been able to compute let fullPostData = withSiteMeta . withPostUrl $ postData template <- compileTemplate' "site/templates/post.html" writeFile' (outputFolder T.unpack postUrl) . T.unpack $ substitute template fullPostData convert fullPostData