') + 23
let tagsHtml = html.substring(startTagsPos)
let endTagsPos = tagsHtml.indexOf('')
tagsHtml = tagsHtml.substring(0, endTagsPos)
let categories = []
let tags = []
tags.byImage = {}
this.subjects.length = 0
this.subjects.push('Fimfiction')
this.subjects.push(this.storyInfo.content_rating_text)
// sex, gore tags
let matchTag = /
(.*?)<\/a>/g
for (let c; (c = matchTag.exec(tagsHtml));) {
let cat = {
url: 'http://www.fimfiction.net' + c[1],
className: 'story_category story_category_' + c[2].replace('tag-', ''),
name: entities.decode(c[3])
}
categories.push(cat)
this.subjects.push(cat.name)
}
// genre tags
matchTag = /(.*?)<\/a>/g
for (let c; (c = matchTag.exec(tagsHtml));) {
let cat = {
url: 'http://www.fimfiction.net' + c[1],
className: 'story_category story_category_' + c[2],
name: entities.decode(c[3])
}
categories.push(cat)
this.subjects.push(cat.name)
}
// character tags
matchTag = /(.*?)<\/a>/g
for (let c; (c = matchTag.exec(tagsHtml));) {
let t = {
url: 'http://www.fimfiction.net' + c[1],
// filename: 'tag-' + c[2],
name: entities.decode(c[3])
// image: 'https://static.fimfiction.net/images/characters/' + entities.decode(c[2]).replace(/-/g, '_') + '.png'
}
tags.push(t)
// tags.byImage[t.image] = t
// this.remoteResources.set(t.image, {filename: t.filename, originalUrl: t.image, where: ['tags']})
}
this.categories = categories
html = html.substring(endTagsPos + 5)
html = html.substring(html.indexOf('') + 38)
let ma = html.match(/This story is a sequel to (.*?)<\/a>/)
if (ma) {
this.storyInfo.prequel = {
url: 'http://www.fimfiction.net' + ma[1],
title: entities.decode(ma[2])
}
html = html.substring(html.indexOf('
') + 6)
}
let endDescPos = html.indexOf('\n')
let description = html.substring(0, endDescPos).trim()
this.description = description
html = html.substring(endDescPos + 7)
let extraPos = html.indexOf('\n')
chapter = chapter.substring(0, pos).trim()
// remove leading and trailing
tags and whitespace
chapter = chapter.replace(trimWhitespace, '')
return {content: chapter, notes: authorNotes, notesFirst: authorNotesPos < chapterPos}
}
replaceRemoteResources () {
if (!this.options.includeExternal) {
this.remoteResources.forEach((r, url) => {
if (r.originalUrl && r.where) {
let ourl = new RegExp(escapeStringRegexp(r.originalUrl), 'g')
for (var i = 0; i < r.where.length; i++) {
let w = r.where[i]
if (typeof w === 'number') {
if (ourl.test(this.chapters[w])) {
this.storyInfo.chapters[w].remote = true
}
} else if (w === 'description') {
if (ourl.test(this.storyInfo.description)) {
this.hasRemoteResources.titlePage = true
}
} else if (w === 'tags') {
this.hasRemoteResources.titlePage = true
}
}
}
})
} else {
this.remoteResources.forEach((r, url) => {
let dest = '../' + r.dest
if (r.dest && r.originalUrl && r.where) {
let ourl = new RegExp(escapeStringRegexp(r.originalUrl), 'g')
for (var i = 0; i < r.where.length; i++) {
let w = r.where[i]
if (typeof w === 'object' && w.chapter !== undefined && this.chaptersHtml[w.chapter]) {
this.chaptersHtml[w.chapter] = this.chaptersHtml[w.chapter].replace(ourl, dest)
} else if (typeof w === 'object' && w.note !== undefined && this.notesHtml[w.note]) {
this.notesHtml[w.note] = this.notesHtml[w.note].replace(ourl, dest)
} else if (w === 'description') {
this.storyInfo.description = this.storyInfo.description.replace(ourl, dest)
} else if (w === 'tags') {
this.tags.byImage[r.originalUrl].image = dest
}
}
}
})
}
}
}
module.exports = FimFic2Epub