diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 58acfe2..8966eb6 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -49,6 +49,9 @@ webpackConfig.forEach((c) => { })) } } + c.plugins.push(new webpack.DefinePlugin({ + FIMFIC2EPUB_VERSION: JSON.stringify(require('./package.json').version) + })) }) const wpCompiler = webpack(webpackConfig) diff --git a/package.json b/package.json index c80afec..657e9aa 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "standard": { "env": { "browser": true - } + }, + "globals": ["FIMFIC2EPUB_VERSION"] } } diff --git a/src/FimFic2Epub.js b/src/FimFic2Epub.js index 6217faf..b1a803f 100644 --- a/src/FimFic2Epub.js +++ b/src/FimFic2Epub.js @@ -36,14 +36,14 @@ module.exports = class FimFic2Epub { return sanitize(storyInfo.title + ' by ' + storyInfo.author.name + '.epub') } - static fetchStoryInfo (storyId) { + static fetchStoryInfo (storyId, raw = false) { return new Promise((resolve, reject) => { storyId = FimFic2Epub.getStoryId(storyId) let url = 'https://www.fimfiction.net/api/story.php?story=' + storyId - fetchRemote(url, (raw, type) => { + fetchRemote(url, (content, type) => { let data try { - data = JSON.parse(raw) + data = JSON.parse(content) } catch (e) {} if (!data) { reject('Unable to fetch story info') @@ -54,6 +54,10 @@ module.exports = class FimFic2Epub { return } let story = data.story + if (raw) { + resolve(story) + return + } // this is so the metadata can be cached. if (!story.chapters) story.chapters = [] delete story.likes @@ -64,7 +68,9 @@ module.exports = class FimFic2Epub { story.chapters.forEach((ch) => { delete ch.views }) - resolve(data.story) + // Add version number + story.FIMFIC2EPUB_VERSION = FIMFIC2EPUB_VERSION + resolve(story) }) }) } diff --git a/src/templates.js b/src/templates.js index 722cf9e..57167e1 100644 --- a/src/templates.js +++ b/src/templates.js @@ -116,10 +116,11 @@ export function createOpf (ffc) { m('dc:source', ffc.storyInfo.url), m('dc:language', 'en'), m('meta', {name: 'cover', content: 'cover'}), - m('meta', {property: 'dcterms:modified'}, new Date(ffc.storyInfo.date_modified * 1000).toISOString().replace('.000', '')) + m('meta', {property: 'dcterms:modified'}, new Date(ffc.storyInfo.date_modified * 1000).toISOString().replace('.000', '')), + m('dc:subject', 'Fimfiction') ].concat(ffc.categories.map((tag) => m('dc:subject', tag.name) - ))), + ), m('meta', {name: 'fimfic2epub version', content: FIMFIC2EPUB_VERSION}))), m('manifest', [ m('item', {id: 'ncx', href: 'toc.ncx', 'media-type': 'application/x-dtbncx+xml'}),