Skip to content

Commit

Permalink
use local items where those in main repo have changed
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswilm committed Dec 5, 2024
1 parent 238ad35 commit e1d196a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
epubBookCoverTemplate,
epubBookOpfTemplate,
epubBookTitlepageTemplate,
navTemplate,
ncxTemplate,
xhtmlTemplate
} from "./templates"
import {
Expand All @@ -26,9 +28,7 @@ import {RenderCitations} from "../../../citations/render"
import {addAlert} from "../../../common"
import {
containerTemplate,
navTemplate,
ncxItemTemplate,
ncxTemplate
ncxItemTemplate
} from "../../../exporter/epub/templates"
import {removeHidden} from "../../../exporter/tools/doc_content"
import {createSlug} from "../../../exporter/tools/file"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {escapeText, localizeDate} from "../../../common"
import {ncxItemTemplate} from "../../../exporter/epub/templates"
import {LANGUAGES} from "../../../schema/const"
import {bookTerm} from "../../i18n"

Expand Down Expand Up @@ -301,3 +302,60 @@ export const epubBookCopyrightTemplate = ({
</section>
</body>
</html>`

/** A template of the NCX file of an epub. */
export const ncxTemplate = ({shortLang, idType, id, title, contentItems}) =>
`<?xml version="1.0" encoding="UTF-8"?>
<ncx xmlns:ncx="http://www.daisy.org/z3986/2005/ncx/" xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="${shortLang}">
<head>
<meta name="dtb:${idType}" content="${id}"/>
</head>
<docTitle>
<text>${escapeText(title)}</text>
</docTitle>
<navMap>
<!-- 2.01 NCX: playOrder is optional -->
${contentItems.map(item => ncxItemTemplate({item})).join("")}
</navMap>
</ncx>`

/** A template for each item in an epub's navigation document. */
const navItemTemplate = ({item}) =>
`\t\t\t\t<li><a href="${
item.link
? item.link
: item.docNum
? `document-${item.docNum}.xhtml#${item.id}`
: `document.xhtml#${item.id}`
}">${escapeText(item.title)}</a>
${
item.subItems.length
? `<ol>
${item.subItems.map(item => navItemTemplate({item})).join("")}
</ol>`
: ""
}
</li>`

/** A template for an epub's navigation document. */
export const navTemplate = ({shortLang, contentItems, styleSheets}) =>
`<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="${shortLang}" lang="${shortLang}" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<meta charset="utf-8"></meta>
<title>Navigation</title>
${styleSheets
.map(
sheet =>
`<link rel="stylesheet" type="text/css" href="${sheet.filename}" />\n`
)
.join("")}
</head>
<body class="epub navigation">
<nav epub:type="toc" id="toc">
<ol>
${contentItems.map(item => navItemTemplate({item})).join("")}
</ol>
</nav>
</body>
</html>`

0 comments on commit e1d196a

Please sign in to comment.