blob: dde902827ef7e5e7cd7841b6381b1010435ba77f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
{-# LANGUAGE OverloadedStrings
, ImportQualifiedPost
#-}
module Vimwiki.Man where
import Data.Map (Map)
import Data.Map qualified as M
import Data.Maybe (fromMaybe)
import Data.String (IsString)
import Data.Text hiding (tail)
import Network.URI
import Text.Pandoc (Inline (Str))
import Util (nullToMaybe)
manRewriter :: (Text -> Maybe Text -> Maybe Text -> Text) -> [Inline] -> URI -> ([Inline], Text)
manRewriter manImpl _ uri
= ([Str $ path <> "(" <> (fromMaybe "?" section') <> ")"]
, manImpl path section' language')
where path :: Text
path = pack $ uriPath uri
section' = pack . tail <$> nullToMaybe (uriFragment uri)
language' = pack . tail <$> nullToMaybe (uriQuery uri)
archMan :: (Semigroup a, IsString a) => a -> Maybe a -> Maybe a -> a
archMan page section' language'
= "https://man.archlinux.org/man/" <> page <> f section' <> f language'
where f = fromMaybe "" . fmap ("." <>)
mannedMan :: (Semigroup a, IsString a) => a -> Maybe a -> Maybe a -> a
mannedMan page section' language'
= "https://manned.org/man" <> f language' <> "/" <> page <> f section'
where f = fromMaybe "" . fmap ("." <>)
-- Comparison of online man pages:
-- https://gist.github.com/rixx/6cb5fa38f694009ad0bd50c275bb61f2
rewriters :: (Semigroup a, IsString a) => Map String (a -> Maybe a -> Maybe a -> a)
rewriters = M.fromList [ ("arch", archMan)
, ("manned", mannedMan)
]
|