on master help sign in
Add FileType module
commitab7c9bef64a433824ba57a04efac98f48884bcd9 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSun 26 Dec 2010, 12:31 (16 years ago) parent7f4b5e5
1 file changed+55
src/Hakyll/Web/FileType.hs+55
src/Hakyll/Web/FileType.hsnew file+55
@@ -0,0 +1,55 @@
1+-- | A module dealing with common file extensions and associated file types.
2+--
3+module Hakyll.Web.FileType
4+ ( FileType (..)
5+ , fileType
6+ , getFileType
7+ ) where
8+
9+import System.FilePath (takeExtension)
10+import Control.Applicative ((<$>))
11+
12+import Hakyll.Core.Identifier
13+import Hakyll.Core.Target
14+
15+-- | Datatype to represent the different file types Hakyll can deal with by
16+-- default
17+--
18+data FileType
19+ = Html
20+ | LaTeX
21+ | LiterateHaskell FileType
22+ | Markdown
23+ | ReStructuredText
24+ | PlainText
25+ | Css
26+ | UnknownFileType
27+ deriving (Eq, Ord, Show, Read)
28+
29+-- | Get the file type for a certain file. The type is determined by extension.
30+--
31+fileType :: FilePath -> FileType
32+fileType = 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' _ = UnknownFileType
51+
52+-- | Get the file type for the current file
53+--
54+getFileType :: TargetM a FileType
55+getFileType = fileType . toFilePath <$> getIdentifier