123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- const start = 1;
- module.exports = {
- opf: function (name, list) {
- return new Promise(resolve => {
- function page1(list) {
- let html = '';
- list.forEach(key => {
- if (startAndEnd(key)) {
- html += `
- <item id="text${key.index}" media-type="text/x-oeb1-document" href="page/text${key.index}.html"></item>`;
- }
- });
- return html;
- }
-
- function page2(list) {
- let html = '';
- list.forEach(key => {
- if (startAndEnd(key)) {
- html += `
- <itemref idref="text${key.index}"/>`;
- }
- });
- return html;
- }
-
- let html = `<?xml version="1.0" encoding="iso-8859-1"?>
- <package unique-identifier="uid" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:asd="http://www.idpf.org/asdfaf">
- <metadata>
- <dc-metadata xmlns:dc="http://purl.org/metadata/dublin_core"
- xmlns:oebpackage="http://openebook.org/namespaces/oeb-package/1.0/">
- <dc:Title>${name}</dc:Title>
- <dc:Language>zh</dc:Language>
- <dc:Creator>Amazon.com</dc:Creator>
- <dc:Copyrights>Amazon.com</dc:Copyrights>
- <dc:Publisher>Amazon.com</dc:Publisher>
- <x-metadata>
- <EmbeddedCover>./danshijianzong.jpg</EmbeddedCover>
- </x-metadata>
- </dc-metadata>
- </metadata>
- <manifest>
- <item id="content" media-type="text/x-oeb1-document" href="toc.html"></item>
- <item id="ncx" media-type="application/x-dtbncx+xml" href="toc.ncx"/>
- ${page1(list)}
- </manifest>
- <spine toc="ncx">
- <itemref idref="content"/>
- ${page2(list)}
- </spine>
- <guide>
- <reference type="toc" title="Table of Contents" href="toc.html"/>
- <reference type="text" title="Book" href="text1.html"/>
- </guide>
- </package>`;
- resolve(html);
- });
- },
- toc: function (list) {
- return new Promise(resolve => {
- function page() {
- let html = '';
- list.forEach(key => {
- if (startAndEnd(key)) {
- html += `
- <li><a href="page/text${key.index}.html#id${key.index}">${key.title}</a></li>`;
- }
-
- });
- return html;
- }
-
- let html = `<!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml" lang="zh" xml:lang="zh">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=utf-8">
- <title>TOC</title>
- </head>
- <body>
- <h1 id="toc">目录</h1>
- <ul>
- ${page()}
- </ul>
- </body>
- </html>
- `;
- resolve(html);
- });
- },
- ncx: function (name, list) {
- return new Promise(resolve => {
- function page() {
- let html = '';
- list.forEach(key => {
- if (startAndEnd(key)) {
- html += `
- <navPoint id="navpoint-${key.index + 1}" playOeder="${key.index + 1}"><navLabel><text>${key.title}</text></navLabel><content src="page/text${key.index}.html#id${key.index}"></content></navPoint>`;
- }
- });
- return html;
- }
-
- let html = `<?xml version="1.0"?>
- <!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
- "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
- <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=utf-8">
- </head>
- <docTitle>
- <text>${name}</text>
- </docTitle>
- <navMap>
- <navPoint id="navpoint-1" playOrder="1"><navLabel><text>Content</text></navLabel><content src="toc.html#toc"/></navPoint>
- ${page()}
- </navMap>
- </ncx>`;
- resolve(html);
- });
- },
- page: function (item, content) {
- return new Promise(resolve => {
- const html = `
- <html xmlns="http://www.w3.org/1999/xhtml" lang="zh" xml:lang="zh">
- <meta http-equiv="content-type" content="text/html; charset=utf-8">
- <body>
- <h3 id="id${item.index}">${content.title}</h3>
- <p>
- ${content.page}
- </p>
- </body>
- </html>
- `;
- resolve(html);
- });
- },
- name: '择天记'
- };
- function startAndEnd(item) {
- return item.index > 0 && item.index < 605;
- }
|