1 module epub.books;
2 
3 @safe:
4 
5 import std.conv;
6 import std.uuid;
7 import std.experimental.logger;
8 
9 /**
10  * A Book is the object model for an epub file.
11  */
12 class Book
13 {
14     /** The ID of the book.
15      * If you don't specify one, we will create it for you.
16      */
17     string id;
18 
19     /// The title of the book.
20     string title;
21 
22     /// The author of the book.
23     string author;
24 
25     /// The fileid of the cover image, which should be present as an attachment.
26     string coverid;
27 
28     /// The chapters of the book, in the order to present them.
29     Chapter[] chapters;
30 
31     /// Attachments (extra files) to include in the epub.
32     Attachment[] attachments;
33 
34     /// The attachment to use as a cover image.
35     Attachment coverImage;
36 
37     import epub.cover;
38 
39     /// The cover page to generate. If not set, no cover page is generated.
40     Cover cover;
41 }
42 
43 /**
44  * An Attachment is a file to include in the epub document.
45  *
46  * For instance, if you want to include an image or stylesheet in the epub,
47  * you should create an Attachment for it.
48  */
49 struct Attachment
50 {
51     /// The ID of the file. Generated if you don't provide it.
52     string fileid;
53 
54     /// The path in the epub to this file.
55     string filename;
56 
57     /// The mime type of the file.
58     string mimeType;
59 
60     /// The file contents.
61     const(ubyte)[] content;
62 }
63 
64 /**
65  * A Chapter is like an Attachment, but it appears in the main content of
66  * the book.
67  *
68  * Chapter content must be a valid XHTML document. The content type is
69  * always "application/xhtml+xml". If you specify invalid XHTML, it is
70  * unlikely that your epub will work.
71  */
72 struct Chapter
73 {
74     /// The title of this chapter, if it's in the table of contents.
75     string title;
76 
77     /// Whether to show this chapter in the table of contents.
78     bool showInTOC;
79 
80     /// The contents of this chapter.
81     const(char)[] content;
82 
83     package int index;
84 
85     package string fileid()
86     {
87         return `chapter` ~ index.to!string;
88     }
89 
90     package string filename()
91     {
92         return `chapter` ~ index.to!string ~ `.html`;
93     }
94 
95     package string id()
96     {
97         return title.sha1UUID().to!string;
98     }
99 }
100