Skip to content

Instantly share code, notes, and snippets.

@tych0
Created January 28, 2013 16:34
Show Gist options
  • Save tych0/4657021 to your computer and use it in GitHub Desktop.
Save tych0/4657021 to your computer and use it in GitHub Desktop.
buildSite :: String -> String -> IO [IO ()]
buildSite src tgt = do
templates <- readTemplates $ src </> "templates"
actions <- foldWithHandler
ignoreExceptions
always
(\acc info -> makeAction info : acc)
[]
src
return $ reverse actions
where
ignoreExceptions _ a _ = return a
mkTgtName :: FilePath -> FilePath
mkTgtName = (</>) tgt . makeRelative src
makeAction :: FileInfo -> IO ()
makeAction info | (isDirectory . infoStatus) info =
(createDirectoryIfMissing True . mkTgtName . infoPath) info
makeAction info | supported info = do
html <- (renderContent . infoPath) info
let target = replaceExtension (mkTgtName . infoPath $ info) ".html"
content = renderHtmlFragment UTF8 html
page = hq "#content" content $ root templates
BS.writeFile target $ toLazyByteString page
makeAction info | (isRegularFile . infoStatus) info =
let path = infoPath info in
copyFile path (mkTgtName path)
makeAction _ = return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment