From 5f8ea066d6626d9c1a1caa028f62865d74ce0d8a Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 23 Jan 2010 17:12:49 +0100 Subject: Added changeExtension ContextManipulation. --- src/Text/Hakyll/Context.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Text/Hakyll/Context.hs b/src/Text/Hakyll/Context.hs index 56adc49..d4d3436 100644 --- a/src/Text/Hakyll/Context.hs +++ b/src/Text/Hakyll/Context.hs @@ -4,12 +4,13 @@ module Text.Hakyll.Context , ContextManipulation , renderValue , renderDate + , changeExtension ) where import qualified Data.Map as M import Data.Map (Map) import System.Locale (defaultTimeLocale) -import System.FilePath (takeFileName) +import System.FilePath (takeFileName, addExtension, dropExtension) import Data.Time.Format (parseTime, formatTime) import Data.Time.Clock (UTCTime) import Data.Maybe (fromMaybe) @@ -47,3 +48,16 @@ renderDate key format defaultValue context = M.insert key value context "%Y-%m-%d" dateString :: Maybe UTCTime return $ formatTime defaultTimeLocale format time + +-- | Change the extension of a file. This is only needed when you want to +-- render, for example, mardown to @.php@ files instead of @.html@ files. +-- +-- > renderChainWith (changeExtension "php") +-- > ["templates/default.html"] +-- > (createPagePath "test.markdown") +-- +-- Will render to @test.php@ instead of @test.html@. +changeExtension :: String -> ContextManipulation +changeExtension extension = renderValue "url" "url" changeExtension' + where + changeExtension' = flip addExtension extension . dropExtension -- cgit v1.2.3