svitak/app/Main.hs

37 lines
948 B
Haskell

module Main (main) where
import System.Environment (getArgs)
import Control.Monad.Reader (runReaderT)
import EpubParser (EpubAction, openEpub, resolveSpine, getChapter)
import Gui (runWindow)
import qualified Data.Text as T
import Text.HTML.TagSoup (renderTags)
main :: IO ()
main = do
args <- getArgs
case args of
[] -> do
putStrLn "Starting GUI..."
runWindow "<h1>Welcome to Svitak</h1><p>Please input an epub file.</p>"
(path:_) -> runSvitak path
runSvitak :: FilePath -> IO ()
runSvitak path = do
result <- openEpub path
case result of
Left err -> putStrLn $ "Error: " ++ err
Right env -> do
htmlContent <- runReaderT loadBook env
runWindow htmlContent
loadBook :: EpubAction String
loadBook = do
spine <- resolveSpine
case spine of
[] -> pure "<h1>No chapters found</h1>"
(firstChapter:_) -> do
tags <- getChapter firstChapter
pure $ T.unpack $ renderTags tags