-- | Module containing rendering functions. All these functions are used to-- render files to the @_site@ directory.moduleText.Hakyll.Render(render,renderAndConcat,renderChain,static,css,writePage)whereimportControl.Arrow((>>>))importControl.Applicative((<$>))importControl.Monad.Reader(liftIO)importSystem.Directory(copyFile)importData.Maybe(fromMaybe)importqualifiedData.MapasMimportText.Hakyll.Context(Context(..))importText.Hakyll.HakyllMonad(Hakyll,askHakyll,getAdditionalContext)importText.Hakyll.FileimportText.Hakyll.HakyllActionimportText.Hakyll.Internal.CompressCssimportText.Hakyll.Internal.Template-- | A pure render function - used internally.pureRender::Template-- ^ Template to use for rendering.->Context-- ^ Renderable object to render with given template.->Context-- ^ The body of the result will contain the render.pureRendertemplate(Contextc)=-- Ignore $root when substituting here. We will only replace that in the-- final render (just before writing).letcontextIgnoringRoot=Context$M.insert"root""$root"cbody=regularSubstitutetemplate$contextIgnoringRootinContext$M.insert"body"bodyc-- | This is the most simple render action. You render a @Context@ with a-- template, and get back the result.render::FilePath-- ^ Template to use for rendering.->HakyllActionContextContext-- ^ The render computation.rendertemplatePath=HakyllAction{actionDependencies=[templatePath],actionUrl=Rightid,actionFunction=\context->flippureRendercontext<$>readTemplatetemplatePath}-- | Render each @Context@ with the given templates, then concatenate the-- result. So, basically this function:---- - Takes every @Context@.---- - Renders every @Context@ with all given templates. This is comparable-- with a renderChain action.---- - Concatenates the result and returns that as a @String@.renderAndConcat::[FilePath]->[HakyllAction()Context]->HakyllAction()StringrenderAndConcattemplatePathsrenderables=HakyllAction{actionDependencies=renders>>=actionDependencies,actionUrl=Rightid,actionFunction=actionFunction'}whererender'=chain(maprendertemplatePaths)renders=map(>>>render')renderablesactionFunction'_=docontexts<-mapMrunHakyllActionrendersreturn$concatMap(fromMaybe"".M.lookup"body".unContext)contexts-- | Chain a render action for a page with a number of templates. This will-- also write the result to the site destination. This is the preferred way-- to do general rendering.---- > renderChain [ "templates/notice.html"-- > , "templates/default.html"-- > ] $ createPagePath "warning.html"---- This code will first render @warning.html@ using @templates/notice.html@,-- and will then render the result with @templates/default.html@.renderChain::[FilePath]->HakyllAction()Context->Hakyll()renderChaintemplatePathsinitial=runHakyllActionIfNeededrenderChainWith'whererenderChainWith'=initial>>>chain'>>>writePagechain'=chain$maprendertemplatePaths-- | Mark a certain file as static, so it will just be copied when the site is-- generated.static::FilePath->Hakyll()staticsource=runHakyllActionIfNeededstatic'wherestatic'=createFileHakyllActionsource$dodestination<-toDestinationsourcemakeDirectoriesdestinationliftIO$copyFilesourcedestination-- | Render a css file, compressing it.css::FilePath->Hakyll()csssource=runHakyllActionIfNeededcss'wherecss'=createFileHakyllActionsource$docontents<-liftIO$readFilesourcedestination<-toDestinationsourcemakeDirectoriesdestinationliftIO$writeFiledestination(compressCsscontents)-- | Write a page to the site destination. Final action after render-- chains and such.writePage::HakyllActionContext()writePage=createHakyllAction$\(ContextinitialContext)->doadditionalContext'<-unContext<$>askHakyllgetAdditionalContextleturl=fromMaybe(error"No url defined at write time.")(M.lookup"url"initialContext)body=fromMaybe""(M.lookup"body"initialContext)letcontext=additionalContext'`M.union`M.singleton"root"(toRooturl)destination<-toDestinationurlmakeDirectoriesdestination-- Substitute $root here, just before writing.liftIO$writeFiledestination$finalSubstitute(fromStringbody)(Contextcontext)