diff --git a/functions.js b/functions.js index e55233b..fa68f74 100644 --- a/functions.js +++ b/functions.js @@ -31,13 +31,19 @@ class Seance { */ } - async fetchFromMedium (mediumUrl) { + async fetchFromMedium (mediumUrl, options = { + json: null, + }) { console.info(`Fetching: ${mediumUrl}`); var output = path.join(process.env.PWD, 'content') var json - json = await this.fetchMediumJSON(mediumUrl) + if (!options.json) { + json = await this.fetchMediumJSON(mediumUrl) + } else { + json = options.json + } // use mediumexporter's getPost function to fetch a Medium post const post = await getPost(mediumUrl, { @@ -264,8 +270,10 @@ class Seance { mediumUrl= `${mediumUrl}?format=json` const response = await fetch(mediumUrl) text = await response.text() + } else if (fs.existsSync(mediumUrl)) { + text = fs.readFileSync(mediumUrl).toString() } else { - throw { error: 'URL must be a Medium URL' } + throw { error: 'URL must be a Medium URL or existing JSON file' } } json = await JSON.parse(text.substr(text.indexOf('{')))