diff options
author | Yuchen Pei <hi@ypei.me> | 2022-09-15 18:21:04 +1000 |
---|---|---|
committer | Yuchen Pei <hi@ypei.me> | 2022-09-15 18:21:04 +1000 |
commit | d4f3629e4eb1a5a8d0dbb82ed4e8087faf6f2a58 (patch) | |
tree | b4eb2bc7d8bd82354f2680d28d3e4a43b2979f24 | |
parent | 265951e087809e8a45802bc00349d198f3515b19 (diff) |
[server] reuse infobox function and separate out main
-rw-r--r-- | app/Main.hs | 5 | ||||
-rw-r--r-- | src/Servall/WikiParser.hs | 20 |
2 files changed, 17 insertions, 8 deletions
diff --git a/app/Main.hs b/app/Main.hs index 74a03eb..ea64179 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -199,10 +199,13 @@ app = serve api server api :: Proxy API api = Proxy +servall :: ServerConfig -> IO () +servall config = run (configPort config) app + main :: IO () main = do config <- execParser opts - run (configPort config) app + servall config where opts = info (optParser <**> helper) diff --git a/src/Servall/WikiParser.hs b/src/Servall/WikiParser.hs index b5188a4..7053197 100644 --- a/src/Servall/WikiParser.hs +++ b/src/Servall/WikiParser.hs @@ -206,21 +206,27 @@ fixHeaderTemplates (Pandoc m blocks) = Pandoc m (go [] blocks) where go acc (Header level (x, y, attr) content : bs) = let (raws, rest) = span isTemplateBlock bs in go - (acc ++ [Header level (x, y, attr ++ concatMap infobox' raws) content] + ( acc + ++ [ Header + level + ( x + , y + , attr ++ infobox (T.concat (map templateFromRawBlock raws)) + ) + content + ] ) rest go acc (b : bs) = go (acc ++ [b]) bs - infobox' :: Block -> [(Text, Text)] - infobox' (RawBlock (Format "mediawiki") temp) = - fromRight [] - $ (\wt -> if isInfobox wt then filterNameValues (wtArgs wt) else []) - <$> parseOnly templateP temp - infobox' _ = [] isTemplateBlock :: Block -> Bool isTemplateBlock (RawBlock (Format "mediawiki") temp) = True isTemplateBlock _ = False +templateFromRawBlock :: Block -> Text +templateFromRawBlock (RawBlock (Format "mediawiki") temp) = temp +templateFromRawBlock _ = "" + fixInline :: Inline -> Inline fixInline (Link attr label (url, "wikilink")) = Link attr label ("wiki:" <> url, "") |