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

TOC update and single css file

parent e4ee3e19
......@@ -170,19 +170,36 @@ class HTMLEPUB {
$('head > link[rel="stylesheet"]').each((index, node) => {
const $node = $(node)
const id = `style-${chapter}-${index}`
const uri = $node.attr('href').replace(/^\//, '') // ensure no leading slash
// const id = `style-${chapter}-${index}`
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) {
throw new Error('Resource is outside the style root')
}
const id = filenameWithoutExtension
const target = `styles/${id}.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)
})
......@@ -219,6 +236,7 @@ class HTMLEPUB {
}
get toc () {
const epub = this
return {
html: {
'@xmlns': 'http://www.w3.org/1999/xhtml',
......@@ -227,21 +245,30 @@ class HTMLEPUB {
meta: {
'@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: {
header: {
h1: 'Contents'
},
nav: {
'@epub:type': 'toc',
ol: {
li: this.xhtml.map(item => ({
'a': {
'@href': item.target,
'#text': item.title
}
}))
section: {
'@data-type': 'toc',
header: {
h1: 'Contents'
},
nav: {
'@epub:type': 'toc',
'@class': 'toc',
ol: {
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