Commit 778adea0 authored by Alexandros Georgantas's avatar Alexandros Georgantas

TOC update and single css file

parent e4ee3e19
...@@ -170,19 +170,36 @@ class HTMLEPUB { ...@@ -170,19 +170,36 @@ class HTMLEPUB {
$('head > link[rel="stylesheet"]').each((index, node) => { $('head > link[rel="stylesheet"]').each((index, node) => {
const $node = $(node) const $node = $(node)
const id = `style-${chapter}-${index}`
const uri = $node.attr('href').replace(/^\//, '') // ensure no leading slash const uri = $node.attr('href').replace(/^\//, '') // ensure no leading slash
// const id = `style-${chapter}-${index}`
const source = url.resolve(stylesRoot, uri) const source = url.resolve(stylesRoot, uri)
const stylesRootExpanded = source.split('/')
const filenameWithExtension = stylesRootExpanded[stylesRootExpanded.length - 1]
const filenameWithoutExtension = filenameWithExtension.split('.')[0]
if (source.indexOf(stylesRoot) !== 0) { if (source.indexOf(stylesRoot) !== 0) {
throw new Error('Resource is outside the style root') throw new Error('Resource is outside the style root')
} }
const id = filenameWithoutExtension
const target = `styles/${id}.css` const target = `styles/${id}.css`
const mimetype = 'text/css' const mimetype = 'text/css'
epub.styles.push({ id, source, mimetype, target }) if (epub.styles.length === 0) {
epub.styles.push({ id, source, mimetype, target })
} else {
let found = false
for (let i = 0; i < epub.styles.length; i++) {
if (epub.styles[i].id === id) {
found = true
break
}
}
if (!found) {
epub.styles.push({ id, source, mimetype, target })
}
}
$node.attr('href', '../' + target) $node.attr('href', '../' + target)
}) })
...@@ -219,6 +236,7 @@ class HTMLEPUB { ...@@ -219,6 +236,7 @@ class HTMLEPUB {
} }
get toc () { get toc () {
const epub = this
return { return {
html: { html: {
'@xmlns': 'http://www.w3.org/1999/xhtml', '@xmlns': 'http://www.w3.org/1999/xhtml',
...@@ -227,21 +245,30 @@ class HTMLEPUB { ...@@ -227,21 +245,30 @@ class HTMLEPUB {
meta: { meta: {
'@charset': 'utf-8' '@charset': 'utf-8'
}, },
title: this.book.title title: this.book.title,
link: {
'@href': epub.styles[0].target,
'@rel': 'stylesheet',
'@type': epub.styles[0].mimetype
}
}, },
body: { body: {
header: { section: {
h1: 'Contents' '@data-type': 'toc',
}, header: {
nav: { h1: 'Contents'
'@epub:type': 'toc', },
ol: { nav: {
li: this.xhtml.map(item => ({ '@epub:type': 'toc',
'a': { '@class': 'toc',
'@href': item.target, ol: {
'#text': item.title li: this.xhtml.map(item => ({
} 'a': {
})) '@href': item.target,
'#text': item.title
}
}))
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment