In the previous post we checked on how to create custom asciidoc container - in my case I wanted to add custom fonts without having to mount them into the container.

The usage was a bit too limited. Passing custom attributes (--atttribute) in the e.g. asciidoc-pdf wasn’t really nice sinc then you would need to know the location of the custom fonts inside the container.

In order to solve that, I tweaked the container a bit:

FROM asciidoctor/docker-asciidoctor
RUN mkdir /usr/share/fonts/redhat
RUN apk add --no-cache ttf-liberation
COPY redhat-fonts/TTF/* /usr/share/fonts/redhat/
RUN fc-cache -f -v

CMD asciidoctor-pdf --attribute pdf-fontsdir="/usr/share/fonts/ttf-liberation;/usr/share/fonts/redhat;GEM_FONTS_DIR" $CUSTOM_ATTR /documents/$ADOC_FILE

We see a few changes:

  1. we provide a fonts dir which makes use of the GEM_FONTS_DIR token. This way I don’t need to know where the gems, specifically the fonts, are installed and can just use something like the following in the them (as opposed to full paths)

    Noto Serif:
      normal: notoserif-regular-subset.ttf
      bold: notoserif-bold-subset.ttf
      italic: notoserif-italic-subset.ttf
      bold_italic: notoserif-bold_italic-subset.ttf
    1. $ADOC_FILE - apparently an environment variable you now have to pass.

    2. $CUSTOM_ATTR - this env variable can be left empty.

    Why would you need these changes? Well, two things: you don’t need to know where the fonts are located anymore when writing your theme and also supporting advanced use cases where you want to have additional attributes. And all this while still having an easy to use container image if you want to.

    Simple usage:

    podman run -v $(pwd):/documents:Z -e ADOC_FILE=foobar.adoc <container image>

Advanced usage (e.g. where you specify the date of your doc using the last git commit date):

podman run -v $(pwd):/documents:Z -e ADOC_FILE=foobar.adoc -e CUSTOM_ATTR="--attribute gitdate=$(git log -1 --date=short --pretty=format:%cd)" <container image>