summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/FileType.hs
blob: d5a9c56bf6470aa3380ea8fec1d9432138af3fba (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-- | A module dealing with common file extensions and associated file types.
--
module Hakyll.Web.FileType
    ( FileType (..)
    , fileType
    , getFileType
    ) where

import System.FilePath (takeExtension)
import Control.Arrow ((>>>), arr)

import Hakyll.Core.Identifier
import Hakyll.Core.Compiler

-- | Datatype to represent the different file types Hakyll can deal with by
-- default
--
data FileType
    = Html
    | LaTeX
    | LiterateHaskell FileType
    | Markdown
    | Rst
    | PlainText
    | Css
    | Binary
    deriving (Eq, Ord, Show, Read)

-- | Get the file type for a certain file. The type is determined by extension.
--
fileType :: FilePath -> FileType
fileType = fileType' . takeExtension
  where
    fileType' ".htm"      = Html
    fileType' ".html"     = Html
    fileType' ".lhs"      = LiterateHaskell Markdown
    fileType' ".markdown" = Markdown
    fileType' ".md"       = Markdown
    fileType' ".mdn"      = Markdown
    fileType' ".mdown"    = Markdown
    fileType' ".mdwn"     = Markdown
    fileType' ".mkd"      = Markdown
    fileType' ".mkdwn"    = Markdown
    fileType' ".page"     = Markdown
    fileType' ".rst"      = Rst
    fileType' ".tex"      = LaTeX
    fileType' ".text"     = PlainText
    fileType' ".txt"      = PlainText
    fileType' ".css"      = Css
    fileType' _           = Binary  -- Treat unknown files as binary

-- | Get the file type for the current file
--
getFileType :: Compiler () FileType
getFileType = getIdentifier >>> arr (fileType . toFilePath)