Allow to promote non-prefixed attributes into page attributes
Original discussion: #355 (closed)
I think it would be useful to introduce a map of non-prefixed attributes that would be automatically promoted into the page attributes map.
Maybe we could define something like this in the playbook (or eventually the component descriptor):
asciidoc:
extra_page_attributes: [author, copyright, product-name]
Another way to solve this (using code) would be to execute Asciidoctor extensions (and more specifically TreeProcessor
extensions) before page attributes are extracted from the Document
:
const EXTRA_PAGE_ATTRIBUTES: ['author', 'copyright', 'product-name']
module.exports = function (registry) {
registry.treeProcessor(function () {
var self = this
self.process(function (doc) {
for (const extraPageAttribute of EXTRA_PAGE_ATTRIBUTES) {
doc.setAttribute(`page-${extraPageAttribute}`, doc.getAttribute(extraPageAttribute))
}
return doc
})
})
}
To give you some context about my specific use case, I'm using Antora in a single-source publishing context where Antora is one of the publishing platform (but not the only one).
As such, I have existing documents with generic attributes used by the different publishing platforms.
For instance:
= A demonstration of causal cluster routing
:slug: a-demonstration-of-causal-cluster-routing
:author: Dana Canzano
:category: cluster
:tags: causal-cluster, routing, cypher-shell
:neo4j-versions: 3.2
If I want to "promote" the category
, the tags
or the neo4j-versions
attributes as page attributes in Antora, I would need to add the following in every documents (a few hundreds):
= A demonstration of causal cluster routing
:slug: a-demonstration-of-causal-cluster-routing
:author: Dana Canzano
:category: cluster
:tags: causal-cluster, routing, cypher-shell
:neo4j-versions: 3.2
// export as Antora page attributes
:page-category: {category}
:page-tags: {tags}
:page-neo4j-versions: {neo4j-versions}
As you can see, the above is a bit tedious but also error-prone.