packages feed

blatex (empty) → 0.1.0.0

raw patch · 4 files changed

+160/−0 lines, 4 filesdep +HaTeXdep +basedep +blaze-htmlsetup-changed

Dependencies added: HaTeX, base, blaze-html, directory, split, tagsoup, text

Files

+ LICENSE view
@@ -0,0 +1,21 @@+The MIT License (MIT)++Copyright (c) [year] [fullname]++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ Main.hs view
@@ -0,0 +1,98 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TypeSynonymInstances #-}+{-# LANGUAGE FlexibleInstances #-}++--Stuff for BlazeHTML+import Control.Monad (forM_)++import Text.Blaze.Html5 as H hiding (main, map)+import Text.Blaze.Html5.Attributes as A+import Text.Blaze.Html.Renderer.String++--Stuff for HaTeX+import Text.LaTeX+import Text.LaTeX.Base.Parser+import Text.LaTeX.Base.Syntax+import Data.Text (unlines, pack, unpack)+import qualified Data.Text.IO as T++--Stuff for TagSoup+import Text.HTML.TagSoup++--Other stuff I'm using+import System.Directory+import Data.List.Split+import Data.Maybe+import Control.Applicative++instance Show Html where+  show = renderHtml++postsToHtml :: [Post] -> Html+postsToHtml xs = do+  ul ! class_ "blog-posts" $+    forM_ xs h+  where+    h s = li ! class_ "blog-post" $+          a ! href (stringValue ("posts/"++fileName s++".pdf")) $+          toHtml (postTitle s)+          +data Post = Post {+  fileName :: String+  , postTitle :: String+  , postAuthor :: String+  , postDate :: String+  , syntaxTree :: LaTeX+    }++instance Show Post where+  show (Post fn t a d _) = t ++ " written by " ++ (a) ++ " on " ++ (d)++getPDF :: FilePath -> Maybe String+getPDF xs = if splitUp !! 1 == "pdf" then Just (splitUp !! 0) else Nothing+  where splitUp = splitOn "." xs++extractCommandArgs :: String -> LaTeX -> Maybe [TeXArg]+extractCommandArgs s (TeXSeq lt rt) = if isJust lst then lst else rst+  where lst = extractCommandArgs s lt+        rst = extractCommandArgs s rt+extractCommandArgs s (TeXComm name args)+  | name == s = Just args+  | otherwise = Nothing+extractCommandArgs _ _ = Nothing++extractFromArgs :: [TeXArg] -> Text+extractFromArgs ((FixArg (TeXRaw s)):xs) = s++getCommandValue :: String -> LaTeX -> Maybe Text+getCommandValue s = (fmap extractFromArgs . extractCommandArgs s) ++createPost :: String -> Either ParseError LaTeX -> Maybe Post+createPost _ (Left err) = Nothing+createPost s (Right t) = Post <$> pure s <*> title <*> author <*> date <*> pure t+  where +    date = fmap unpack (getCommandValue "date" t)+    author = fmap unpack (getCommandValue "author" t)+    title = fmap unpack (getCommandValue "title" t)++fileNameToPost :: String -> IO (Maybe Post) +fileNameToPost fn = do+  latexFile <- fmap (parseLaTeX . pack) (readFile ("posts/"++fn++".tex"))+  return (createPost "post1" latexFile)++injectPosts :: String -> Html -> String +injectPosts layout ul = renderTags (beginning ++ parseTags (show ul) ++ end)+  where+    splitFile = splitOn [(TagOpen "ul" [("id","blog-posts")]), (TagClose "ul")] (parseTags layout)+    beginning = splitFile !! 0+    end = splitFile !! 1++main = do+  fileNames <- fmap (catMaybes . map getPDF) (getDirectoryContents "posts")+  posts <- fmap (catMaybes) (mapM fileNameToPost fileNames)+  --print posts+  let generatedHtml = postsToHtml posts+  --print generatedHtml+  layoutFile <- readFile "index.html.bltx"+  let outputFile = layoutFile `injectPosts` generatedHtml+  writeFile "index.html" outputFile
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ blatex.cabal view
@@ -0,0 +1,39 @@+-- Initial blatex.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++name:                blatex+version:             0.1.0.0+synopsis:            Blog in LaTeX+description:         Static site generator that lets you write your blog in LaTeX and publish it to github pages.+description:         Markdown and HTML are the standard tools used to write your every day tech blog with. But they have pretty weak support for embedding mathematical formulas, and are not conducive to writing for an extended period of time. Plus, they aren't even Turing complete! So use BlaTeX to start blogging in LaTeX!+                     .+                     BlaTeX is basically a static site generator (like Jekyll) that lets you write your blog in LaTeX, specify a layout file for the homepage, and publish it to github pages.+                     .+                     To get started, check out <https://github.com/2016rshah/BlaTeX#how-to>+homepage:            https://github.com/2016rshah/BlaTeX+license:             MIT+license-file:        LICENSE+author:              Rushi Shah+maintainer:          2016rshah@gmail.com+-- copyright:           +category:            Web+build-type:          Simple+cabal-version:       >=1.10++executable blatex+  main-is:             Main.hs+  -- other-modules:       +  other-extensions:    OverloadedStrings+  build-depends:       HaTeX >=3.16 && <3.17+                     , base >=4.7 && <4.8+                     , blaze-html >= 0.8.1.1+                     , directory >=1.2 && <1.3+                     , split >=0.2 && <0.3+                     , tagsoup >= 0.13.3+                     , text >=1.1 && <1.2+  -- hs-source-dirs:      +  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/2016rshah/BlaTeX.git