diff options
| author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-03-08 18:44:12 +0100 |
|---|---|---|
| committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-03-08 18:44:12 +0100 |
| commit | d023eb5bf66bd45c1460c9dd331af409d8294763 (patch) | |
| tree | 0c494592ec5d53ef20aab29f19e9a2b877dddd89 /src/Text/Hakyll/Internal | |
| parent | 94400da4a09501051a7c4e6c377e55995c708ebd (diff) | |
| download | hakyll-d023eb5bf66bd45c1460c9dd331af409d8294763.tar.gz | |
Added Text.Hakyll.Internal.FileType module.
Diffstat (limited to 'src/Text/Hakyll/Internal')
| -rw-r--r-- | src/Text/Hakyll/Internal/FileType.hs | 45 | ||||
| -rw-r--r-- | src/Text/Hakyll/Internal/Page.hs | 24 |
2 files changed, 58 insertions, 11 deletions
diff --git a/src/Text/Hakyll/Internal/FileType.hs b/src/Text/Hakyll/Internal/FileType.hs new file mode 100644 index 0000000..e3a73cd --- /dev/null +++ b/src/Text/Hakyll/Internal/FileType.hs @@ -0,0 +1,45 @@ +-- | A module dealing with file extensions and associated file types. +module Text.Hakyll.Internal.FileType + ( FileType (..) + , getFileType + , isRenderable + , isRenderableFile + ) where + +import System.FilePath (takeExtension) + +-- | Datatype to represent the different file types Hakyll can deal with. +data FileType = Html + | LaTeX + | LiterateHaskellMarkdown + | Markdown + | ReStructuredText + | UnknownFileType + deriving (Eq, Ord, Show, Read) + +-- | Get the file type for a certain file. The type is determined by extension. +getFileType :: FilePath -> FileType +getFileType = getFileType' . takeExtension + where + getFileType' ".htm" = Html + getFileType' ".html" = Html + getFileType' ".lhs" = LiterateHaskellMarkdown + getFileType' ".markdown" = Markdown + getFileType' ".md" = Markdown + getFileType' ".mdn" = Markdown + getFileType' ".mdown" = Markdown + getFileType' ".mdwn" = Markdown + getFileType' ".mkd" = Markdown + getFileType' ".mkdwn" = Markdown + getFileType' ".rst" = ReStructuredText + getFileType' ".tex" = LaTeX + getFileType' _ = UnknownFileType + +-- | Check if a certain @FileType@ is renderable. +isRenderable :: FileType -> Bool +isRenderable UnknownFileType = False +isRenderable _ = True + +-- | Check if a certain file is renderable. +isRenderableFile :: FilePath -> Bool +isRenderableFile = isRenderable . getFileType diff --git a/src/Text/Hakyll/Internal/Page.hs b/src/Text/Hakyll/Internal/Page.hs index 657ea77..5168161 100644 --- a/src/Text/Hakyll/Internal/Page.hs +++ b/src/Text/Hakyll/Internal/Page.hs @@ -17,6 +17,7 @@ import Text.Hakyll.Hakyll import Text.Hakyll.Regex (substituteRegex, matchesRegex) import Text.Hakyll.Util (trim) import Text.Hakyll.Internal.Cache +import Text.Hakyll.Internal.FileType -- | The default reader options for pandoc parsing. readerOptions :: ParserState @@ -35,18 +36,19 @@ writerOptions = defaultWriterOptions } -- | Get a render function for a given extension. -getRenderFunction :: String -> (String -> String) -getRenderFunction ".html" = id -getRenderFunction ".htm" = id -getRenderFunction ext = writeHtmlString writerOptions - . readFunction ext (readOptions ext) +getRenderFunction :: FileType -> (String -> String) +getRenderFunction Html = id +getRenderFunction fileType = writeHtmlString writerOptions + . readFunction fileType (readOptions fileType) where - readFunction ".rst" = readRST - readFunction ".tex" = readLaTeX - readFunction _ = readMarkdown + readFunction ReStructuredText = readRST + readFunction LaTeX = readLaTeX + readFunction Markdown = readMarkdown + readFunction t = error $ "Cannot render file " ++ show t - readOptions ".lhs" = readerOptions { stateLiterateHaskell = True } - readOptions _ = readerOptions + readOptions LiterateHaskellMarkdown = + readerOptions { stateLiterateHaskell = True } + readOptions _ = readerOptions -- | Split a page into sections. splitAtDelimiters :: [String] -> [[String]] @@ -89,7 +91,7 @@ readSection renderFunction isFirst ls -- has a @.markdown@ extension, it will be rendered using pandoc. readPageFromFile :: FilePath -> Hakyll Context readPageFromFile path = do - let renderFunction = getRenderFunction $ takeExtension path + let renderFunction = getRenderFunction $ getFileType path sectionFunctions = map (readSection renderFunction) (True : repeat False) |
