X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Flwn-epub.git;a=blobdiff_plain;f=src%2FEpublishable.hs;fp=src%2FEpublishable.hs;h=01d27f9afe7c648250377d38003607dc707037f1;hp=0000000000000000000000000000000000000000;hb=b591d5f5c3c47d253c24144beae1edf8648cd94b;hpb=8e5616a377196f0a200947173d4c78a3dca8a55f diff --git a/src/Epublishable.hs b/src/Epublishable.hs new file mode 100644 index 0000000..01d27f9 --- /dev/null +++ b/src/Epublishable.hs @@ -0,0 +1,37 @@ +module Epublishable +where + +import Codec.EBook +import qualified Data.ByteString.Lazy as B (writeFile) +import Data.List (foldl') +import Data.Tree.NTree.TypeDefs (NTree) +import System.FilePath (normalise) +import Text.XML.HXT.Core (IOSArrow, XNode, XmlTree) + +import Misc (string_to_bytestring) +import XHTML + + +class (XHTML a) => Epublishable a where + parse :: IOSArrow XmlTree (NTree XNode) -> IO (Maybe a) + + title :: a -> String + + epublish :: a -> FilePath -> Integer -> IO () + epublish obj path time = do + let book_name = title obj + let book = + emptyBook { + bookID = "http://lwn.net/" ++ book_name, + bookAuthor = "LWN Copyright Eklektix, Inc.", + bookTitle = book_name + } + let xhtml = to_xhtml obj + bs_xhtml <- string_to_bytestring xhtml + let iid = "iid-1" + let normalized_path = normalise path + let metadata = Just (ChapterMetadata book_name) + let bi = BookItem iid normalized_path bs_xhtml opsMediatype metadata + let bookFull = foldl' addItem2Book book [bi] + let outdata = book2Bin bookFull time + B.writeFile normalized_path outdata