01d27f9afe7c648250377d38003607dc707037f1
[dead/lwn-epub.git] / src / Epublishable.hs
1 module Epublishable
2 where
3
4 import Codec.EBook
5 import qualified Data.ByteString.Lazy as B (writeFile)
6 import Data.List (foldl')
7 import Data.Tree.NTree.TypeDefs (NTree)
8 import System.FilePath (normalise)
9 import Text.XML.HXT.Core (IOSArrow, XNode, XmlTree)
10
11 import Misc (string_to_bytestring)
12 import XHTML
13
14
15 class (XHTML a) => Epublishable a where
16 parse :: IOSArrow XmlTree (NTree XNode) -> IO (Maybe a)
17
18 title :: a -> String
19
20 epublish :: a -> FilePath -> Integer -> IO ()
21 epublish obj path time = do
22 let book_name = title obj
23 let book =
24 emptyBook {
25 bookID = "http://lwn.net/" ++ book_name,
26 bookAuthor = "LWN <http://lwn.net> Copyright Eklektix, Inc.",
27 bookTitle = book_name
28 }
29 let xhtml = to_xhtml obj
30 bs_xhtml <- string_to_bytestring xhtml
31 let iid = "iid-1"
32 let normalized_path = normalise path
33 let metadata = Just (ChapterMetadata book_name)
34 let bi = BookItem iid normalized_path bs_xhtml opsMediatype metadata
35 let bookFull = foldl' addItem2Book book [bi]
36 let outdata = book2Bin bookFull time
37 B.writeFile normalized_path outdata