Created
January 28, 2013 16:34
-
-
Save tych0/4657021 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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