update templates

This commit is contained in:
daniel-j 2018-03-12 22:09:08 +01:00
parent 7a95d40c77
commit a541a9f9d4

View file

@ -37,6 +37,8 @@ export function createChapter (ch) {
sections.reverse() sections.reverse()
} }
const tokenContent = '%%HTML_CONTENT_' + Math.random() + '%%'
return Promise.all([ return Promise.all([
render( render(
m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS}, [ m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS}, [
@ -45,23 +47,23 @@ export function createChapter (ch) {
m('link', {rel: 'stylesheet', type: 'text/css', href: '../Styles/style.css'}), m('link', {rel: 'stylesheet', type: 'text/css', href: '../Styles/style.css'}),
m('title', title) m('title', title)
]), ]),
m('body', [ m('body', {'epub:type': 'bodymatter chapter'}, m('section', [
title ? m('.chapter-title', [ title ? m('.chapter-title', [
m('h1', title), m('h1', title),
m('hr.old') m('hr.old')
]) : null, ]) : null,
'%%HTML_CONTENT%%', tokenContent,
(link || linkNotes) ? m('p.double', {style: 'text-align: center; clear: both;'}, (link || linkNotes) ? m('p.double', {style: 'text-align: center; clear: both;'},
link ? m('a.chaptercomments', {href: link + '#comment_list'}, 'Read chapter comments online') : null, link ? m('a.chaptercomments', {href: link + '#comment_list'}, 'Read chapter comments online') : null,
linkNotes ? m('a.chaptercomments', {href: linkNotes}, 'Read author\'s note') : null linkNotes ? m('a.chaptercomments', {href: linkNotes}, 'Read author\'s note') : null
) : null ) : null
]) ]))
]) ])
, {strict: true}), , {strict: true}),
render(sections) render(sections)
]).then(([chapterPage, sectionsData]) => { ]).then(([chapterPage, sectionsData]) => {
chapterPage = '<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html>\n' + pretty.xml(chapterPage) chapterPage = '<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html>\n' + chapterPage
chapterPage = chapterPage.replace('%%HTML_CONTENT%%', '\n' + sectionsData + '\n') chapterPage = chapterPage.replace(tokenContent, '\n' + sectionsData + '\n')
return chapterPage return chapterPage
}) })
} }
@ -149,7 +151,7 @@ export function createOpf (ffc) {
m('meta', {refines: '#cre', property: 'role', scheme: 'marc:relators'}, 'aut'), m('meta', {refines: '#cre', property: 'role', scheme: 'marc:relators'}, 'aut'),
m('dc:date', new Date((ffc.storyInfo.publishDate || ffc.storyInfo.date_modified) * 1000).toISOString().substring(0, 10)), m('dc:date', new Date((ffc.storyInfo.publishDate || ffc.storyInfo.date_modified) * 1000).toISOString().substring(0, 10)),
m('dc:publisher', 'Fimfiction'), m('dc:publisher', 'Fimfiction'),
m('dc:description', ffc.storyInfo.short_description), ffc.storyInfo.short_description ? m('dc:description', ffc.storyInfo.short_description) : null,
m('dc:source', ffc.storyInfo.url), m('dc:source', ffc.storyInfo.url),
m('dc:language', 'en'), m('dc:language', 'en'),
ffc.coverImage ? m('meta', {name: 'cover', content: 'cover'}) : null, ffc.coverImage ? m('meta', {name: 'cover', content: 'cover'}) : null,
@ -161,12 +163,15 @@ export function createOpf (ffc) {
m('manifest', [ m('manifest', [
ffc.coverImage ? m('item', {id: 'cover', href: ffc.coverFilename, 'media-type': ffc.coverType, properties: 'cover-image'}) : null, ffc.coverImage ? m('item', {id: 'cover', href: ffc.coverFilename, 'media-type': ffc.coverType, properties: 'cover-image'}) : null,
m('item', {id: 'ncx', href: 'toc.ncx', 'media-type': 'application/x-dtbncx+xml'}), m('item', {id: 'ncx', href: 'toc.ncx', 'media-type': 'application/x-dtbncx+xml'}),
m('item', {id: 'nav', 'href': 'Text/nav.xhtml', 'media-type': 'application/xhtml+xml', properties: 'nav'}), m('item', {id: 'nav', 'href': 'nav.xhtml', 'media-type': 'application/xhtml+xml', properties: 'nav'}),
ffc.options.includeAuthorNotes && ffc.options.useAuthorNotesIndex ? m('item', {id: 'notesnav', 'href': 'Text/notesnav.xhtml', 'media-type': 'application/xhtml+xml'}) : null, ffc.options.includeAuthorNotes && ffc.options.useAuthorNotesIndex && ffc.hasAuthorNotes ? m('item', {id: 'notesnav', 'href': 'notesnav.xhtml', 'media-type': 'application/xhtml+xml'}) : null,
m('item', {id: 'style', href: 'Styles/style.css', 'media-type': 'text/css'}), m('item', {id: 'style', href: 'Styles/style.css', 'media-type': 'text/css'}),
m('item', {id: 'coverstyle', href: 'Styles/coverstyle.css', 'media-type': 'text/css'}), m('item', {id: 'coverstyle', href: 'Styles/coverstyle.css', 'media-type': 'text/css'}),
m('item', {id: 'titlestyle', href: 'Styles/titlestyle.css', 'media-type': 'text/css'}), m('item', {id: 'titlestyle', href: 'Styles/titlestyle.css', 'media-type': 'text/css'}),
m('item', {id: 'navstyle', href: 'Styles/navstyle.css', 'media-type': 'text/css'}),
ffc.iconsFont ? m('item', {id: 'font-awesome', href: 'Fonts/fontawesome-webfont-subset.ttf', 'media-type': 'application/x-font-ttf'}) : null,
m('item', {id: 'coverpage', href: 'Text/cover.xhtml', 'media-type': 'application/xhtml+xml', properties: ffc.coverImage ? 'svg' : undefined}), m('item', {id: 'coverpage', href: 'Text/cover.xhtml', 'media-type': 'application/xhtml+xml', properties: ffc.coverImage ? 'svg' : undefined}),
m('item', {id: 'titlepage', href: 'Text/title.xhtml', 'media-type': 'application/xhtml+xml', properties: ffc.hasRemoteResources.titlePage ? 'remote-resources' : null}) m('item', {id: 'titlepage', href: 'Text/title.xhtml', 'media-type': 'application/xhtml+xml', properties: ffc.hasRemoteResources.titlePage ? 'remote-resources' : null})
@ -183,13 +188,13 @@ export function createOpf (ffc) {
))), ))),
m('guide', [ m('guide', [
m('reference', {type: 'cover', title: 'Cover', href: 'Text/cover.xhtml'}), m('reference', {type: 'cover', title: 'Cover', href: 'Text/cover.xhtml'}),
m('reference', {type: 'toc', title: 'Contents', href: 'Text/nav.xhtml'}) m('reference', {type: 'toc', title: 'Contents', href: 'nav.xhtml'})
]) ])
]) ])
, {strict: true}).then((contentOpf) => { , {strict: true}).then((contentOpf) => {
contentOpf = '<?xml version="1.0" encoding="utf-8"?>\n' + pretty.xml(contentOpf) contentOpf = '<?xml version="1.0" encoding="utf-8"?>\n' + pretty.xml(contentOpf)
return Buffer.from(contentOpf, 'utf8') return contentOpf
}) })
} }
function navPoints (list) { function navPoints (list) {
@ -214,61 +219,84 @@ export function createNcx (ffc) {
]), ]),
m('docTitle', m('text', ffc.storyInfo.title)), m('docTitle', m('text', ffc.storyInfo.title)),
m('navMap', navPoints([ m('navMap', navPoints([
['Cover', 'Text/cover.xhtml'] ['Cover', 'Text/cover.xhtml'],
['Title Page', 'Text/title.xhtml'],
['Contents', 'nav.xhtml']
].concat(ffc.storyInfo.chapters.map((ch, num) => ].concat(ffc.storyInfo.chapters.map((ch, num) =>
[ch.title, 'Text/chapter_' + zeroFill(3, num + 1) + '.xhtml'] [ch.title, 'Text/chapter_' + zeroFill(3, num + 1) + '.xhtml']
), ffc.options.includeAuthorNotes && ffc.options.useAuthorNotesIndex && ffc.hasAuthorNotes ? [['Author\'s Notes', 'Text/notesnav.xhtml']] : null))) ), ffc.options.includeAuthorNotes && ffc.options.useAuthorNotesIndex && ffc.hasAuthorNotes ? [['Author\'s Notes', 'notesnav.xhtml']] : null)))
]) ])
, {strict: true}).then((tocNcx) => { , {strict: true}).then((tocNcx) => {
tocNcx = '<?xml version="1.0" encoding="utf-8" ?>\n' + pretty.xml(tocNcx) tocNcx = '<?xml version="1.0" encoding="utf-8" ?>\n' + pretty.xml(tocNcx)
return Buffer.from(tocNcx, 'utf8') return tocNcx
}) })
} }
export function createNav (ffc, mode = 0) { export function createNav (ffc) {
let title, list let list = [
switch (mode) { m('li', {hidden: ''}, m('a', {href: 'Text/cover.xhtml'}, 'Cover')),
case 0: m('li', {hidden: ''}, m('a', {href: 'Text/title.xhtml'}, 'Title Page')),
title = 'Contents' ffc.storyInfo.chapters.length > 0 ? m('li', {hidden: ''}, m('a', {href: 'nav.xhtml'}, 'Contents')) : null
list = [m('li', {hidden: ''}, m('a', {href: 'cover.xhtml'}, 'Cover'))] ].concat(ffc.storyInfo.chapters.map((ch, num) =>
.concat(ffc.storyInfo.chapters.map((ch, num) => m('li', [
m('li', [ m('a.leftalign', {href: 'Text/chapter_' + zeroFill(3, num + 1) + '.xhtml'}, ch.title)
m('a.leftalign', {href: 'chapter_' + zeroFill(3, num + 1) + '.xhtml'}, ch.title) ])
// m('span.date', [m('b', ' · '), prettyDate(new Date(ch.date_modified * 1000)), m('span', {style: 'display: none'}, ' · ')]), ))
// m('.floatbox', m('span.wordcount', ch.realWordCount.toLocaleString('en-GB'))) let prettyList = ffc.storyInfo.chapters.map((ch, num) =>
]) m('.item', [
)) m('.floatbox', m('span.wordcount', ch.realWordCount.toLocaleString('en-GB'))),
if (ffc.options.includeAuthorNotes && ffc.options.useAuthorNotesIndex && ffc.hasAuthorNotes) { m('a.leftalign', {href: 'Text/chapter_' + zeroFill(3, num + 1) + '.xhtml'}, ch.title),
list.push(m('li', m('a.leftalign', {href: 'notesnav.xhtml'}, 'Author\'s Notes'))) m('span.date', [m('b', ' · '), prettyDate(new Date(ch.date_modified * 1000))])
} ])
break )
case 1: if (ffc.options.includeAuthorNotes && ffc.options.useAuthorNotesIndex && ffc.hasAuthorNotes) {
title = 'Author\'s Notes' list.push(m('li', m('a', {href: 'notesnav.xhtml'}, 'Author\'s Notes')))
list = ffc.chaptersWithNotes.map((num) => { prettyList.push(m('.item.double', m('a.leftalign', {href: 'notesnav.xhtml'}, 'Author\'s Notes')))
let ch = ffc.storyInfo.chapters[num]
return m('li', m('a.leftalign', {href: 'note_' + zeroFill(3, num + 1) + '.xhtml'}, ch.title))
})
break
} }
return render( return render(
m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS}, [ m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS}, [
m('head', [ m('head', [
m('meta', {charset: 'utf-8'}), m('meta', {charset: 'utf-8'}),
m('link', {rel: 'stylesheet', type: 'text/css', href: '../Styles/style.css'}), m('link', {rel: 'stylesheet', type: 'text/css', href: 'Styles/style.css'}),
m('title', title) m('link', {rel: 'stylesheet', type: 'text/css', href: 'Styles/navstyle.css'}),
m('title', 'Contents')
]), ]),
m('body#navpage', [ m('body', {'epub:type': 'frontmatter toc'}, m('section', [
m('nav#toc', mode === 0 ? {'epub:type': 'toc'} : null, [ m('h3', 'Contents'),
m('h3', title), m('#toc.hidden', prettyList),
m('ol', list) m('nav.invisible', {'epub:type': 'toc'}, m('ol', list))
]) ]))
])
]) ])
, {strict: true}).then((navDocument) => { , {strict: true}).then((navDocument) => {
navDocument = '<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html>\n' + pretty.xml(navDocument) navDocument = '<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html>\n' + pretty.xml(navDocument)
return Buffer.from(navDocument, 'utf8') return navDocument
})
}
export function createNotesNav (ffc) {
let list = ffc.chaptersWithNotes.map((num) => {
let ch = ffc.storyInfo.chapters[num]
return m('.item', m('a.leftalign', {href: 'Text/note_' + zeroFill(3, num + 1) + '.xhtml'}, ch.title))
}) })
return render(
m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS}, [
m('head', [
m('meta', {charset: 'utf-8'}),
m('link', {rel: 'stylesheet', type: 'text/css', href: 'Styles/style.css'}),
m('link', {rel: 'stylesheet', type: 'text/css', href: 'Styles/navstyle.css'}),
m('title', 'Author\'s Notes')
]),
m('body#navpage', {'epub:type': 'frontmatter toc'}, m('section', [
m('h3', 'Author\'s Notes'),
m('#toc', list)
]))
])
, {strict: true}).then((navDocument) => {
navDocument = '<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html>\n' + pretty.xml(navDocument)
return navDocument
})
} }
export function createCoverPage (ffc) { export function createCoverPage (ffc) {
@ -294,12 +322,12 @@ export function createCoverPage (ffc) {
m('title', 'Cover'), m('title', 'Cover'),
m('link', {rel: 'stylesheet', type: 'text/css', href: '../Styles/coverstyle.css'}) m('link', {rel: 'stylesheet', type: 'text/css', href: '../Styles/coverstyle.css'})
]), ]),
m('body', {'epub:type': 'cover'}, body) m('body#coverpage', {'epub:type': 'frontmatter cover'}, m('section', body))
]) ])
, {strict: true}).then((coverPage) => { , {strict: true}).then((coverPage) => {
coverPage = '<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html>\n' + pretty.xml(coverPage) coverPage = '<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html>\n' + pretty.xml(coverPage)
return Buffer.from(coverPage, 'utf8') return coverPage
}) })
} }
function infoBox (heading, data) { function infoBox (heading, data) {
@ -320,6 +348,15 @@ function calcWordCount (chapters) {
} }
export function createTitlePage (ffc) { export function createTitlePage (ffc) {
const tokenContent = '%%HTML_CONTENT_' + Math.random() + '%%'
const completedIcon = {
complete: 'check',
incomplete: 'pencil',
hiatus: 'pause',
cancelled: 'ban'
}
return render( return render(
m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS}, [ m('html', {xmlns: NS.XHTML, 'xmlns:epub': NS.OPS}, [
m('head', [ m('head', [
@ -328,43 +365,46 @@ export function createTitlePage (ffc) {
m('link', {rel: 'stylesheet', type: 'text/css', href: '../Styles/titlestyle.css'}), m('link', {rel: 'stylesheet', type: 'text/css', href: '../Styles/titlestyle.css'}),
m('title', ffc.storyInfo.title) m('title', ffc.storyInfo.title)
]), ]),
m('body#titlepage', [ m('body#titlepage', {'epub:type': 'frontmatter titlepage'}, m('section', [
m('.title', [ m('.title', [
m('div', {className: 'content-rating content-rating-' + ffc.storyInfo.content_rating_text.toLowerCase()}, ffc.storyInfo.content_rating_text.charAt(0).toUpperCase()),
m('.story_name', ffc.storyInfo.title + ' '), m('.story_name', ffc.storyInfo.title + ' '),
m('.author', ['by ', m('b', ffc.storyInfo.author.name)]) m('.author', ['by ', m('b', ffc.storyInfo.author.name)])
]), ]),
m('.readlink', m('a', {href: ffc.storyInfo.url}, 'Read on Fimfiction')),
// m('hr'), // m('hr'),
m('.categories', [ m('.tags', [
m('div', {className: 'content-rating-' + ffc.storyInfo.content_rating_text.toLowerCase()}, ffc.storyInfo.content_rating_text.charAt(0).toUpperCase()), ffc.tags.filter((tag) => tag.type !== 'character').map((tag) =>
ffc.categories.map((tag) => [m('div', {className: tag.className}, tag.name), ' ']
m('div', {className: tag.className}, tag.name)
) )
]), ]),
m('.readlink', m('a', {href: ffc.storyInfo.url}, 'Story on Fimfiction')),
m('br'),
// m('hr'), // m('hr'),
ffc.storyInfo.prequel ? [m('div', [ ffc.storyInfo.prequel ? [m('div', [
'This story is a sequel to ', 'This story is a sequel to ',
m('a', {href: ffc.storyInfo.prequel.url}, ffc.storyInfo.prequel.title) m('a', {href: ffc.storyInfo.prequel.url}, ffc.storyInfo.prequel.title)
]), m('hr')] : null, ]), m('hr')] : null,
m('#description', '%%HTML_CONTENT%%'), m('#description', tokenContent),
m('.bottom', [ m('.bottom', [
m('span', {className: 'completed-status-' + ffc.storyInfo.status.toLowerCase()}, ffc.storyInfo.status), m('div', {className: 'completed-status completed-status-' + ffc.storyInfo.status.toLowerCase()}, [
m('i.fa.fa-fw.fa-' + completedIcon[ffc.storyInfo.status.toLowerCase()]),
m('span', ffc.storyInfo.status)
]),
ffc.storyInfo.publishDate && infoBox('First Published', prettyDate(new Date(ffc.storyInfo.publishDate * 1000))), ffc.storyInfo.publishDate && infoBox('First Published', prettyDate(new Date(ffc.storyInfo.publishDate * 1000))),
infoBox('Last Modified', prettyDate(new Date(ffc.storyInfo.date_modified * 1000))), infoBox('Last Modified', prettyDate(new Date(ffc.storyInfo.date_modified * 1000))),
infoBox('Word Count', calcWordCount(ffc.storyInfo.chapters).toLocaleString('en-GB')) infoBox('Word Count', calcWordCount(ffc.storyInfo.chapters).toLocaleString('en-GB'))
]), ]),
// m('hr'), // m('hr'),
m('.characters', [ m('.tags', [
ffc.tags.map((t) => ffc.tags.filter((tag) => tag.type === 'character').map((tag) =>
// m('span', {className: 'character_icon', title: t.name}, m('img', {src: t.image, className: 'character_icon'})) [m('div', {className: tag.className}, tag.name), ' ']
m('span.story_character', t.name)
) )
]) ])
]) ]))
]) ])
, {strict: true}).then((titlePage) => { , {strict: true}).then((titlePage) => {
titlePage = '<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html>\n' + pretty.xml(titlePage) titlePage = '<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html>\n' + titlePage
titlePage = titlePage.replace('%%HTML_CONTENT%%', '\n' + ffc.storyInfo.description + '\n') titlePage = titlePage.replace(tokenContent, '\n' + ffc.storyInfo.description + '\n')
return Buffer.from(titlePage, 'utf8') return titlePage
}) })
} }