@antora/pdf-extension
Advanced tools
Comparing version 1.0.0-alpha.7 to 1.0.0-alpha.8
'use strict' | ||
const { runCommand } = (() => { | ||
try { | ||
return require('@antora/assembler') | ||
} catch { | ||
return require('../../assembler') | ||
} | ||
})() | ||
const fsp = require('node:fs/promises') | ||
const ospath = require('node:path') | ||
@@ -14,14 +8,15 @@ | ||
// Q: rename to convertDocumentToPDF? | ||
function convertDocumentToPdf (doc, buildConfig) { | ||
async function convertDocumentToPdf (doc, buildConfig, runCommand) { | ||
const { | ||
asciidoc: { attributes: baseAttributes } = { attributes: {} }, | ||
contents: input, | ||
src: { component, version, basename, extname: docfilesuffix }, | ||
src: { component, version, basename, extname = doc.extname }, | ||
} = doc | ||
const { command = 'asciidoctor-pdf', cwd, dir } = buildConfig | ||
const { cwd = process.cwd(), dir = cwd } = buildConfig | ||
const command = buildConfig.command ?? (await scopeDefaultCommand(cwd)) | ||
const docfile = `${version}@${component}::pdf$${basename}` | ||
const docname = basename.substr(0, basename.length - docfilesuffix.length) | ||
const docname = basename.slice(0, basename.length - extname.length) | ||
const convertAttributes = Object.assign({}, baseAttributes, { | ||
docfile, | ||
docfilesuffix, | ||
docfilesuffix: extname, | ||
'docname@': docname, | ||
@@ -37,2 +32,4 @@ imagesdir: dir, | ||
const output = ospath.join(dir, doc.path) | ||
// Q: should mkdirs be the default behavior? | ||
if (buildConfig.mkdirs) await fsp.mkdir(ospath.dirname(output), { recursive: true, force: true }) | ||
argv.push('-o', output) | ||
@@ -45,2 +42,9 @@ // Q: should runCommand accept outputFlag and automatically append to argv? | ||
function scopeDefaultCommand (cwd, baseCommand = 'asciidoctor-pdf') { | ||
return fsp.stat(ospath.join(cwd, 'Gemfile.lock')).then( | ||
() => `bundle exec ${baseCommand}`, | ||
() => baseCommand | ||
) | ||
} | ||
module.exports = convertDocumentToPdf |
'use strict' | ||
const convertDocumentToPdf = require('./convert-document-to-pdf') | ||
const { assembleContent } = (() => { | ||
try { | ||
return require('@antora/assembler') | ||
} catch { | ||
return require('../../assembler') | ||
} | ||
})() | ||
module.exports.register = function () { | ||
this.on('contentClassified', ({ contentCatalog }) => { | ||
contentCatalog.getPages((page) => { | ||
if (!page.out) return | ||
page.src.contents = page.contents | ||
page.src = new Proxy(page.src, { deleteProperty: (o, p) => (p === 'contents' ? true : delete o[p]) }) | ||
}) | ||
this.once('beforeProcess', ({ siteAsciiDocConfig }) => { | ||
siteAsciiDocConfig.keepSource = true | ||
}) | ||
this.on('beforePublish', ({ playbook, contentCatalog, siteCatalog }) => | ||
assembleContent.call(this, playbook, contentCatalog, convertDocumentToPdf, { siteCatalog }) | ||
) | ||
this.once('beforePublish', ({ playbook, contentCatalog, siteCatalog }) => { | ||
const { assembleContent } = this.require('@antora/assembler') | ||
return assembleContent.call(this, playbook, contentCatalog, convertDocumentToPdf, { siteCatalog }) | ||
}) | ||
} |
{ | ||
"name": "@antora/pdf-extension", | ||
"version": "1.0.0-alpha.7", | ||
"version": "1.0.0-alpha.8", | ||
"description": "An Antora extension that assembles content pages into PDF files by version and publishes them with the site.", | ||
@@ -17,4 +17,5 @@ "license": "MPL-2.0", | ||
"scripts": { | ||
"prepublishOnly": "node $npm_config_local_prefix/npm/prepublishOnly.js", | ||
"postpublish": "node $npm_config_local_prefix/npm/postpublish.js" | ||
"test": "_mocha test", | ||
"prepublishOnly": "npx -y downdoc --prepublish", | ||
"postpublish": "npx -y downdoc --postpublish" | ||
}, | ||
@@ -25,4 +26,7 @@ "main": "lib/index.js", | ||
}, | ||
"imports": { | ||
"#convert-document-to-pdf": "./lib/convert-document-to-pdf.js" | ||
}, | ||
"dependencies": { | ||
"@antora/assembler": "1.0.0-alpha.7" | ||
"@antora/assembler": "1.0.0-alpha.8" | ||
}, | ||
@@ -29,0 +33,0 @@ "engines": { |
@@ -24,3 +24,3 @@ # Antora PDF Extension | ||
You can configure the behavior of the extension using the optional *antora-assembler.yml* file. | ||
You can configure the behavior of the extension using the optional _antora-assembler.yml_ file. | ||
@@ -27,0 +27,0 @@ ## Copyright and License |
4670
54
+ Added@antora/assembler@1.0.0-alpha.8(transitive)
- Removed@antora/assembler@1.0.0-alpha.7(transitive)