Created
June 29, 2013 11:54
-
-
Save funrep/5890869 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