X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Flwn-epub.git;a=blobdiff_plain;f=src%2FEpublishable.hs;h=3ca9b68b57babd9c6fa22e24defe059afdcca814;hp=01d27f9afe7c648250377d38003607dc707037f1;hb=d5bab2c486d30e54d3e94cc3bdbb230f2cd1f3f3;hpb=b591d5f5c3c47d253c24144beae1edf8648cd94b diff --git a/src/Epublishable.hs b/src/Epublishable.hs index 01d27f9..3ca9b68 100644 --- a/src/Epublishable.hs +++ b/src/Epublishable.hs @@ -1,14 +1,13 @@ module Epublishable where -import Codec.EBook -import qualified Data.ByteString.Lazy as B (writeFile) -import Data.List (foldl') +import Text.Pandoc +import qualified Data.ByteString.Lazy as B (ByteString, writeFile) +import Data.Time (getCurrentTime) 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 @@ -17,21 +16,28 @@ class (XHTML a) => Epublishable a where 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 - } + metadata :: a -> IO String + metadata obj = do + date <- getCurrentTime + return $ + "http://lwn.net/\n" ++ + "" ++ (show date) ++ "\n" ++ + "en-US\n" ++ + "Copyright Eklektix, Inc.\n" ++ + "" ++ (title obj) ++ "\n" + + epublish :: a -> FilePath -> IO () + epublish obj path = do let xhtml = to_xhtml obj - bs_xhtml <- string_to_bytestring xhtml - let iid = "iid-1" + epmd <- metadata obj + epub <- xhtml_to_epub epmd xhtml 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 + B.writeFile normalized_path epub + +xhtml_to_epub :: String -> String -> IO B.ByteString +xhtml_to_epub epmd = + write_epub . read_html + where + my_writer_options = defaultWriterOptions { writerEPUBMetadata = epmd } + write_epub = writeEPUB Nothing [] my_writer_options + read_html = readHtml defaultParserState