on 9939708 help sign in
hakyll/src/Hakyll/Web/FileType.hs
55 lines 1.5 kB history raw
1-- | A module dealing with common file extensions and associated file types.
2--
3module Hakyll.Web.FileType
4 ( FileType (..)
5 , fileType
6 , getFileType
7 ) where
9import System.FilePath (takeExtension)
10import Control.Applicative ((<$>))
12import Hakyll.Core.Identifier
13import Hakyll.Core.Target
15-- | Datatype to represent the different file types Hakyll can deal with by
16-- default
17--
18data FileType
19 = Html
20 | LaTeX
21 | LiterateHaskell FileType
22 | Markdown
23 | ReStructuredText
24 | PlainText
25 | Css
26 | Binary
27 deriving (Eq, Ord, Show, Read)
29-- | Get the file type for a certain file. The type is determined by extension.
30--
31fileType :: FilePath -> FileType
32fileType = fileType' . takeExtension
33 where
34 fileType' ".htm" = Html
35 fileType' ".html" = Html
36 fileType' ".lhs" = LiterateHaskell Markdown
37 fileType' ".markdown" = Markdown
38 fileType' ".md" = Markdown
39 fileType' ".mdn" = Markdown
40 fileType' ".mdown" = Markdown
41 fileType' ".mdwn" = Markdown
42 fileType' ".mkd" = Markdown
43 fileType' ".mkdwn" = Markdown
44 fileType' ".page" = Markdown
45 fileType' ".rst" = ReStructuredText
46 fileType' ".tex" = LaTeX
47 fileType' ".text" = PlainText
48 fileType' ".txt" = PlainText
49 fileType' ".css" = Css
50 fileType' _ = Binary -- Treat unknown files as binary
52-- | Get the file type for the current file
53--
54getFileType :: TargetM a FileType
55getFileType = fileType . toFilePath <$> getIdentifier