summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Servall/Types.hs21
-rw-r--r--src/Servall/WikiParser.hs13
2 files changed, 26 insertions, 8 deletions
diff --git a/src/Servall/Types.hs b/src/Servall/Types.hs
index 69c2045..794482c 100644
--- a/src/Servall/Types.hs
+++ b/src/Servall/Types.hs
@@ -1,8 +1,6 @@
+{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
-module Servall.Types
- ( WikiTemplate(..)
- , Video(..)
- ) where
+module Servall.Types where
import Data.Aeson ( (.:)
, (.=)
@@ -13,6 +11,7 @@ import Data.Aeson ( (.:)
)
import qualified Data.HashMap.Lazy as HM
import Data.Text ( Text )
+import GHC.Generics ( Generic )
data WikiTemplate = WikiTemplate
{ wtName :: Text
@@ -48,3 +47,17 @@ instance ToJSON Video where
, "description" .= desc
, "duration" .= duration
]
+
+
+data WikiSummary = WikiSummary
+ { wsTitle :: Text
+ , wsWikbase :: Text
+ , wsPageId :: Int
+ }
+ deriving (Show, Eq, Generic)
+
+instance FromJSON WikiSummary where
+ parseJSON (Object o) =
+ WikiSummary <$> o .: "title" <*> o .: "wikibase_item" <*> o .: "pageid"
+
+instance ToJSON WikiSummary
diff --git a/src/Servall/WikiParser.hs b/src/Servall/WikiParser.hs
index 2680fad..e284a3b 100644
--- a/src/Servall/WikiParser.hs
+++ b/src/Servall/WikiParser.hs
@@ -32,8 +32,9 @@ import qualified Data.Text as T
import Data.Text ( Text )
import GHC.Generics ( Generic )
import Servall.Types
-import Text.Pandoc.Definition ( Inline(..)
- , Pandoc
+import Text.Pandoc.Definition ( Block(..)
+ , Inline(..)
+ , Pandoc(..)
)
import Text.Pandoc.Generic ( topDown )
@@ -109,8 +110,12 @@ wikilinkP = do
content <- T.pack <$> manyTill anyChar (string "]]")
return $ beg <> content <> "]]"
-wikiFilter :: Pandoc -> Pandoc
-wikiFilter = topDown fixUrl
+wikiFilter :: Text -> Pandoc -> Pandoc
+wikiFilter title = insertHeader title . topDown fixUrl
+
+insertHeader :: Text -> Pandoc -> Pandoc
+insertHeader title (Pandoc m bs) =
+ Pandoc m (Header 1 ("", [], []) [Str title] : bs)
fixUrl :: Inline -> Inline
fixUrl (Link attr label (url, "wikilink")) =