Awesome Asciidoctor: Adding Custom Content to Head and Footer
When we convert our Asciidoctor markup to HTML we automatically get a head
and footer element. We can add custom content to the HTML head
element and to the HTML div
with id footer. We must set a document attribute and create the files that contain the HTML that needs to be added to the head or footer. We have three different document attributes we can set to include the custom content files:
:docinfo:
include document specific content. Files to be included must be named<docname>-docinfo.html
forhead
element and<docname>-docinfo-footer.html
for footer content.:docinfo1:
include general custom content. Files to be included must be nameddocinfo.htmtl
forhead
element anddocinfo-footer.html
for footer content.:docinfo2:
include document specific and general custom content. Files to be included must be named<docname>-docinfo.html
anddocinfo.html
forhead
element and<docname>-docinfo-footer.html
anddocinfo-footer.html
for footer content.
In this sample we create the files docinfo.html
and docinfo-footer.html
we want to include in the generated output from the following Asciidoctor source file:
= Asciidoctor custom header and footer
Hubert A. Klein Ikkink
// Document specific and general custom
// content files are used:
:docinfo2:
// Include general custom content files:
//:docinfo1:
// Include document specific content files:
//:docinfo:
// In generated HTML this is transformed
// to meta element with name description.
:description: Sample document with custom header and footer parts.
// In generated HMTL this is transformed
// into meta element with name keywords.
:keywords: Asciidoctor, header, footer, docinfo
Using the `docinfo` attributes we can include custom content
in the header and footer. Contents of the files
named `docinfo.html` and `docinfo-footer.html` are included.
We can choose between general or document specific custom
header and footer content.
Our `docinfo.html` looks like this:
/* Change CSS overflow for table of contents. */
#toc.toc2, #toc { overflow: scroll; }
/* Change styling for footer text. */
.footer-text { color: rgba(255,255,255,.8); }
For the custom footer we create the file docinfo-footer.html
:
Generated with Asciidoctor v{asciidoctor-version}.
The following screenshot shows the generated HTML page:
And here is part of the generated head
element:
...
/* Change CSS overflow for table of contents. */
#toc.toc2, #toc { overflow: scroll; }
/* Change styling for footer text. */
.footer-text { color: rgba(255,255,255,.8); }
Written with Asciidoctor 1.5.2.