diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-11-15 19:04:04 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-11-15 20:14:17 +0100 |
commit | 54c57126addf787c46ef03f6d532732ffd8943f9 (patch) | |
tree | 574fd3d6f8794510252bc502719294d4a1d93eaf | |
parent | Templetize version in makefile. (diff) | |
download | vimwiki-scripts-54c57126addf787c46ef03f6d532732ffd8943f9.tar.gz vimwiki-scripts-54c57126addf787c46ef03f6d532732ffd8943f9.tar.xz |
Cleanup after running through LSP.
-rw-r--r-- | hs/src/Data/Text/Compat.hs | 2 | ||||
-rw-r--r-- | hs/src/Files.hs | 7 | ||||
-rw-r--r-- | hs/src/Handlingar.hs | 4 | ||||
-rw-r--r-- | hs/src/Html.hs | 60 | ||||
-rw-r--r-- | hs/src/System/Home.hs | 2 | ||||
-rw-r--r-- | hs/src/Vimwiki/Man.hs | 6 | ||||
-rw-r--r-- | hs/src/main.hs | 2 |
7 files changed, 38 insertions, 45 deletions
diff --git a/hs/src/Data/Text/Compat.hs b/hs/src/Data/Text/Compat.hs index f07d60a..81efddb 100644 --- a/hs/src/Data/Text/Compat.hs +++ b/hs/src/Data/Text/Compat.hs @@ -1,6 +1,6 @@ {-# LANGUAGE CPP , FlexibleInstances - , TypeSynonymInstances #-} + #-} module Data.Text.Compat where diff --git a/hs/src/Files.hs b/hs/src/Files.hs index 20554c1..bddcad6 100644 --- a/hs/src/Files.hs +++ b/hs/src/Files.hs @@ -36,7 +36,7 @@ fmt st | isBlockDevice st = "block" | otherwise = "UNKNOWN" instance Show FileStatus where - show st = fmt st + show = fmt fileTree :: [FilePath] -> IO [(FileStatus, [FilePath])] fileTree base = do @@ -58,8 +58,9 @@ isFiletype extension st path copyFile' :: FilePath -> FileStatus -> [FilePath] -> IO () copyFile' dest st path - | isDirectory st = createDirectoryIfMissing True (dest </> (joinPath $ tail path)) - | otherwise = copyFile (joinPath path) $ dest </> (joinPath $ tail path) + | isDirectory st = createDirectoryIfMissing True p + | otherwise = copyFile (joinPath path) p + where p = dest </> joinPath (tail path) copyFiles :: FilePath -> [(FileStatus, [FilePath])] -> IO () copyFiles dest = mapM_ (uncurry $ copyFile' dest) diff --git a/hs/src/Handlingar.hs b/hs/src/Handlingar.hs index 281223f..e6d2d96 100644 --- a/hs/src/Handlingar.hs +++ b/hs/src/Handlingar.hs @@ -45,8 +45,8 @@ headingLevel _ = error "Need header" getHeadingData :: Text -> [Block] -> [Block] getHeadingData heading blocks = let (head:remaining) = dropWhile (not . findHeading heading) blocks - items = takeWhile (not . (oneOf (findHorizontalRule) - (findHeadingByLevel $ headingLevel head))) + items = takeWhile (not . oneOf findHorizontalRule + (findHeadingByLevel $ headingLevel head)) remaining in head : items diff --git a/hs/src/Html.hs b/hs/src/Html.hs index 57a132b..bcc25b1 100644 --- a/hs/src/Html.hs +++ b/hs/src/Html.hs @@ -21,6 +21,7 @@ import Control.Lens (_2) import Control.Lens.Operators hiding ((<.>)) import Control.Lens.Setter (ASetter) +import Control.Monad (when) import Control.Monad.IO.Class (liftIO) import Data.Default (def) @@ -93,11 +94,11 @@ mailRewriter :: String -> [Inline] -> URI -> ([Inline], PandocStr) mailRewriter mu4eURL body uri = (body, conv $ mu4eURL <> "?id=" <> uriPath uri) urlRewrites :: Configuration -> Map String ([Inline] -> URI -> ([Inline], PandocStr)) -urlRewrites conf = M.fromList $ (maybeToList $ ((,) "mail") . mailRewriter <$> (conf ^. output . mu4eURL)) +urlRewrites conf = M.fromList $ maybeToList ((,) "mail" . mailRewriter <$> (conf ^. output . mu4eURL)) -- TODO include descriptive text from -- original link - ++ case (conf ^. output . manProvider) >>= ((flip M.lookup) rewriters) of - Just impl -> [("man", manRewriter $ impl)] + ++ case (conf ^. output . manProvider) >>= flip M.lookup rewriters of + Just impl -> [("man", manRewriter impl)] Nothing -> [] @@ -124,7 +125,7 @@ rebuildLinks conf l@(Link attributes body (url, title@"wikilink")) , Superscript [Str $ conv wikiname]] (conv $ resolveInterwiki (conf ^. wikis) wikiname uri, title) _ -> case M.lookup (init . uriScheme $ uri) (urlRewrites conf) of - Just proc -> (proc body uri) & (\(body, url) -> Link attributes body (url, title)) + Just proc -> proc body uri & (\(body, url) -> Link attributes body (url, title)) Nothing -> l Nothing -> case break (== '#') (from url) of ("", '#':_) -> Link attributes body (url, title) @@ -157,10 +158,10 @@ applyFilters conf pandoc = pandoc & walk buildCheckboxes' handleSourceText :: PandocMonad m => Configuration -> Text -> m Pandoc -handleSourceText conf text = (& applyFilters conf) <$> readVimwiki def text +handleSourceText conf text = applyFilters conf <$> readVimwiki def text breadcrumbLinks :: Configuration -> [FilePath] -> [String] -breadcrumbLinks conf parts = f <$> (accumulate $ (conf ^. output . webPath) : parts) +breadcrumbLinks conf parts = f <$> accumulate ((conf ^. output . webPath) : parts) where f parts = joinBy "/" parts -<.> "html" buildBreadcrumbs :: [String] -> [Html] @@ -176,14 +177,14 @@ htmlWrap conf title parts backlinks mtoc main = docTypeHtml $ do H.meta ! charset "utf-8" H.meta ! name "generator" ! content "pandoc" H.meta ! name "viewport" ! content "width=device-width, initial-scale=1.0, user-scalable=yes" - H.link ! rel "stylesheet" ! (href . textValue $ (pack $ conf ^. output . webPath <> "/style.css")) - H.script ! (A.src . textValue $ (pack $ conf ^. output . webPath <> "/script.js")) $ mempty + H.link ! rel "stylesheet" ! (href . textValue $ pack (conf ^. output . webPath <> "/style.css")) + H.script ! (A.src . textValue $ pack (conf ^. output . webPath <> "/script.js")) $ mempty H.title $ H.string $ title <> " — Vimwiki" H.body $ do H.header $ do H.nav ! A.id "breadcrumb" $ do - let bc = (buildBreadcrumbs . breadcrumbLinks conf $ init parts) - let all = mconcat [ [ H.a ! (href . textValue $ (pack $ conf ^. output . webPath) <> "/index.html") + let bc = buildBreadcrumbs . breadcrumbLinks conf $ init parts + let all = mconcat [ [ H.a ! (href . textValue $ pack (conf ^. output . webPath) <> "/index.html") $ "⌂" ] , tail bc , [ H.span $ H.string . takeBaseName . last $ parts ] ] @@ -197,7 +198,7 @@ htmlWrap conf title parts backlinks mtoc main = docTypeHtml $ do H.input ! A.type_ "search" ! A.name "P" ! A.placeholder "Sök..." H.input ! A.type_ "submit" ! A.value "Sök" H.div ! A.id "with-resizer" $ do - H.main $ main + H.main main case mtoc of Just toc -> do H.div ! A.id "resizer" $ do @@ -238,13 +239,13 @@ handlePart conf outdir backlinks wiki_root parts = do bl <- case M.lookup (pack . dropExtension $ item_path) backlinks of Just links -> return $ (H.h2 . H.string $ "Backlinks") - <> (H.ul . mconcat $ (H.li . toHtml) <$> (S.toList links)) + <> (H.ul . mconcat $ H.li . toHtml <$> S.toList links) Nothing -> return $ H.b "No backlinks" pandoc <- handleSourceText conf text let Pandoc meta blocks = pandoc #if MIN_VERSION_pandoc(2, 6, 0) - toc <- fmap Just <$> writeHtml5 def $ Pandoc meta $ [toTableOfContents def blocks] + toc <- fmap Just <$> writeHtml5 def $ Pandoc meta [toTableOfContents def blocks] #else let toc = Nothing #endif @@ -257,7 +258,7 @@ handlePart conf outdir backlinks wiki_root parts = do -- liftIO $ print meta let title :: PandocStr = firstJust (conv $ takeBaseName item_path) [ nullToMaybe $ lookupMetaString "title" meta - , headerContent =<< (listToMaybe $ allHeaders pandoc) + , headerContent =<< listToMaybe (allHeaders pandoc) ] -- liftIO $ print log @@ -283,11 +284,9 @@ stripTrailing c s dup a = (a, a) filterM :: Monad m => (a -> m Bool) -> [a] -> m [a] -filterM f = fmap (fmap fst) - . fmap (filter snd) +filterM f = fmap (fmap fst . filter snd) . mapM sequence - . fmap (_2 %~ f) - . fmap dup + . fmap ((_2 %~ f) . dup) copyFromDatadir :: FilePath -> [FilePath] -> FilePath -> IO () copyFromDatadir filename datadirs destination = do @@ -308,23 +307,20 @@ main = do Left err -> error err Right conf -> return conf - let conf = (conf' & data' . inputDir .~? indir args - & data' . outputDir .~? outdir args - & output . webPath .~? webp args - & output . webPath %~ stripTrailing '/' - ) + let conf = conf' & data' . inputDir .~? indir args + & data' . outputDir .~? outdir args + & output . webPath .~? webp args + & output . webPath %~ stripTrailing '/' -- indir' <- expandTilde `mapM` indir args -- outdir' <- expandTilde `mapM` outdir args -- print conf - if null (conf ^. data' . inputDir) - then error "No input directory given" - else return () + when (null $ conf ^. data' . inputDir) + $ error "No input directory given" - if null (conf ^. data' . outputDir) - then error "No output directory given" - else return () + when (null $ conf ^. data' . outputDir) + $ error "No output directory given" print $ "input = " <> (conf ^. data' . inputDir) print $ "output = " <> (conf ^. data' . outputDir) @@ -359,9 +355,7 @@ main = do runIOorExplode $ do mlang <- toLang $ Just "sv-SE" - case mlang of - Nothing -> return () - Just l -> setTranslations l + mapM_ setTranslations mlang - mapM_ (handlePart conf (conf^.data'.outputDir) backlinks $ (conf ^. data' . inputDir)) relative_paths + mapM_ (handlePart conf (conf^.data'.outputDir) backlinks (conf ^. data' . inputDir)) relative_paths -- mapM_ (putStrLn . show) wikiFiles diff --git a/hs/src/System/Home.hs b/hs/src/System/Home.hs index 30a08f1..54f8b9c 100644 --- a/hs/src/System/Home.hs +++ b/hs/src/System/Home.hs @@ -6,7 +6,7 @@ import System.FilePath -- Return home directory for given user, or currently logged in user. getUserHome :: Maybe String -> IO (Either IOError String) -getUserHome Nothing = (Just <$> getEffectiveUserName) >>= getUserHome +getUserHome Nothing = getEffectiveUserName >>= getUserHome . Just getUserHome (Just name) = tryIOError $ homeDirectory <$> getUserEntryForName name -- If the first component of path is either a tilde `~', or a tilde diff --git a/hs/src/Vimwiki/Man.hs b/hs/src/Vimwiki/Man.hs index fca432d..406a83c 100644 --- a/hs/src/Vimwiki/Man.hs +++ b/hs/src/Vimwiki/Man.hs @@ -18,7 +18,7 @@ import Data.Text.Compat manRewriter :: (PandocStr -> Maybe PandocStr -> Maybe PandocStr -> PandocStr) -> [Inline] -> URI -> ([Inline], PandocStr) manRewriter manImpl body uri - = (handle body $ path <> "(" <> (fromMaybe "?" section') <> ")" + = (handle body $ path <> "(" <> fromMaybe "?" section' <> ")" , manImpl path section' language') where path :: PandocStr path = conv $ uriPath uri @@ -32,12 +32,12 @@ manRewriter manImpl body 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 ("." <>) + where f = maybe "" ("." <>) 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 ("." <>) + where f = maybe "" ("." <>) -- Comparison of online man pages: diff --git a/hs/src/main.hs b/hs/src/main.hs index 1b38cba..017ee66 100644 --- a/hs/src/main.hs +++ b/hs/src/main.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE OverloadedStrings #-} - module Main where import qualified Html |