base.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. const start = 1;
  2. module.exports = {
  3. opf: function (info, list) {
  4. return new Promise(resolve => {
  5. function item(list) {
  6. let html = '';
  7. list.forEach(key => {
  8. if (startAndEnd(key)) {
  9. html += `
  10. <item id="text${key.index}.xhtml" href="Text/text${key.index}.xhtml" media-type="application/xhtml+xml"/>
  11. `;
  12. }
  13. });
  14. return html;
  15. }
  16. function itemref(list) {
  17. let html = '';
  18. list.forEach(key => {
  19. if (startAndEnd(key)) {
  20. html += `
  21. <itemref idref="text${key.index}.xhtml"/>`;
  22. }
  23. });
  24. return html;
  25. }
  26. let html = `<?xml version="1.0" encoding="utf-8"?>
  27. <package version="2.0" unique-identifier="BookId" xmlns="http://www.idpf.org/2007/opf">
  28. <metadata xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/">
  29. <dc:creator>${info.author}</dc:creator>
  30. <dc:language>zh</dc:language>
  31. <dc:title>${info.name}</dc:title>
  32. <meta content="0.9.10" name="Sigil version" />
  33. <dc:date xmlns:opf="http://www.idpf.org/2007/opf" opf:event="modification">${info.time}</dc:date>
  34. <dc:identifier id="BookId" opf:scheme="UUID">urn:uuid:${info.uid}</dc:identifier>
  35. <meta name="cover" content="cover.jpg" />
  36. </metadata>
  37. <manifest>
  38. <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
  39. ${item(list)}
  40. <item id="book.xhtml" href="Text/book.xhtml" media-type="application/xhtml+xml"/>
  41. <item id="mc-style.css" href="Styles/mc-style.css" media-type="text/css"/>
  42. <item id="cover.jpg" href="Images/cover.jpg" media-type="image/jpeg"/>
  43. <item id="cover.xhtml" href="Text/cover.xhtml" media-type="application/xhtml+xml"/>
  44. </manifest>
  45. <spine toc="ncx">
  46. <itemref idref="cover.xhtml"/>
  47. <itemref idref="book.xhtml"/>
  48. ${itemref(list)}
  49. </spine>
  50. <guide>
  51. <reference type="cover" title="封面" href="Text/cover.xhtml"/>
  52. </guide>
  53. </package>
  54. `;
  55. resolve(html);
  56. });
  57. },
  58. tocNcx: function (info, list) {
  59. return new Promise(resolve => {
  60. function navPoint(list) {
  61. let page = '';
  62. list.forEach(key => {
  63. if (startAndEnd(key)) {
  64. page += `<navPoint id="navPoint-${key.index + 1}" playOrder="${key.index + 1}">
  65. <navLabel>
  66. <text>${key.title}</text>
  67. </navLabel>
  68. <content src="Text/text${key.index}.xhtml"/>
  69. </navPoint>`
  70. }
  71. })
  72. return page
  73. }
  74. const html = `<?xml version="1.0" encoding="UTF-8"?>
  75. <!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
  76. "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
  77. <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
  78. <head>
  79. <meta name="dtb:uid" content="urn:uuid:${info.uid}"/>
  80. <meta name="dtb:depth" content="1"/>
  81. <meta name="dtb:totalPageCount" content="0"/>
  82. <meta name="dtb:maxPageNumber" content="0"/>
  83. </head>
  84. <docTitle>
  85. <text>${info.name}</text>
  86. </docTitle>
  87. <navMap>
  88. <navPoint id="navPoint-1" playOrder="1">
  89. <navLabel>
  90. <text>制作信息</text>
  91. </navLabel>
  92. <content src="Text/book.xhtml"/>
  93. </navPoint>
  94. ${navPoint(list)}
  95. </navMap>
  96. </ncx>
  97. `;
  98. resolve(html)
  99. })
  100. },
  101. book: function (info) {
  102. return new Promise(resolve => {
  103. const html = `<?xml version="1.0" encoding="utf-8"?>
  104. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  105. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  106. <html xmlns="http://www.w3.org/1999/xhtml">
  107. <head>
  108. <title></title>
  109. <link href="../Styles/mc-style.css" type="text/css" rel="stylesheet"/>
  110. </head>
  111. <body>
  112. <h1 class="sigil_not_in_toc">${info.name}</h1>
  113. <div class="author">
  114. <b>${info.author}</b> <span style="font-size: smaller;">/ 著</span>
  115. </div>
  116. <div class="copyright">
  117. 排版/制作:飞鼠
  118. </div>
  119. <p style="text-align: center; font-size: smaller; text-indent: 0;"><a href="http://mebook.cc" target="_blank">www.mebook.cc</a></p>
  120. </body>
  121. </html>`
  122. resolve(html)
  123. })
  124. },
  125. page: function (item, content) {
  126. return new Promise(resolve => {
  127. function page(content) {
  128. let contents = content.split('\n');
  129. let html = ''
  130. contents.forEach(key => {
  131. html += `
  132. <p>${key}</p>`
  133. })
  134. return html
  135. }
  136. const html = `
  137. <html xmlns="http://www.w3.org/1999/xhtml" lang="zh" xml:lang="zh">
  138. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  139. <body>
  140. <h3 id="id${item.index}">${content.title}</h3>
  141. ${page(content.page)}
  142. </body>
  143. </html>
  144. `;
  145. resolve(html);
  146. });
  147. },
  148. name: '微微一笑很倾城',
  149. author: '顾漫',
  150. uid: '',
  151. time: ''
  152. };
  153. function startAndEnd(item) {
  154. return item.index > 0 && item.index < 605;
  155. }