summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Resource/Provider/File.hs
blob: 3a67817f8736613587c56d2aeeb9815d5121a398 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- | A concrete 'ResourceProvider' that gets it's resources from the filesystem
--
{-# LANGUAGE CPP #-}
module Hakyll.Core.Resource.Provider.File
    ( fileResourceProvider
    ) where

import Control.Applicative ((<$>))

import Data.Time (readTime)
import System.Directory (getModificationTime)
import System.Locale (defaultTimeLocale)
import System.Time (formatCalendarTime, toCalendarTime)
import qualified Data.ByteString.Lazy as LB

import Hakyll.Core.Resource
import Hakyll.Core.Resource.Provider
import Hakyll.Core.Util.File
import Hakyll.Core.Configuration

-- | Create a filesystem-based 'ResourceProvider'
--
fileResourceProvider :: HakyllConfiguration -> IO ResourceProvider
fileResourceProvider configuration = do
    -- Retrieve a list of paths
    list <- map resource . filter (not . shouldIgnoreFile configuration) <$>
        getRecursiveContents False "."
    makeResourceProvider list (readFile . unResource)
                              (LB.readFile . unResource)
                              (mtime . unResource)
  where
    mtime r = do
#if MIN_VERSION_directory(1,2,0)
        getModificationTime r
#else
        ct <- toCalendarTime =<< getModificationTime r
        let str = formatCalendarTime defaultTimeLocale "%s" ct
        return $ readTime defaultTimeLocale "%s" str
#endif