Complete mapping from spine to full path in manifest

This commit is contained in:
Marko Andjelic 2026-01-24 02:03:09 +00:00
commit a9e774676e

View file

@ -8,7 +8,7 @@ import Text.HTML.Scalpel (scrape, text, tagSelector, attr, attrs, Scraper, chroo
import System.FilePath (takeDirectory, (</>))
import Control.Monad.Reader
import qualified Data.Text as T
import Data.Maybe (fromMaybe)
import Data.Maybe (fromMaybe, catMaybes)
import qualified Data.Map as M
type EpubAction a = ReaderT EpubEnv IO a
@ -62,7 +62,6 @@ getTagText tagName tags =
let scraper = text (tagSelector tagName)
in T.pack $ fromMaybe "" (scrape scraper tags)
getSpine :: [Tag String] -> [T.Text]
getSpine tags =
map T.pack . fromMaybe [] $ scrape (attrs "idref" (tagSelector "itemref")) tags
@ -81,7 +80,8 @@ resolvePath spineId = do
m <- asks manifestMap
p <- asks rootPrefix
let mHref = M.lookup spineId m
pure $ fmap (\href -> p </> T.unpack href) (M.lookup spineId m)
pure $ fmap (\href -> p </> T.unpack href) mHref
resolveSpine :: EpubAction [FilePath]
resolveSpine =
catMaybes <$> (asks spine >>= mapM resolvePath)