02-other.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. const fs = require('fs');
  2. const moment = require('moment');
  3. const shell = require('shelljs');
  4. const utils = require('./utils/base');
  5. var $xindaming = require('./xindaming');
  6. utils.uid = moment().format();
  7. utils.time = moment().format('YYYY-MM-DD');
  8. function mkdir(path) {
  9. if (!fs.existsSync(path)) {
  10. fs.mkdirSync(path)
  11. }
  12. }
  13. // shell.exec('rm -rf book && mkdir book');
  14. mkdir('./book/META-INF');
  15. fs.writeFileSync('./book/META-INF/container.xml', `<?xml version="1.0" encoding="UTF-8"?>
  16. <container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
  17. <rootfiles>
  18. <rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>
  19. </rootfiles>
  20. </container>
  21. `)
  22. fs.writeFileSync('./book/mimetype', 'application/epub+zip')
  23. mkdir('./book/OEBPS')
  24. mkdir('./book/OEBPS/Images')
  25. mkdir('./book/OEBPS/Styles')
  26. fs.writeFileSync('./book/OEBPS/Styles/mc-style.css', `@charset "UTF-8";
  27. /*=========================font-face=========================*/
  28. @font-face {
  29. font-family:"zw";
  30. src:
  31. local("宋体"),local("明体"),local("明朝"),
  32. local("微软雅黑"),local("黑体"),
  33. local("Songti"),local("Songti SC"),local("Songti TC"),
  34. local("Song S"),local("Song T"),local("STBShusong"),local("TBMincho"),local("HYMyeongJo"),
  35. local("DK-SONGTI")
  36. local("Heiti"),local("Heiti SC"),local("Heiti TC"),
  37. local("MYing Hei S"),local("MYing Hei T"),local("TBGothic"),
  38. local("DK-HEITI"),
  39. url(../Fonts/fzzy.ttf);
  40. }
  41. /* This defines styles and classes used in sioebook */
  42. /*Global Setting*/
  43. * {
  44. margin: 0;
  45. padding: 0;
  46. }
  47. body {
  48. padding: 3% 2%;
  49. margin-top: 3%;
  50. margin-bottom: 3%;
  51. margin-left: 1%;
  52. margin-right: 1%;
  53. line-height: 1.3em;
  54. text-align: justify;
  55. font-family: "Times New Roman","方正书宋","宋体","明体","zw",sans-serif;
  56. }
  57. /* P 正常段落 */
  58. p {
  59. margin: 0.5em 0em;
  60. line-height: 1.3em;
  61. text-indent: 2em;
  62. }
  63. /* 居中、右、左 */
  64. .center {
  65. text-indent: 0em;
  66. text-align: center;
  67. }
  68. .right {
  69. text-indent: 0em;
  70. text-align: right;
  71. }
  72. .left {
  73. text-indent: 0em;
  74. text-align: left;
  75. }
  76. /*图片*/
  77. img {
  78. border: none;
  79. text-align: center;
  80. /*max-width: 100%;*/
  81. max-height: 100%;
  82. }
  83. /* 表格 */
  84. table {
  85. border-collapse: collapse;
  86. border-spacing: 0;
  87. margin: 0 auto 0;
  88. width: 100%;
  89. font-size: small;
  90. vertical-align:center;
  91. }
  92. tr,th,td {
  93. margin: 0;
  94. padding: 0.25em;
  95. border: none;
  96. font-size: 95%;
  97. font-family: "Times New Roman","方正书宋","宋体","明体","zw",sans-serif;
  98. text-indent: 0!important;
  99. text-align: left;
  100. vertical-align: middle;
  101. color: #666666;
  102. line-height: 1.05em;
  103. }
  104. /* 列表格式 */
  105. ul, ol {
  106. list-style:none;
  107. }
  108. /* 链接 颜色 不加下划线 */
  109. a {
  110. text-decoration:none;
  111. color: #663366;
  112. }
  113. a:hover {
  114. text-decoration:none;
  115. color: #CC99CC;
  116. }
  117. /* 文案 */
  118. .oval {
  119. padding: 5% 5%;
  120. margin: 12% 5% 2%;
  121. border: 0px dotted #993333;
  122. text-indent: 0em;
  123. font-size: 0.9em;
  124. color: #666666;
  125. }
  126. /* 水平线 */
  127. hr {
  128. border:0;
  129. background-color:#BEBEBE;
  130. height:1.5px;
  131. margin-top: 2%;
  132. margin-bottom: 2%;
  133. }
  134. /* 上下标注 */
  135. sup {
  136. font-size:small;
  137. }
  138. sub {
  139. font-size:small;
  140. }
  141. /* 标题1 书名 卷 */
  142. h1 {
  143. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  144. text-indent: 0em;
  145. text-align:center;
  146. line-height: 2em;
  147. margin-top: 30%;
  148. color: #996699;
  149. text-shadow: 1px 1px 1px gray;
  150. }
  151. h2 {
  152. color: #FFFFFF;
  153. margin-left:25%;
  154. line-height:200%;
  155. border-style: none double solid solid;
  156. border-width: 0px 3px 2px 30px;
  157. font-weight:bold;
  158. font-size:large;
  159. border-color: #FFFFFF;
  160. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  161. text-shadow: 1px 1px 1px gray;
  162. padding: 2px 10px 2px 10px;
  163. }
  164. h2.epub {
  165. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  166. text-indent: 0em;
  167. font-size: 1.2em;
  168. text-align: center;
  169. width: 1em;
  170. margin: 0em 5% 1.5em;
  171. line-height: 110%;
  172. color: #EEEEEE;
  173. border-style: none double none none;
  174. border-width: 0px 3px 0px 0px;
  175. border-color: #EEEEEE;
  176. padding: 0.5em 10px 0.5em 2px;
  177. text-shadow: 0px 0px 0px #AAAAAA;
  178. }
  179. h3 {
  180. margin: 1em 0 5em;
  181. color: #663366;
  182. line-height: 120%;
  183. text-align: left;
  184. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  185. text-shadow: 1px 1px 1px gray;
  186. padding: 15px 12px 1em 5px;
  187. border-style: none none dotted none;
  188. border-color: #CC6699;
  189. border-width: 0px 0px 1px 0px;
  190. text-shadow: 1px 1px 1px #AAAAAA;
  191. }
  192. h3.ebook {
  193. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  194. text-indent: 0em;
  195. margin: 1em 0 1em;
  196. padding: 2px 12px 2px 2px;
  197. text-align: left;
  198. line-height: 120%;
  199. border-style: none none none none;
  200. text-shadow: 1px 1px 1px #AAAAAA;
  201. }
  202. /* 章节序号 */
  203. .num {
  204. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  205. background-color: #CC6699;
  206. border-radius: 2px;
  207. padding: 4px 0.5em;
  208. color: #FFF;
  209. font-size: small;
  210. text-shadow: 1px 1px 1px #AAAAAA;
  211. }
  212. h4 {
  213. line-height: 2em;
  214. text-indent: 0em;
  215. color: #FFFFFF;
  216. margin-left:25%;
  217. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  218. text-shadow: 1px 1px 1px gray;
  219. }
  220. h5 {
  221. line-height: 1.5em;
  222. text-indent: 0em;
  223. color: #FF9900;
  224. font-size: 14px;
  225. }
  226. .vol {
  227. padding: 30% 5% 20%;
  228. margin: 15% -2em 2%;
  229. background-color: #996699;
  230. text-indent: 0em;
  231. }
  232. .volbg {
  233. background-color: #996699;
  234. }
  235. /* 作者译者编者等 */
  236. .author {
  237. margin: 20% 0;
  238. text-indent: 0em;
  239. text-align: center;
  240. font-size: 1em;
  241. line-height: 120%;
  242. font-weight: 600;
  243. color: #;
  244. }
  245. .wt {
  246. text-indent: 0em;
  247. font-style:italic;
  248. font-size: 0.9rem;
  249. line-height: 1.2em;
  250. color: #336699;
  251. }
  252. /* 出版社 */
  253. .copyright {
  254. margin: 35% 0 0;
  255. text-indent: 0em;
  256. text-align: center;
  257. font-size: 1em;
  258. line-height: 120%;
  259. font-weight: 300;
  260. color: #;
  261. }
  262. /* 书票 */
  263. .exL {
  264. margin: 45% 0;
  265. text-align: center;
  266. page-break-before: always;
  267. }
  268. .kh {
  269. text-indent: 0em;
  270. text-align: center;
  271. font-size: 0.80em;
  272. color: #EEEEEE;
  273. }
  274. /* 电子书信息 */
  275. .info {
  276. font-size: 1em;
  277. font-weight: bold;
  278. line-height: 150%;
  279. color: #666666;
  280. margin: 0 0 1em 20%;
  281. }
  282. .info_items {
  283. font-size: 0.8em;
  284. line-height: 120%;
  285. color: #666666;
  286. margin: 0 0 0 20%;
  287. }
  288. /* 多看 图框 */
  289. .duokan-image-single {
  290. margin: 0.5em 0;
  291. bottom: 2%;
  292. text-align: center;
  293. }
  294. /*++*/
  295. .rht {
  296. font-family: "微软雅黑","黑体","ht","zw",sans-serif;
  297. font-size: 115%;
  298. line-height: 120%;
  299. text-indent: 0em;
  300. text-align: right;
  301. color: #CCCCCC;
  302. }
  303. .lt {
  304. font-size: 80%;
  305. text-indent: 0em;
  306. text-align: right;
  307. color: #003366;
  308. }
  309. div.float {
  310. width: 42%;
  311. float: right;
  312. margin: 1em 0 0em 1em;
  313. }`)
  314. mkdir('./book/OEBPS/Text')
  315. fs.writeFileSync('./book/OEBPS/Text/cover.xhtml', `<?xml version="1.0" encoding="utf-8"?>
  316. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  317. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  318. <html xmlns="http://www.w3.org/1999/xhtml">
  319. <head>
  320. <title>Cover</title>
  321. </head>
  322. <body>
  323. <div style="text-align: center; padding: 0pt; margin: 0pt;">
  324. <svg xmlns="http://www.w3.org/2000/svg" height="100%" preserveAspectRatio="xMidYMid meet" version="1.1" viewBox="0 0 240 300" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink">
  325. <image width="240" height="300" xlink:href="../Images/cover.jpg"/>
  326. </svg>
  327. </div>
  328. </body>
  329. </html>`)
  330. // opf toc.ncx ...
  331. utils.opf(utils, $xindaming).then(res => {
  332. fs.writeFileSync('./book/OEBPS/content.opf', res);
  333. return utils.tocNcx(utils, $xindaming)
  334. }).then(res => {
  335. fs.writeFileSync('./book/OEBPS/toc.ncx', res);
  336. return utils.book(utils)
  337. }).then(res => {
  338. fs.writeFileSync('./book/OEBPS/Text/book.xhtml', res)
  339. });