svitak/app/Main.hs

45 lines
1.2 KiB
Haskell

module Main (main) where
import System.Environment (getArgs)
import Control.Monad.Reader (runReaderT, liftIO)
import EpubParser (EpubAction, openEpub, resolveSpine, getChapter)
import Gui (runWindow)
main :: IO ()
main = do
args <- getArgs
case args of
[] -> do
putStrLn "Starting GUI..."
runWindow -- This is just for testing GTK works, useless for now.
(path:_) -> runSvitak path
runSvitak :: FilePath -> IO ()
runSvitak path = do
result <- openEpub path
case result of
Left err -> putStrLn $ "Error: " ++ err
Right env -> do
runReaderT prntCh env
prntCh :: EpubAction ()
prntCh = do
chapterPaths <- resolveSpine
liftIO $ putStrLn $ "Spine resolved: " ++ show chapterPaths -- Print the found chapter paths for debugging
findText chapterPaths
where
findText [] = liftIO $ putStrLn "No chapters found in spine."
findText (p:ps) = do
liftIO $ putStrLn $ "\n--- Checking Chapter: " ++ p ++ " ---"
tags <- getChapter p
if null tags
then findText ps
else do
liftIO $ mapM_ print tags -- Each tag has a new line, only print the first one for testing
pure ()