wikizimmer.js output logic
This commit is contained in:
parent
8d51ba092d
commit
55d3ff5972
|
@ -918,9 +918,9 @@ ${data}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processSamplePage ( samplePageUrl ) {
|
async function processSamplePage ( sampleURLUrl ) {
|
||||||
const resp = await requestPromise({
|
const resp = await requestPromise({
|
||||||
url: encodeurl( samplePageUrl ),
|
url: encodeurl( sampleURLUrl ),
|
||||||
resolveWithFullResponse: true,
|
resolveWithFullResponse: true,
|
||||||
})
|
})
|
||||||
//~log(resp)
|
//~log(resp)
|
||||||
|
@ -929,9 +929,6 @@ async function processSamplePage ( samplePageUrl ) {
|
||||||
const realUrl = resp.request.href
|
const realUrl = resp.request.href
|
||||||
http = pooledRequest( requestPromise, realUrl )
|
http = pooledRequest( requestPromise, realUrl )
|
||||||
|
|
||||||
const purl = urlconv.parse( realUrl )
|
|
||||||
wiki.saveDir = sanitizeFN( purl.hostname )
|
|
||||||
|
|
||||||
const dom = cheerio.load( resp.body )
|
const dom = cheerio.load( resp.body )
|
||||||
|
|
||||||
// find out API entry URL
|
// find out API entry URL
|
||||||
|
@ -1253,32 +1250,35 @@ function closeMetadataStorage () {
|
||||||
return wiki.db.close()
|
return wiki.db.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initDir ( ) {
|
async function initDir ( sampleURL, outPath ) {
|
||||||
let oldDir
|
const purl = urlconv.parse( sampleURL )
|
||||||
|
|
||||||
|
wiki.saveDir = outPath || sanitizeFN( purl.hostname )
|
||||||
|
|
||||||
|
let done = true
|
||||||
if ( command.rmdir ) {
|
if ( command.rmdir ) {
|
||||||
oldDir = wiki.saveDir + '$'
|
const oldDir = wiki.saveDir + '$'
|
||||||
try {
|
try {
|
||||||
await fs.move( wiki.saveDir, oldDir, { overwrite: true })
|
await fs.move( wiki.saveDir, oldDir, { overwrite: true })
|
||||||
} catch ( err ) {
|
} catch ( err ) {
|
||||||
log( err )
|
log( 'initDir', err )
|
||||||
}
|
}
|
||||||
|
done = fs.remove( oldDir )
|
||||||
}
|
}
|
||||||
await fs.mkdirs( wiki.saveDir )
|
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 ) {
|
if ( command.userAgent ) {
|
||||||
UserAgent = command.userAgent == 'firefox' ? UserAgentFirefox : command.userAgent
|
UserAgent = command.userAgent == 'firefox' ? UserAgentFirefox : command.userAgent
|
||||||
}
|
}
|
||||||
log( 'UserAgent', UserAgent )
|
log( 'UserAgent', UserAgent )
|
||||||
try {
|
try {
|
||||||
await loadPreRequisites( )
|
const oldDir = await initDir( sampleURL, outPath )
|
||||||
|
|
||||||
const sampleDom = await processSamplePage( samplePage, command.rmdir )
|
|
||||||
|
|
||||||
const oldDir = await initDir()
|
|
||||||
|
|
||||||
|
await loadPreRequisites()
|
||||||
|
const sampleDom = await processSamplePage( sampleURL )
|
||||||
await initWikiDb()
|
await initWikiDb()
|
||||||
await loadCss( sampleDom )
|
await loadCss( sampleDom )
|
||||||
await getSiteInfo()
|
await getSiteInfo()
|
||||||
|
@ -1296,7 +1296,7 @@ async function core ( samplePage ) {
|
||||||
function main () {
|
function main () {
|
||||||
command
|
command
|
||||||
.version( packageInfo.version )
|
.version( packageInfo.version )
|
||||||
.arguments( '<wiki-page-URL>' )
|
.arguments( '<wiki-page-URL> [<output-path>]' )
|
||||||
.description( `Dump a static-HTML snapshot of a MediaWiki-powered wiki.
|
.description( `Dump a static-HTML snapshot of a MediaWiki-powered wiki.
|
||||||
|
|
||||||
Where:
|
Where:
|
||||||
|
@ -1329,7 +1329,7 @@ function main () {
|
||||||
|
|
||||||
log( command.opts() )
|
log( command.opts() )
|
||||||
|
|
||||||
core( command.args[0] )
|
core( ... command.args )
|
||||||
}
|
}
|
||||||
|
|
||||||
main ()
|
main ()
|
||||||
|
|
|
@ -1589,7 +1589,7 @@ async function main () {
|
||||||
|
|
||||||
argv
|
argv
|
||||||
.version( packageInfo.version )
|
.version( packageInfo.version )
|
||||||
.arguments( '<source-directory> [zim-file...]' )
|
.arguments( '<source-directory> [<output-file>]' )
|
||||||
.description( `Pack a directory into a zim file
|
.description( `Pack a directory into a zim file
|
||||||
|
|
||||||
Where:
|
Where:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user