@jti/antora-extension-detect_assembler

1.0.0 • Public • Published

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}}

Dependencies (3)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @jti/antora-extension-detect_assembler

    Weekly Downloads

    14

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    7.25 kB

    Total Files

    10

    Last publish

    Collaborators

    • jtiee