summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2015-03-29 01:36:42 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2015-03-29 01:36:42 +0100
commit29907c6c870933ec1031fa6499ea9994c96f7aa6 (patch)
treefb4cb96f30e2138b9d6c0e7ec7b01950d6fe803f
parent316dfb918c586fa1743b9389729177375e883d9a (diff)
downloaddirty-haskell.org-29907c6c870933ec1031fa6499ea9994c96f7aa6.tar
dirty-haskell.org-29907c6c870933ec1031fa6499ea9994c96f7aa6.tar.gz
dirty-haskell.org-29907c6c870933ec1031fa6499ea9994c96f7aa6.tar.bz2
dirty-haskell.org-29907c6c870933ec1031fa6499ea9994c96f7aa6.tar.xz
dirty-haskell.org-29907c6c870933ec1031fa6499ea9994c96f7aa6.zip
extract-title.hs now only writes title to stdout
-rwxr-xr-xbuild/extract-title.hs25
1 files changed, 17 insertions, 8 deletions
diff --git a/build/extract-title.hs b/build/extract-title.hs
index a84442e..4582657 100755
--- a/build/extract-title.hs
+++ b/build/extract-title.hs
@@ -1,16 +1,25 @@
1#!/usr/bin/env runhaskell 1#!/usr/bin/env runhaskell
2 2
3-- import Text.Pandoc.Pretty
4-- import Text.Pandoc.JSON
3import Text.Pandoc.Pretty 5import Text.Pandoc.Pretty
4import Text.Pandoc.JSON 6import Text.Pandoc.JSON
7import qualified Text.Pandoc.Walk as W
5import System.IO 8import System.IO
9import qualified Data.Aeson as A
10import qualified Data.ByteString.Lazy as BL
6 11
7extract_title :: Pandoc -> IO Pandoc 12extract_title :: Pandoc -> String
8extract_title d@(Pandoc m _) = do hPutStrLn stderr $ (++) "title: " $ render Nothing $ cat $ map pretty (docTitle m) 13extract_title d@(Pandoc m _) = do
9 return d 14 title <- render Nothing $ cat $ map pretty (docTitle m)
10 where pretty :: Inline -> Doc 15 return title
11 pretty (Str s) = text s 16 where pretty :: Inline -> Doc
12 pretty Space = space 17 pretty (Str s) = text s
13 pretty _ = empty 18 pretty Space = space
19 pretty _ = empty
14 20
15main :: IO () 21main :: IO ()
16main = toJSONFilter extract_title 22main = do
23 input <- BL.getContents
24 let title = (W.query extract_title :: Pandoc -> String) . either error id . A.eitherDecode' $ input
25 putStrLn title