summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-12-26 12:31:36 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-12-26 12:31:36 +0100
commitab7c9bef64a433824ba57a04efac98f48884bcd9 (patch)
tree93979a13110a02f7344b8db418118ad6014279e6 /src
parent7f4b5e542c3f96bc05e329f846b80661b394be90 (diff)
downloadhakyll-ab7c9bef64a433824ba57a04efac98f48884bcd9.tar.gz
Add FileType module
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Web/FileType.hs55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/Hakyll/Web/FileType.hs b/src/Hakyll/Web/FileType.hs
new file mode 100644
index 0000000..8f0bdcc
--- /dev/null
+++ b/src/Hakyll/Web/FileType.hs
@@ -0,0 +1,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.Applicative ((<$>))
+
+import Hakyll.Core.Identifier
+import Hakyll.Core.Target
+
+-- | Datatype to represent the different file types Hakyll can deal with by
+-- default
+--
+data FileType
+ = Html
+ | LaTeX
+ | LiterateHaskell FileType
+ | Markdown
+ | ReStructuredText
+ | PlainText
+ | Css
+ | UnknownFileType
+ 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" = ReStructuredText
+ fileType' ".tex" = LaTeX
+ fileType' ".text" = PlainText
+ fileType' ".txt" = PlainText
+ fileType' ".css" = Css
+ fileType' _ = UnknownFileType
+
+-- | Get the file type for the current file
+--
+getFileType :: TargetM a FileType
+getFileType = fileType . toFilePath <$> getIdentifier