diff --git a/wikizimmer.js b/wikizimmer.js index db5a9d2..21b000b 100755 --- a/wikizimmer.js +++ b/wikizimmer.js @@ -918,9 +918,9 @@ ${data} } } -async function processSamplePage ( samplePageUrl ) { +async function processSamplePage ( sampleURLUrl ) { const resp = await requestPromise({ - url: encodeurl( samplePageUrl ), + url: encodeurl( sampleURLUrl ), resolveWithFullResponse: true, }) //~log(resp) @@ -929,9 +929,6 @@ async function processSamplePage ( samplePageUrl ) { const realUrl = resp.request.href http = pooledRequest( requestPromise, realUrl ) - const purl = urlconv.parse( realUrl ) - wiki.saveDir = sanitizeFN( purl.hostname ) - const dom = cheerio.load( resp.body ) // find out API entry URL @@ -1253,32 +1250,35 @@ function closeMetadataStorage () { return wiki.db.close() } -async function initDir ( ) { - let oldDir +async function initDir ( sampleURL, outPath ) { + const purl = urlconv.parse( sampleURL ) + + wiki.saveDir = outPath || sanitizeFN( purl.hostname ) + + let done = true if ( command.rmdir ) { - oldDir = wiki.saveDir + '$' + const oldDir = wiki.saveDir + '$' try { await fs.move( wiki.saveDir, oldDir, { overwrite: true }) } catch ( err ) { - log( err ) + log( 'initDir', err ) } + done = fs.remove( oldDir ) } await fs.mkdirs( wiki.saveDir ) - return { done: command.rmdir ? fs.remove( oldDir ) : true } + return { done } } -async function core ( samplePage ) { +async function core ( sampleURL, outPath ) { if ( command.userAgent ) { UserAgent = command.userAgent == 'firefox' ? UserAgentFirefox : command.userAgent } log( 'UserAgent', UserAgent ) try { - await loadPreRequisites( ) - - const sampleDom = await processSamplePage( samplePage, command.rmdir ) - - const oldDir = await initDir() + const oldDir = await initDir( sampleURL, outPath ) + await loadPreRequisites() + const sampleDom = await processSamplePage( sampleURL ) await initWikiDb() await loadCss( sampleDom ) await getSiteInfo() @@ -1296,7 +1296,7 @@ async function core ( samplePage ) { function main () { command .version( packageInfo.version ) - .arguments( '' ) + .arguments( ' []' ) .description( `Dump a static-HTML snapshot of a MediaWiki-powered wiki. Where: @@ -1329,7 +1329,7 @@ function main () { log( command.opts() ) - core( command.args[0] ) + core( ... command.args ) } main () diff --git a/zimmer.js b/zimmer.js index 01f9ca6..6090df7 100755 --- a/zimmer.js +++ b/zimmer.js @@ -1589,7 +1589,7 @@ async function main () { argv .version( packageInfo.version ) - .arguments( ' [zim-file...]' ) + .arguments( ' []' ) .description( `Pack a directory into a zim file Where: