From 1b5a0220f99742586e8c2c498f8ad878cddd30dd Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sun, 14 Nov 2010 22:48:48 +0100 Subject: Add default title --- src/Text/Hakyll/ContextManipulations.hs | 18 +++--------------- src/Text/Hakyll/Page.hs | 3 +++ 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/Text/Hakyll/ContextManipulations.hs b/src/Text/Hakyll/ContextManipulations.hs index f73e88c..1c26f72 100644 --- a/src/Text/Hakyll/ContextManipulations.hs +++ b/src/Text/Hakyll/ContextManipulations.hs @@ -2,7 +2,6 @@ -- manipulate @Context@s. module Text.Hakyll.ContextManipulations ( renderValue - , renderMissingValue , changeValue , changeUrl , copyValue @@ -14,7 +13,7 @@ module Text.Hakyll.ContextManipulations ) where import Control.Monad (liftM) -import Control.Arrow (arr, (>>>)) +import Control.Arrow (arr) import System.Locale (TimeLocale, defaultTimeLocale) import System.FilePath (takeFileName, addExtension, dropExtension) import Data.Time.Format (parseTime, formatTime) @@ -33,21 +32,10 @@ renderValue :: String -- ^ Key of which the value should be copied. -> String -- ^ Key the value should be copied to. -> (String -> String) -- ^ Function to apply on the value. -> HakyllAction Context Context -renderValue source destination f = - arr (Context . M.delete destination . unContext) - >>> renderMissingValue source destination f - --- | Render a value, but do not overwrite the destination value if it already --- exists. --- -renderMissingValue :: String -- ^ Source key - -> String -- ^ Destination key - -> (String -> String) -- ^ Function to apply on the value - -> HakyllAction Context Context -renderMissingValue source destination f = arr $ \(Context context) -> Context $ +renderValue source destination f = arr $ \(Context context) -> Context $ case M.lookup source context of Nothing -> context - (Just value) -> M.insertWith (flip const) destination (f value) context + (Just value) -> M.insert destination (f value) context -- | Change a value in a @Context@. -- diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs index 347e10a..f2b5fde 100644 --- a/src/Text/Hakyll/Page.hs +++ b/src/Text/Hakyll/Page.hs @@ -88,8 +88,11 @@ readPage path = do let sections = evalState (splitAtDelimiters $ lines contents) Nothing sectionsData = concat $ zipWith ($) sectionFunctions sections + -- Note that url, path etc. are listed first, which means can be overwritten + -- by section data return $ PageSection ("url", url, False) : PageSection ("path", path, False) + : PageSection ("title", takeBaseName path, False) : (category ++ sectionsData) where category = let dirs = splitDirectories $ takeDirectory path -- cgit v1.2.3