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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
--------------------------------------------------------------------------------
-- | A module dealing with pandoc file extensions and associated file types
module Hakyll.Web.Pandoc.FileType
( FileType (..)
, fileType
, itemFileType
) where
--------------------------------------------------------------------------------
import System.FilePath (splitExtension)
--------------------------------------------------------------------------------
import Hakyll.Core.Identifier
import Hakyll.Core.Item
--------------------------------------------------------------------------------
-- | Datatype to represent the different file types Hakyll can deal with by
-- default
data FileType
= Binary
| Css
| DocBook
| Html
| Jupyter
| LaTeX
| LiterateHaskell FileType
| Markdown
| MediaWiki
| OrgMode
| PlainText
| Rst
| Textile
deriving (Eq, Ord, Show, Read)
--------------------------------------------------------------------------------
-- | Get the file type for a certain file. The type is determined by extension.
fileType :: FilePath -> FileType
fileType = uncurry fileType' . splitExtension
where
fileType' _ ".css" = Css
fileType' _ ".dbk" = DocBook
fileType' _ ".ipynb" = Jupyter
fileType' _ ".htm" = Html
fileType' _ ".html" = Html
fileType' f ".lhs" = LiterateHaskell $ case fileType f of
-- If no extension is given, default to Markdown + LiterateHaskell
Binary -> Markdown
-- Otherwise, LaTeX + LiterateHaskell or whatever the user specified
x -> x
fileType' _ ".markdown" = Markdown
fileType' _ ".mediawiki" = MediaWiki
fileType' _ ".md" = Markdown
fileType' _ ".mdn" = Markdown
fileType' _ ".mdown" = Markdown
fileType' _ ".mdwn" = Markdown
fileType' _ ".mkd" = Markdown
fileType' _ ".mkdwn" = Markdown
fileType' _ ".org" = OrgMode
fileType' _ ".page" = Markdown
fileType' _ ".rst" = Rst
fileType' _ ".tex" = LaTeX
fileType' _ ".text" = PlainText
fileType' _ ".textile" = Textile
fileType' _ ".txt" = PlainText
fileType' _ ".wiki" = MediaWiki
fileType' _ _ = Binary -- Treat unknown files as binary
--------------------------------------------------------------------------------
-- | Get the file type for the current file
itemFileType :: Item a -> FileType
itemFileType = fileType . toFilePath . itemIdentifier
|