From 6e0fa21ba9340a9f0390e3ee211fddba8c69746f Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Sat, 5 Aug 2023 01:23:06 +0200 Subject: [PATCH] Reference name algorithm --- app/Main.hs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index a1ce0de..2e5217e 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -36,22 +36,28 @@ main = parseArgs =<< execParser opts parseArgs :: Args -> IO() parseArgs (Args t dir h v r c) = do - if c then do - print CgiSuccess + if c + then do print CgiSuccess putStrLn $ "# " ++ t - else putStrLn $ "# " ++ t + else putStrLn $ "# " ++ t + if not (null h) - then putStr $ "\n" ++ h ++ "\n\n" - else putStr "\n" + then putStr $ "\n" ++ h ++ "\n\n" + else putStr "\n" + mapM_ (mkIndex r dir) . filter (isSuffixOf ".gmi") =<< getDirectoryContents dir mkIndex :: Bool -> FilePath -> FilePath -> IO () -mkIndex True d l = do - line <- head . lines <$> readFile path - putStrLn $ "=> " ++ path ++ line - where path = d++"/"++l++" " mkIndex False d l = putStrLn $ "=> " ++ path where path = d++"/"++l ---compose = (++) <$> ("=> " ++) <*> (show . length) <*> (head . lines =<< readFile) +mkIndex True d l = do + line <- trim . words . head . lines <$> readFile path + putStrLn $ "=> " ++ path ++ " " ++ line + where path = d++"/"++l + trim s + | length s >= 8 = (++ "...") . unwords . take 8 . cleanString $ s + | otherwise = unwords . cleanString $ s + -- remove all '#' signs and any potential resulting empty lists + where cleanString = filter(/="") . map (dropWhile (=='#'))