diff options
Diffstat (limited to 'site.hs')
| -rw-r--r-- | site.hs | 33 |
1 files changed, 25 insertions, 8 deletions
@@ -12,6 +12,7 @@ import Data.List (nub) import Data.List.Extra (stripSuffix) import qualified Data.Map as M import Data.Maybe (fromMaybe, isJust) +import qualified Data.Set as S import Data.String (fromString) import qualified Data.Text as T import qualified Data.Text.Encoding @@ -24,11 +25,11 @@ import Lens.Micro.Mtl import System.Environment (getArgs) import System.FilePath ((</>), splitPath) import qualified Text.Mustache as Mu -import qualified Text.Parsec.Error import Text.Pandoc.Class (runIOorExplode) import qualified Text.Pandoc.Extensions import Text.Pandoc.Options (ReaderOptions(..)) import Text.Pandoc.Readers.Markdown (readMarkdown) +import qualified Text.Parsec.Error import Types @@ -91,12 +92,18 @@ pageTemplate pi = do -- | Collect all templates required for rendering the currently loaded pages. pageTemplates :: Site [FilePath] -pageTemplates = nub <$> (gets (^.. pages . traverse) >>= traverse pageTemplate) - -compileTemplate :: FilePath -> FilePath -> Site (Either Text.Parsec.Error.ParseError Mu.Template) -compileTemplate templdir templ = io $ do - putStrLn $ "TTT " ++ (templdir </> templ) - Mu.automaticCompile [templdir] templ +pageTemplates = do + rt <- use redirectTemplate + nub . (rt :) <$> (gets (^.. pages . traverse) >>= traverse pageTemplate) + +compileTemplate :: + FilePath + -> FilePath + -> Site (Either Text.Parsec.Error.ParseError Mu.Template) +compileTemplate templdir templ = + io $ do + putStrLn $ "TTT " ++ (templdir </> templ) + Mu.automaticCompile [templdir] templ -- | Use a template set from a given directory. sourceTemplates :: FilePath -> Site () @@ -113,13 +120,23 @@ indexFilename mount = do od <- use outputDir pure (od </> mount </> "index.html") +-- | Check that the page was not rendered before, and add it to the rendered set +checkRender :: FilePath -> Site () +checkRender fp = do + found <- S.member fp <$> use renders + if found + then error $ "colliding renders for page: " ++ fp + else renders %= S.insert fp + -- | Render a page using the current template. installPage :: FilePath -> PageInfo -> Site () -installPage mount pi = do +installPage mount pi {- find the correct template and metadata -} + = do tname <- pageTemplate pi templ <- use $ templates . to (M.! fromString tname) file <- indexFilename mount + checkRender file io $ do putStrLn $ ">>> " ++ file makeDirectories file |
