Reference name algorithm
This commit is contained in:
parent
fdf0f88dea
commit
6e0fa21ba9
20
app/Main.hs
20
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
|
||||
|
||||
if not (null h)
|
||||
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 (=='#'))
|
||||
|
|
Loading…
Reference in a new issue