summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-04 15:15:32 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-04 15:15:32 +0100
commitd3ce014d2643fc62aa5af5b54b298fb083bf25b0 (patch)
tree8ac19a5886c7025700b79ec10c7bb8e6055f8eb7
parent9b3babe142e36e96d2ffcbf2ec5b22346c54c3d9 (diff)
downloadhakyll-d3ce014d2643fc62aa5af5b54b298fb083bf25b0.tar.gz
Proper string trimming.
-rw-r--r--src/Text/Hakyll/Page.hs6
-rw-r--r--src/Text/Hakyll/Util.hs9
2 files changed, 11 insertions, 4 deletions
diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs
index 902d36b..3888b1d 100644
--- a/src/Text/Hakyll/Page.hs
+++ b/src/Text/Hakyll/Page.hs
@@ -18,6 +18,7 @@ import Data.Maybe
import System.FilePath
import System.IO
+import Text.Hakyll.Util
import Text.Pandoc
-- | A Page is basically key-value mapping. Certain keys have special
@@ -27,7 +28,6 @@ type Page = M.Map String PageValue
-- | We use a ByteString for obvious reasons.
type PageValue = B.ByteString
-
-- | Add a key-value mapping to the Page.
addContext :: String -> String -> Page -> Page
addContext key value = M.insert key (B.pack value)
@@ -61,8 +61,8 @@ readMetaData handle = do
line <- hGetLine handle
if isDelimiter line then return []
else do others <- readMetaData handle
- return $ (trim . break (== ':')) line : others
- where trim (key, value) = (key, dropWhile (`elem` ": ") value)
+ return $ (trimPair . break (== ':')) line : others
+ where trimPair (key, value) = (trim key, trim $ tail value)
isDelimiter :: String -> Bool
isDelimiter = L.isPrefixOf "---"
diff --git a/src/Text/Hakyll/Util.hs b/src/Text/Hakyll/Util.hs
index dd84d73..50a36e6 100644
--- a/src/Text/Hakyll/Util.hs
+++ b/src/Text/Hakyll/Util.hs
@@ -1,11 +1,13 @@
module Text.Hakyll.Util
( makeDirectories,
- getRecursiveContents
+ getRecursiveContents,
+ trim
) where
import System.Directory
import System.FilePath
import Control.Monad
+import Data.Char
-- | Given a path to a file, try to make the path writable by making
-- all directories on the path.
@@ -27,3 +29,8 @@ getRecursiveContents topdir = do
else return [path]
return (concat paths)
where isProper = not . (== '.') . head
+
+-- | Trim a string (drop spaces and tabs at both sides).
+trim :: String -> String
+trim = reverse . trim' . reverse . trim'
+ where trim' = dropWhile isSpace