Skip to content
Browse files

Make $root$ and $gendate$ available in all templates.

  • Loading branch information...
1 parent 3a323eb commit 404b69b6a776521cc43152e2e52013dd65e5f1f5 @jgm committed
Showing with 9 additions and 4 deletions.
  1. +9 −4 Yst/Render.hs
View
13 Yst/Render.hs
@@ -100,6 +100,7 @@ formatFromExtension f = case (map toLower $ takeExtension f) of
".txt" -> PlainFormat
".markdown" -> PlainFormat
_ -> HtmlFormat
+
renderPage :: Site -> Page -> IO String
renderPage site page = do
let menuHtml = renderNav (pageUrl page) (navigation site)
@@ -109,18 +110,22 @@ renderPage site page = do
let g = foldl1 mergeSTGroups gs
attrs <- forM (pageData page) $ \(k, v) -> getData site v >>= \n -> return (k,n)
todaysDate <- liftM utctDay getCurrentTime
+ let root' = case length (filter (=='/') $ pageUrl page) of
+ 0 -> ""
+ n -> concat $ replicate n "../"
rawContents <-
case sourceFile page of
SourceFile sf -> liftM (filter (/='\r')) $ searchPath srcDirs sf >>= readFile
TemplateFile tf -> do
templ <- getTemplate tf g
- return $ render (setManyAttrib attrs templ)
+ return $ render
+ . setManyAttrib attrs
+ . setAttribute "root" root'
+ . setAttribute "gendate" todaysDate
+ $ templ
layoutTempl <- getTemplate layout g
let format = formatFromExtension (stripStExt layout)
let contents = converterForFormat format rawContents
- let root' = case length (filter (=='/') $ pageUrl page) of
- 0 -> ""
- n -> concat $ replicate n "../"
return $ render
. setManyAttrib attrs
. setAttribute "sitetitle" (siteTitle site)

0 comments on commit 404b69b

Please sign in to comment.
Something went wrong with that request. Please try again.