@jti/antora-extension-detect_assembler
v1.0.0
Published
An Antora extension that detects when the Antora Assembler is enabled so your UI can include links to the generated PDF.
Downloads
49
Maintainers
Readme
jti-antora-extension-repeated_words
An Antora extension that checks Asciidoc source files for repeated words in prose.
When the extension executes and detects Assembler, it adds the assemblerEnabled
attribute. The attribute definition is equivalent to:
asciidoc:
attributes:
assemblerEnabled: "yes"
Your Antora UI can find that attribute and compose a URL to an Assembler-generated PDF.
Here is a sample helper file:
'use strict'
const util = require('util')
let output = false
module.exports = (ctx) => {
if (output) {
output = false
console.log(
'ctx:',
util.inspect(ctx.data.root.page, {
showHidden: false,
depth: null,
maxArrayLength: null,
})
)
}
const { componentVersion } = ctx.data.root.page
if (
!componentVersion?.asciidoc?.attributes?.assemblerEnabled
) {
return false
}
const component = componentVersion.name
const version = componentVersion.version
const filename = componentVersion.title
.replace(/[&:]/g, '')
.replace(/[ ,/"']/g, '-')
.replace(/--/g, '-')
.toLowerCase() +
'.pdf'
const url = `${component}/${version}/${filename}`
return url
}
When the helper is called pdfLink.js
, a Handlebars template can do:
{{#if (pdfLink)}}
<div class="navbar-item hide-for-print">
<span class="control">
<a class="button is-primary" href="{{{siteRootPath}}}/{{{pdfLink}}}">Download PDF</a>
</span>
</div>
{{/if}}