Created
June 28, 2013 14:45
-
-
Save funrep/5885217 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 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 (readMarkdown, writeHtml, def) | |
import Data.Text (Text, unpack) | |
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 :: Text -> IO () | |
publish md = do | |
file <- readMarkdown def $ unpack md | |
writeFile "posts/test.html" $ 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
test.hs:15:11:
No instance for (scotty-0.4.6:Web.Scotty.Action.Parsable Text)
arising from a use of
param' Possible fix: add an instance declaration for (scotty-0.4.6:Web.Scotty.Action.Parsable Text) In a stmt of a 'do' block: md <- param "markdown" In the second argument of
($)', namely`do { md <- param "markdown";
liftIO $ publish md;
redirect "/archive" }'
In a stmt of a 'do' block:
post "/publish"
$ do { md <- param "markdown";
liftIO $ publish md;
redirect "/archive" }
test.hs:22:11:
Couldn't match expected type
IO t0' with actual type
Text.Pandoc.Definition.Pandoc'In a stmt of a 'do' block: file <- readMarkdown def $ unpack md
In the expression:
do { file <- readMarkdown def $ unpack md;
writeFile "posts/test.html" $ writeHtml def file }
In an equation for `publish':
publish md
= do { file <- readMarkdown def $ unpack md;
writeFile "posts/test.html" $ writeHtml def file }