Created
June 28, 2013 15:04
-
-
Save funrep/5885357 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
import Prelude hiding (writeFile) | |
import Web.Scotty (scotty, get, post, html, file, param, redirect) | |
import Text.Blaze.Html5 (Html) | |
import qualified Text.Blaze.Html5 as H | |
import qualified Text.Blaze.Html5.Attributes as A | |
import Text.Blaze.Html.Renderer.Text (renderHtml) | |
import Text.Pandoc (Pandoc, readMarkdown, writeHtml, def) | |
import Data.Text.Lazy.IO (writeFile) | |
import Control.Monad.Trans (liftIO) | |
main = scotty 3000 $ do | |
get "/" $ do | |
html $ renderHtml home | |
post "/publish" $ do | |
md <- param "markdown" | |
liftIO $ publish md | |
redirect "/archive" | |
get "/archive" $ file "/posts/test.html" | |
publish :: String -> IO () | |
publish md = let file = readMarkdown def md in | |
writeFile "posts/test.html" $ renderHtml $ writeHtml def file | |
home :: Html | |
home = H.docTypeHtml $ do | |
H.html $ do | |
H.body $ do | |
H.form H.! A.method "post" H.! A.action "/publish" $ do | |
H.input H.! A.type_ "text" H.! A.name "markdown" | |
H.input H.! A.type_ "submit" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ runhaskell test.hs
test.hs: /home/klrr/.cabal/lib/regex-pcre-builtin-0.94.4.6.8.31/ghc-7.4.1/HSregex-pcre-builtin-0.94.4.6.8.31.o: unknown symbol
utf8_table4' test.hs: test.hs: unable to load package
regex-pcre-builtin-0.94.4.6.8.31'