heckle 2.0.0.3 → 2.0.0.4
raw patch · 4 files changed
+49/−22 lines, 4 files
Files
- Files.hs +22/−1
- Heckle.hs +11/−16
- Main.hs +15/−4
- heckle.cabal +1/−1
Files.hs view
@@ -6,7 +6,7 @@ [ "\\documentclass{article}" , "\\author{Rushi Shah}" , "\\date{1 January 2015}"- , "\\title{Example Post}"+ , "\\title{Example LaTeX Post}" , "\\begin{document}" , "\\maketitle" , "This is an example LaTeX/PDF post."@@ -25,6 +25,27 @@ exampleIndexFile :: String exampleIndexFile = unlines [ "<ul id='blog-posts'></ul>"]++exampleResFile :: String+exampleResFile = unlines+ ["<ul id=\"blog-posts\">"+ ," <li class=\"blog-post\">"+ ," <a class=\"post-link\" href=\"posts/example-markdown.html\">"+ ," Example MD Post"+ ," </a>"+ ," <div class=\"post-date\">"+ ," 1 January 2016"+ ," </div>"+ ," </li>"+ ," <li class=\"blog-post\">"+ ," <a class=\"post-link\" href=\"posts/example-latex.pdf\">"+ ," Example Post"+ ," </a>"+ ," <div class=\"post-date\">"+ ," 1 January 2015"+ ," </div>"+ ," </li>"+ ,"</ul>"] exampleTemplateFile :: String exampleTemplateFile = unlines
Heckle.hs view
@@ -16,15 +16,15 @@ import Data.Dates --Pandoc-import Text.Pandoc.Options-import Text.Pandoc.Readers.Markdown-import Text.Pandoc.Readers.LaTeX+import Text.Pandoc.Options (def)+import Text.Pandoc.Readers.Markdown (readMarkdown)+import Text.Pandoc.Readers.LaTeX (readLaTeX) import Text.Pandoc.Definition-import Text.Pandoc.Writers.HTML-import Text.Pandoc.Shared+import Text.Pandoc.Writers.HTML (writeHtmlString)+import Text.Pandoc.Shared (stringify) --Other stuff I'm using-import Data.List.Split+import Data.List.Split (splitOn) import Data.Either import Control.Applicative import Control.Monad@@ -33,8 +33,6 @@ instance Show Html where show = renderHtml ---Post {fileName = "example-post", postTitle = "Example Post", postAuthor = "Rushi Shah", postDate = 1 January 2015, 0:0:0, syntaxTree = TeXSeq (TeXComm "documentclass" [FixArg (TeXRaw "article")]) (TeXSeq (TeXRaw "\n") (TeXSeq (TeXComm "author" [FixArg (TeXRaw "Rushi Shah")]) (TeXSeq (TeXRaw "\n") (TeXSeq (TeXComm "date" [FixArg (TeXRaw "1 January 2015")]) (TeXSeq (TeXRaw "\n") (TeXSeq (TeXComm "title" [FixArg (TeXRaw "Example Post")]) (TeXSeq (TeXRaw "\n") (TeXSeq (TeXEnv "document" [] (TeXSeq (TeXRaw "\n") (TeXSeq (TeXCommS "maketitle") (TeXRaw "\nThis is an example LaTeX/PDF post.\n")))) (TeXRaw "\n")))))))))}- showMonth :: Int -> String showMonth i = months !! (i-1) where months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]@@ -96,7 +94,7 @@ --Creates a post given a constructor for a post --The long function in the type signature is just---A constructor for a post (Either `LaTeX` or `MD`)+--A constructor for a post (either `LaTeX` or `MD`) createPost :: Show a => (String -> String -> DateTime -> Pandoc -> Post) -> String -> Either a Pandoc -> Either String Post@@ -110,13 +108,10 @@ fileToPost :: String -> IO (Either String Post) fileToPost fn = case splitOn "." fn of- [fn, "pdf"] -> do- -- latexFile <- fmap (parseLaTeXWith (ParserConf ["verbatim", "minted"]) . pack) (readFile ("posts/"++fn++".tex"))- latexFile <- fmap (readLaTeX def) (readFile ("posts/" ++ fn ++ ".tex"))- return (createPost LaTeX fn latexFile)- [fn, "md"] -> do- native <- fmap (readMarkdown def) (readFile ("posts/" ++ fn ++".md"))- return (createPost MD fn native)+ [fn, "pdf"] -> + return . createPost LaTeX fn . readLaTeX def =<< readFile ("posts/" ++ fn ++ ".tex")+ [fn, "md"] -> + return . createPost MD fn . readMarkdown def =<< readFile ("posts/" ++ fn ++ ".md") _ -> return (Left "Not a LaTeX or MD file") injectIndex :: String -> Html -> Either String String
Main.hs view
@@ -3,6 +3,7 @@ import Data.List import System.Environment (getArgs) import System.Process (readProcess)+import Control.Exception import Files import Heckle @@ -37,14 +38,24 @@ --Create the basic layout file writeFile "index.html.hkl" exampleIndexFile --Change to layout when testing, index when deploying" writeFile "template.html.hkl" exampleTemplateFile+ writeFile "index.html" exampleResFile --Create directory for posts and basic post createDirectoryIfMissing True "posts" setCurrentDirectory "posts"- writeFile "example-latex.tex" exampleTeXPost writeFile "example-markdown.md" exampleMDPost+ --Compile the LaTeX file into a PDF --Could do this for every .tex file if wanted to- readProcess "pdflatex" ["example-latex.tex"] ""- print "Success initializing!"+ writeFile "example-latex.tex" exampleTeXPost+ x <- try (readProcess "pdflatex" ["example-latex.tex"] "")+ case x of+ Left e -> do+ let err = show (e :: IOException)+ putStrLn "Warning: LaTeX installation not found, removing LaTeX post"+ removeFile "example-latex.tex"+ return "LaTeX not found"+ Right r -> return "Success"++ putStrLn "Success initializing!" - _ -> print "That's not a valid command"+ _ -> putStrLn "That's not a valid command"
heckle.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: heckle-version: 2.0.0.3+version: 2.0.0.4 synopsis: Jekyll in Haskell (feat. LaTeX) description: A static site generator that supports LaTeX/PDF and Markdown/HTML posts. Care has been taken to make it configurable, easy to use, and unopinionated. homepage: https://github.com/2016rshah/heckle