summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-08-02 12:59:22 +0200
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-08-02 12:59:22 +0200
commit2066be06213cd70fdeae42a6194bc645a15d9835 (patch)
treebfec1f0e558a68078f137c0cc6ed4d52fe9bc197 /src/Text/Hakyll
parent1af0421efe7983eb5634440ec162da48518b0b78 (diff)
downloadhakyll-2066be06213cd70fdeae42a6194bc645a15d9835.tar.gz
Add inHakyllDirectory function and test cases
Diffstat (limited to 'src/Text/Hakyll')
-rw-r--r--src/Text/Hakyll/File.hs22
-rw-r--r--src/Text/Hakyll/HakyllMonad.hs2
2 files changed, 24 insertions, 0 deletions
diff --git a/src/Text/Hakyll/File.hs b/src/Text/Hakyll/File.hs
index 84d8183..96d05be 100644
--- a/src/Text/Hakyll/File.hs
+++ b/src/Text/Hakyll/File.hs
@@ -5,6 +5,7 @@ module Text.Hakyll.File
, toCache
, toUrl
, toRoot
+ , inHakyllDirectory
, removeSpaces
, makeDirectories
, getRecursiveContents
@@ -16,6 +17,7 @@ module Text.Hakyll.File
) where
import System.Directory
+import Control.Applicative ((<$>))
import System.FilePath
import System.Time (ClockTime)
import Control.Monad
@@ -85,6 +87,26 @@ toRoot = emptyException . joinPath . map parent . splitPath
emptyException [] = "."
emptyException x = x
+-- | Check if a file is in a Hakyll directory. With a Hakyll directory, we mean
+-- a directory that should be "ignored" such as the @_site@ or @_cache@
+-- directory.
+--
+-- Example:
+--
+-- > inHakyllDirectory "_cache/pages/index.html"
+--
+-- Result:
+--
+-- > True
+--
+inHakyllDirectory :: FilePath -> Hakyll Bool
+inHakyllDirectory path =
+ or <$> mapM (liftM inDirectory . askHakyll) [siteDirectory, cacheDirectory]
+ where
+ inDirectory dir = case splitDirectories path of
+ [] -> False
+ (x : _) -> x == dir
+
-- | Swaps spaces for '-'.
removeSpaces :: FilePath -> FilePath
removeSpaces = map swap
diff --git a/src/Text/Hakyll/HakyllMonad.hs b/src/Text/Hakyll/HakyllMonad.hs
index f17ae52..3ec78c4 100644
--- a/src/Text/Hakyll/HakyllMonad.hs
+++ b/src/Text/Hakyll/HakyllMonad.hs
@@ -59,6 +59,8 @@ data HakyllConfiguration = HakyllConfiguration
askHakyll :: (HakyllConfiguration -> a) -> Hakyll a
askHakyll = flip liftM ask
+-- | Obtain the globally available, additional context.
+--
getAdditionalContext :: HakyllConfiguration -> Context
getAdditionalContext configuration =
let (Context c) = additionalContext configuration