orErrorHakyllPage :: (MonadIO m,HasPlugin Hakyll t m,Pretty a) => FilePath -> a -> Haap t m a -> Haap t m a
orErrorHakyllPage page def m = orDo go m
  where
    go e = do
        hp <- getHakyllP
        hakyllFocus ["templates"] $ hakyllRules $ create [fromFilePath page] $ do
            route $ idRoute `composeRoutes` (funRoute $ hakyllRoute hp)
            compile $ do
                let errCtx = constField "errorMessage" (H.renderHtml $ H.toHtml $ prettyString e)
                             `mappend` constField "projectpath" (fileToRoot $ hakyllRoute hp page)
                makeItem "" >>= loadAndApplyHTMLTemplate "templates/error.html" errCtx >>= hakyllCompile hp
        return $! def
orErrorHakyllPage :: (MonadIO m,HasPlugin Hakyll t m,Pretty a) => FilePath -> a -> Haap t m a -> Haap t m a
orErrorHakyllPage page def m = orDo go m
  where
    go e = do
        hp <- getHakyllP
        hakyllFocus ["templates"] $ hakyllRules $ create [fromFilePath page] $ do
            route $ idRoute `composeRoutes` (funRoute $ hakyllRoute hp)
            compile $ do
                let errCtx = constField "errorMessage" (H.renderHtml $ H.toHtml $ prettyString e)
                             `mappend` constField "projectpath" (fileToRoot $ hakyllRoute hp page)
                makeItem "" >>= loadAndApplyHTMLTemplate "templates/error.html" errCtx >>= hakyllCompile hp
        return $! def
orErrorHakyllPage page def m = orDo go m
  where
    go e = do
        hp <- getHakyllP
        hakyllFocus ["templates"] $ hakyllRules $ create [fromFilePath page] $ do
            route $ idRoute `composeRoutes` (funRoute $ hakyllRoute hp)
            compile $ do
                let errCtx = constField "errorMessage" (H.renderHtml $ H.toHtml $ prettyString e)
                             `mappend` constField "projectpath" (fileToRoot $ hakyllRoute hp page)
                makeItem "" >>= loadAndApplyHTMLTemplate "templates/error.html" errCtx >>= hakyllCompile hp
        return $! def