summaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-23 17:12:49 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-23 17:12:49 +0100
commit5f8ea066d6626d9c1a1caa028f62865d74ce0d8a (patch)
treeb0bd350feadaa38cdf4234371f9e667c0d6f2545 /src/Text
parente8e0f217377a51ae18f1558389890ae53d4d437f (diff)
downloadhakyll-5f8ea066d6626d9c1a1caa028f62865d74ce0d8a.tar.gz
Added changeExtension ContextManipulation.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Hakyll/Context.hs16
1 files changed, 15 insertions, 1 deletions
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