<?xml version="1.0" encoding="UTF-8"?>
  <rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
    <channel>
      <title><![CDATA[Blog - Yuzu tech]]></title>
      <description><![CDATA[Yuzu tech technical blog]]></description>
      <link>https://blog.yuzutech.fr</link>
      <image>
        <url>https://blog.yuzutech.fr/favicon.ico</url>
        <title>Blog - Yuzu tech</title>
        <link>https://blog.yuzutech.fr</link>
      </image>
      <generator>Antora 3.0.0-rc.2</generator>
      <lastBuildDate>Mon, 27 Dec 2021 11:19:29 GMT</lastBuildDate>
      <atom:link href="https://blog.yuzutech.fr/rss/feed.xml" rel="self" type="application/rss+xml"/>
      <ttl>60</ttl>
      <item>
    <title><![CDATA[Awesome Antora: Add icons to admonition labels]]></title>
    <description><![CDATA[You are using Antora's default UI and you want to add icons next to the admonition labels, look no further!]]></description>
    <link>undefined</link>
    <category><![CDATA[Antora]]></category>
<category><![CDATA[Font Awesome]]></category>
    <dc:creator><![CDATA[Guillaume Grossetie]]></dc:creator>
    <pubDate>Tue, 05 Mar 2019 11:25:00 GMT</pubDate>
    <media:content url="https://blog.yuzutech.fr/_/images/come.jpeg" medium="image"/>
    <content:encoded><![CDATA[<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
  
  <p>Admonitions are a great way to draw the reader&#8217;s attention to auxiliary information.
Asciidoctor provides five admonition style labels:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>NOTE</p>
</li>
<li>
<p>TIP</p>
</li>
<li>
<p>IMPORTANT</p>
</li>
<li>
<p>CAUTION</p>
</li>
<li>
<p>WARNING</p>
</li>
</ul>
</div>
<div class="paragraph">
  
  <p>If you are familiar with Asciidoctor, you probably know that you can enable font-based icons using <code>:icons: font</code>.
When you do that, Asciidoctor will draw an icon for the built-in admonition labels.
And here&#8217;s the result with the default stylesheet:</p>
</div>
<div class="imageblock text-center">
<div class="content">
<img src="../_images/asciidoctor-default-admonition.png" alt="asciidoctor default admonition">
</div>
</div>
<div class="paragraph">
  
  <p>It might come as a surprise, but the Antora&#8217;s default UI uses its own stylesheet and does not include an icon font.
So, using <code>:icons: font</code> will not produce the desired affect:</p>
</div>
<div class="imageblock text-center">
<div class="content">
<img src="../_images/antora-default-admonition.png" alt="antora default admonition">
</div>
</div>
<div class="paragraph">
  
  <p>Luckily, with a few lines of CSS, we can add the icons back to the admonitions labels.</p>
</div>
</div>
</div>
<section class="section is-small">
<h2 class="title is-4">Supplemental files</h2>
<div class="paragraph">
  
  <p>Antora provides a feature called "supplemental files" to <em>supercharge</em> the UI.
As you can see below, we can define a key named <code>supplemental_files</code> that points to a directory named <em class="path">supplemental-ui</em>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-yml" data-lang=yml>ui:
  bundle:
    url: 'https://gitlab.com/antora/antora-ui-default/-/jobs/artifacts/master/raw/build/ui-bundle.zip?job=bundle-stable'
    snapshot: true
  supplemental_files: './supplemental-ui'</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>In this directory we will create a CSS file:</p>
</div>
<div class="listingblock">
<div class="listing-title">supplemental-ui/css/extra.css</div>
<div class="content">
<pre class="nowrap"><code class="language-css" data-lang=css>.doc .admonitionblock .icon {
    border-radius: 1rem;
}

i.fa[class^='icon-'],
i.fa[class*=' icon-']::before {
    content: "";
    height: 1.25rem;
    width: 1.25rem;
    margin-right: 0.25rem;
    margin-left: -0.5rem;
}

i.fa.icon-note::before {
    background: no-repeat url("../img/note.svg");
}

i.fa.icon-tip::before {
    background: no-repeat url("../img/tip.svg");
}

i.fa.icon-important::before {
    background: no-repeat url("../img/important.svg");
}

i.fa.icon-warning::before {
    background: no-repeat url("../img/warning.svg");
}

i.fa.icon-caution::before {
    background: no-repeat url("../img/caution.svg");
}</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Then, create a directory named <em class="path">img</em> in the <em class="path">supplemental-ui</em> directory and add the following SVG icons:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="../_attachments/note.svg" target="_blank" rel="noopener">note.svg</a></p>
</li>
<li>
<p><a href="../_attachments/tip.svg" target="_blank" rel="noopener">tip.svg</a></p>
</li>
<li>
<p><a href="../_attachments/important.svg" target="_blank" rel="noopener">important.svg</a></p>
</li>
<li>
<p><a href="../_attachments/warning.svg" target="_blank" rel="noopener">warning.svg</a></p>
</li>
<li>
<p><a href="../_attachments/caution.svg" target="_blank" rel="noopener">caution.svg</a></p>
</li>
</ul>
</div>
<div class="box note">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-note">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        The above icons were created using <a href="https://fontawesome.com/icons">Font Awesome 5 icons</a>.
      </div>
    </div>
  </article>
</div>
<div class="paragraph">
  
  <p>The circular background behind the icons is black with transparency so you can change the background colour of the admonitions without having to update the SVG files.
Thanks to <a href="https://github.com/streetster">@streetster</a> for the idea!</p>
</div>
<div class="paragraph">
  
  <p>Now, we need to reference this new <em class="path">extra.css</em> file in the <code>&lt;head&gt;</code> of our documentation site by creating a template named <em class="path">head-meta.hbs</em> in a <em class="path">partials</em> directory:</p>
</div>
<div class="listingblock">
<div class="listing-title">supplemental-ui/partials/head-meta.hbs</div>
<div class="content">
<pre class="nowrap"><code class="language-html" data-lang=html>    &lt;link rel="stylesheet" href="{{uiRootPath}}/css/extra.css"&gt;</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>To sum up, your <em class="path">supplemental-ui</em> directory should contain the following files and directories:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-tree" data-lang=tree>supplemental-ui
├── css
│   └── extra.css
├── img
│   ├── caution.svg
│   ├── important.svg
│   ├── note.svg
│   ├── tip.svg
│   └── warning.svg
└── partials
    └── head-meta.hbs

3 directories, 7 file</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>And here&#8217;s the result:</p>
</div>
<div class="imageblock text-center">
<div class="content">
<img src="../_images/antora-icon-admonition.png" alt="antora icon admonition">
</div>
</div>
<div class="paragraph">
  
  <p>Since we are using a background with transparency, we can use alternative colors:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-css" data-lang=css>.doc .admonitionblock.note .icon {
    background-color: #795548;
}

.doc .admonitionblock.tip .icon {
    background-color: #607D8B;
}

.doc .admonitionblock.important .icon {
    background-color: #E91E63;
}

.doc .admonitionblock.warning .icon {
    background-color: #FF7043;
}

.doc .admonitionblock.caution .icon {
    background-color: #673AB7;
}</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>And here&#8217;s the result:</p>
</div>
<div class="imageblock text-center">
<div class="content">
<img src="../_images/antora-alternative-admonition-colors.png" alt="antora alternative admonition colors">
</div>
</div>
<div class="paragraph">
  
  <p>Here, we&#8217;ve demonstrated how to add icons next to the admonition labels but you can virtually <strong>override the style of any elements</strong> by adding CSS rules 🎨</p>
</div>
</section>]]></content:encoded>
  </item>
<item>
    <title><![CDATA[Awesome Asciidoctor.js: Find broken links in your documentation]]></title>
    <description><![CDATA[Don't let your documentation be filled with broken links. Learn how to use Asciidoctor.js to find them.]]></description>
    <link>undefined</link>
    <category><![CDATA[Asciidoctor.js]]></category>
<category><![CDATA[JavaScript]]></category>
    <dc:creator><![CDATA[Guillaume Grossetie]]></dc:creator>
    <pubDate>Fri, 18 Jan 2019 16:40:00 GMT</pubDate>
    <media:content url="https://blog.yuzutech.fr/_/images/catalog-links.jpg" medium="image"/>
    <content:encoded><![CDATA[<div class="paragraph">
  
  <p>One of the most frustrating experiences for a reader is broken links.
Using a <a href="https://opendevise.com/blog/referencing-pages/">good site generator</a> can help but what about external links ?<br>
How do you make sure that all the external links in your documentation still work ?</p>
</div>
<div class="paragraph">
  
  <p>With Asciidoctor.js, you can enable a catalog using the <code>catalog_assets</code> option.
Once this option is enabled, the processor will capture every links found in your document, and store them in the catalog.<br>
For reference, the parser will also capture footnotes, images, index terms, cross-references and ids. But let&#8217;s focus on links for now.</p>
</div>
<div class="paragraph">
  
  <p>Here&#8217;s an example where <code>catalog_assets</code> is enabled:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="11,12,13"><code class="language-js" data-lang=js>const input = `
* link:subdir/foo.pdf[]
* link:subdir/bar.pdf[]
* link:quz.pdf[]
* https://antoraa.org
* https://asciidoctor.org
* https://yuzutech.fr
* https://asciidoctor.org/doc
* http://neverssl.com`

const doc = asciidoctor.load(input, { 'catalog_assets': true }) <i class="conum" data-value="1"></i>
doc.convert() <i class="conum" data-value="2"></i>
const linksCatalog = doc.getLinks() <i class="conum" data-value="3"></i>
console.log(linksCatalog) // [ 'subdir/foo.pdf', 'subdir/bar.pdf', ... ]</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>Enable the <code>catalog_assets</code> option</td>
          </tr>
<tr>
          <td><i class="conum" data-value="2"></i><b>2</b></td>
          <td>Convert the document because links will only be available after the document has been converted</td>
          </tr>
<tr>
          <td><i class="conum" data-value="3"></i><b>3</b></td>
          <td>Return an <code>Array</code> of links found in the document</td>
          </tr>
</table>
</div>
<div class="paragraph">
  
  <p>Now that we have all the links present in our document, we can make sure that every one of them is still working.<br>
To do that we should probably use a library but here&#8217;s a naive implementation to give you an idea.</p>
</div>
<div class="paragraph">
  
  <p>Here, we are using the <code>http</code> and <code>https</code> module from Node.js to make sure that the server does not return a <code>4xx</code> or <code>5xx</code> errors for the URL:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="8,13,16"><code class="language-js" data-lang=js>const https = require('https')
const http = require('http')

const checkHttpLink = link =&gt; new Promise(resolve =&gt; {
  const module = link.startsWith('https://') ? https : http
  module.get(link, res =&gt; {
    const isError = res.statusCode &gt;= 400 &amp;&amp; res.statusCode &lt; 600
    if (isError) { <i class="conum" data-value="1"></i>
      resolve({
        error: true,
        message: `Found a broken link: ${link} - Status code is: ${res.statusCode}`
      })
    } else { <i class="conum" data-value="2"></i>
      resolve({ error: false })
    }
  }).on('error', e =&gt; resolve({ <i class="conum" data-value="3"></i>
    error: true,
    message: `Found a broken link: ${link} - ${e}`
  }))
})</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>The server returns an error code <code>4xx</code> or <code>5xx</code></td>
          </tr>
<tr>
          <td><i class="conum" data-value="2"></i><b>2</b></td>
          <td>The status code is (considered) valid</td>
          </tr>
<tr>
          <td><i class="conum" data-value="3"></i><b>3</b></td>
          <td>The client returns an error (most likely because the server is nonexistent)</td>
          </tr>
</table>
</div>
<div class="box note">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-note">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>We are not using <code>reject</code> because we want all the promises to be resolved (ie. we don&#8217;t want to stop at the first failure).</p>
</div>
      </div>
    </div>
  </article>
</div>
<div class="paragraph">
  
  <p>We also define a function to check if a file exists:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="4"><code class="language-js" data-lang=js>const util = require('util')
const stat = util.promisify(require('fs').stat)

const checkFileLink = path =&gt; stat(path) <i class="conum" data-value="1"></i>
  .catch(error =&gt; ({
    error: true,
    message: `Found a broken link: ${path} - ${error.toString()}`
  }))</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>Use <a href="https://nodejs.org/api/fs.html#fs_fs_stat_path_options_callback"><code>stat</code></a> to make sure that the file exists</td>
          </tr>
</table>
</div>
<div class="paragraph">
  
  <p>And finally, we iterate on each link:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="5,7,10,13,15,24,29"><code class="language-js" data-lang=js>const ospath = require('path')
const url = require('url')

const promises = linksCatalog.map((link) =&gt; {
  const uri = url.parse(link) <i class="conum" data-value="1"></i>
  if (uri.protocol === 'https:' || uri.protocol === 'http:') {
    return checkHttpLink(link) <i class="conum" data-value="2"></i>
  }
  if (uri.protocol === 'file:') {
    return checkFileLink(ospath.normalize(`${uri.host}${uri.path}`)) <i class="conum" data-value="3"></i>
  }
  if (uri.protocol === null) {
    return checkFileLink(link) <i class="conum" data-value="4"></i>
  }
  return Promise.resolve({ <i class="conum" data-value="5"></i>
    error: true,
    message: `Unsupported protocol ${uri.protocol}. Unable to check the ${link}.`
  })
})

Promise.all(promises)
  .then((result) =&gt; {
    const errors = result.filter(item =&gt; item.error === true)
    if (errors.length &gt; 0) { <i class="conum" data-value="6"></i>
      errors.forEach(error =&gt; {
        console.log(error.message)
      })
      // abort the mission!
      process.exit(1) <i class="conum" data-value="7"></i>
    } else {
      // all good...
    }
  })</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>Parse the link</td>
          </tr>
<tr>
          <td><i class="conum" data-value="2"></i><b>2</b></td>
          <td>If the protocol is <code>http:</code> or <code>http:</code>, use the <code>checkHttpLink</code> function</td>
          </tr>
<tr>
          <td><i class="conum" data-value="3"></i><b>3</b></td>
          <td>If the protocol is <code>file:</code>, normalize the path and use the <code>checkFileLink</code> function</td>
          </tr>
<tr>
          <td><i class="conum" data-value="4"></i><b>4</b></td>
          <td>If the protocol is <code>undefined</code>, use the <code>checkFileLink</code> function</td>
          </tr>
<tr>
          <td><i class="conum" data-value="5"></i><b>5</b></td>
          <td>If the protocol is unsupported, return an error</td>
          </tr>
<tr>
          <td><i class="conum" data-value="6"></i><b>6</b></td>
          <td>Check if there&#8217;s one or more errors</td>
          </tr>
<tr>
          <td><i class="conum" data-value="7"></i><b>7</b></td>
          <td>Exit the program with the return code 1</td>
          </tr>
</table>
</div>
<div class="paragraph">
  
  <p>And here&#8217;s the output of this program:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code>Found a broken link: subdir/bar.pdf - Error: ENOENT: no such file or directory, stat 'subdir/bar.pdf'
Found a broken link: quz.pdf - Error: ENOENT: no such file or directory, stat 'quz.pdf'
Found a broken link: https://antoraa.org - Error: getaddrinfo ENOTFOUND antoraa.org antoraa.org:443
Found a broken link: https://asciidoctor.org/doc - Status code is: 404</code></pre>
</div>
</div>]]></content:encoded>
  </item>
<item>
    <title><![CDATA[Awesome Asciidoctor.js: Server Side Rendering with Font Awesome 5]]></title>
    <description><![CDATA[Server Side Rendering is great for static sites. With the introduction of SVG's to Font Awesome we can now render icons on the server. Discover how to use the new Font Awesome JavaScript API in Asciidoctor.js.]]></description>
    <link>undefined</link>
    <category><![CDATA[Asciidoctor.js]]></category>
<category><![CDATA[Converter]]></category>
<category><![CDATA[Font Awesome]]></category>
<category><![CDATA[JavaScript]]></category>
    <dc:creator><![CDATA[Guillaume Grossetie]]></dc:creator>
    <pubDate>Thu, 13 Dec 2018 20:00:00 GMT</pubDate>
    <media:content url="https://blog.yuzutech.fr/_/images/fontawesome.jpg" medium="image"/>
    <content:encoded><![CDATA[<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
  
  <p>With <a href="https://fontawesome.com/">Font Awesome 5</a> icons can be rendered as SVG elements using JavaScript.
This implementation includes an API that can be used to do <a href="https://fontawesome.com/how-to-use/on-the-web/other-topics/server-side-rendering">Server Side Rendering</a>.
By rendering server side you save the browser the effort required to download additional files or perform the rendering calculations.</p>
</div>
<div class="paragraph">
  
  <p>For reference, the built-in HTML5 converter in Asciidoctor.js 1.5.9 is using Font Awesome 4.7.0 and the icons are rendered as CSS pseudo-elements and styled with the <code>Font Awesome</code> font-family.</p>
</div>
<div class="paragraph">
  
  <p>In a previous article, we explained <a href="custom-converter.adoc">how to create a custom HTML5 converter</a>.
In this article, we are going to see how we can use this knowledge to render icons as SVG using the <em>Font Awesome</em> JavaScript API.</p>
</div>
</div>
</div>
<section class="section is-small">
<h2 class="title is-4">Using the Font Awesome JavaScript API</h2>
<div class="paragraph">
  
  <p>Let&#8217;s take a quick look at the Font Awesome JavaScript API.<br>
You can install the library using <code>npm</code>:</p>
</div>
<div class="literalblock ">
<div class="content">
<pre>$ npm i @fortawesome/fontawesome-svg-core</pre> 
</div>
</div>
<div class="paragraph">
  
  <p>In addition we also need to install the SVG icons:</p>
</div>
<div class="literalblock ">
<div class="content">
<pre>$ npm i @fortawesome/free-solid-svg-icons \
        @fortawesome/free-regular-svg-icons \
        @fortawesome/free-brands-svg-icons</pre> 
</div>
</div>
<div class="box note">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-note">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>Font Awesome provides 3 sets of icons:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>solid</p>
</li>
<li>
<p>regular</p>
</li>
<li>
<p>brands</p>
</li>
</ul>
</div>
<div class="paragraph">
  
  <p>Here we install them all but you can choose to install just one set of icons.</p>
</div>
      </div>
    </div>
  </article>
</div>
<div class="paragraph">
  
  <p>So now we can start using the <em>Font Awesome</em> JavaScript API.<br>
The first thing to do is to add icons to the library:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-js" data-lang=js>const library = require('@fortawesome/fontawesome-svg-core').library;
const fas = require('@fortawesome/free-solid-svg-icons').fas
const far = require('@fortawesome/free-regular-svg-icons').far
const fab = require('@fortawesome/free-brands-svg-icons').fab
library.add(fas, far, fab)</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Then we can use the <code>icon</code> function to find an icon by name and get the SVG:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-js" data-lang=js>const icon = require('@fortawesome/fontawesome-svg-core').icon
const flaskIcon = icon({ iconName: 'flask' })
console.log(flaskIcon) // { type: 'icon', prefix: 'fa',  iconName: 'flask',  icon: [...] }
console.log(flaskIcon.html) // [ '&lt;svg...&gt;&lt;path ...&gt;&lt;/path&gt;&lt;/svg&gt;' ]</code></pre>
</div>
</div>
<div class="box important">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-important">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="exclamation-circle" class="svg-inline--fa fa-exclamation-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zm-248 50c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>If the icon does not exist, the function will return <code>undefined</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-js" data-lang=js>console.log(icon({ iconName: '404' })) // undefined</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Also make sure to specify the <code>prefix</code> attribute when you search for a brand icon:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-js" data-lang=js>console.log(icon({ iconName: 'gitlab' })) // undefined
console.log(icon({ prefix: 'fab', iconName: 'gitlab' })) // { type: 'icon', prefix: 'fab',  iconName: 'gitlab',  icon: [...] }</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Or when the icon is available in two styles (regular <code>far</code> and solid <code>fas</code>):</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-js" data-lang=js>console.log(icon({ prefix: 'far', iconName: 'address-book' })) // { type: 'icon', prefix: 'far',  iconName: 'address-book',  icon: [...] }
console.log(icon({ prefix: 'fas', iconName: 'address-book' })) // { type: 'icon', prefix: 'fas',  iconName: 'address-book',  icon: [...] }</code></pre>
</div>
</div>
      </div>
    </div>
  </article>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Server-side Rendering with a custom HTML5 converter</h2>
<div class="paragraph">
  
  <p>Now that we have learned how to use the <em>Font Awesome</em> JavaScript API, let&#8217;s write a custom converter to use it:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="4"><code class="language-js" data-lang=js>class TemplateConverter {
  constructor () {
    this.baseConverter = asciidoctor.Html5Converter.$new()
    const inlineImage = (node) =&gt; { /* */ } <i class="conum" data-value="1"></i>
    this.templates = {
      inline_image: inlineImage
    }
  }

  convert (node, transform, opts) {
    const template = this.templates[transform || node.node_name]
    if (template) {
      return template(node)
    }
    return this.baseConverter.convert(node, transform, opts)
  }
}

asciidoctor.ConverterFactory.register(new TemplateConverter(), ['html5'])</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>This function controls how the <code>inline_image</code> element will be converted to HTML.</td>
          </tr>
</table>
</div>
<div class="paragraph">
  
  <p>Here I will focus on the implementation of the <code>inlineImage</code> function.</p>
</div>
<div class="paragraph">
  
  <p>Now that we know how the Font Awesome API is working, we can implement the <code>inlineImage</code> function.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="2,3,5,7,11,14"><code class="language-js" data-lang=js>    const inlineImage = (node) =&gt; {
      if (node.getType() === 'icon' <i class="conum" data-value="1"></i>
        &amp;&amp; node.getDocument().isAttribute('icons', 'svg')) { <i class="conum" data-value="2"></i>
        const search = {}
        search.iconName = node.getTarget() <i class="conum" data-value="3"></i>
        if (node.hasAttribute('prefix')) {
          search.prefix = node.getAttribute('prefix') <i class="conum" data-value="4"></i>
        }
        const faIcon = icon(search)
        if (faIcon) {
          return faIcon.html <i class="conum" data-value="5"></i>
        }
      } else {
        return this.baseConverter.$inline_image(node) <i class="conum" data-value="6"></i>
      }
    }</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>Check that the <code>node</code> is an <code>icon</code> (ie. <code>inline_image</code> can also convert images)</td>
          </tr>
<tr>
          <td><i class="conum" data-value="2"></i><b>2</b></td>
          <td>Check that the document&#8217;s attribute named <code>icons</code> is equals to <code>svg</code></td>
          </tr>
<tr>
          <td><i class="conum" data-value="3"></i><b>3</b></td>
          <td>Get the icon&#8217;s name using <code>getTarget()</code> function</td>
          </tr>
<tr>
          <td><i class="conum" data-value="4"></i><b>4</b></td>
          <td>If defined, add the <code>prefix</code> to the search</td>
          </tr>
<tr>
          <td><i class="conum" data-value="5"></i><b>5</b></td>
          <td>If the icon was found, return the SVG representation</td>
          </tr>
<tr>
          <td><i class="conum" data-value="6"></i><b>6</b></td>
          <td>If the <code>node</code> is not an <code>icon</code> or if the document&#8217;s attribute named <code>icons</code> is not <code>svg</code>, delegate to the default HTML5 converter</td>
          </tr>
</table>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">And a bit of CSS</h2>
<div class="paragraph">
  
  <p>To render an SVG icon effectively we need to add a few styles in the page.
To do that, we are using a Docinfo processor:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="7"><code class="language-js" data-lang=js>const dom = require('@fortawesome/fontawesome-svg-core').dom;
const registry = asciidoctor.Extensions.create()
registry.docinfoProcessor(function () {
  const self = this
  self.atLocation('head')
  self.process(function () {
    return `&lt;style&gt;${dom.css()}&lt;/style&gt;` <i class="conum" data-value="1"></i>
  })
})</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td><code>dom.css()</code> returns a <code>String</code> representing all the styles required to display icons at the correct size</td>
          </tr>
</table>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Usage</h2>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="8"><code class="language-js" data-lang=js>const input = `You can enable icon:flask[] experimental features on icon:gitlab[prefix=fab] GitLab.`
const options = {
  header_footer: true,
  safe: 'safe',
  extension_registry: registry,
  attributes: { icons: 'svg' }
}
console.log(asciidoctor.convert(input, options)) <i class="conum" data-value="1"></i></code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>It will produce a full HTML5 page with SVG icons</td>
          </tr>
</table>
</div>
<div class="paragraph">
  
  <p>And here&#8217;s the result:</p>
</div>
<div class="exampleblock">
<div class="content">
<div class="paragraph">
  
  <p>You can enable <svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="flask" class="svg-inline--fa fa-flask fa-w-14" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M437.2 403.5L320 215V64h8c13.3 0 24-10.7 24-24V24c0-13.3-10.7-24-24-24H120c-13.3 0-24 10.7-24 24v16c0 13.3 10.7 24 24 24h8v151L10.8 403.5C-18.5 450.6 15.3 512 70.9 512h306.2c55.7 0 89.4-61.5 60.1-108.5zM137.9 320l48.2-77.6c3.7-5.2 5.8-11.6 5.8-18.4V64h64v160c0 6.9 2.2 13.2 5.8 18.4l48.2 77.6h-172z"></path></svg> experimental features on <svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="gitlab" class="svg-inline--fa fa-gitlab fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M105.2 24.9c-3.1-8.9-15.7-8.9-18.9 0L29.8 199.7h132c-.1 0-56.6-174.8-56.6-174.8zM.9 287.7c-2.6 8 .3 16.9 7.1 22l247.9 184-226.2-294zm160.8-88l94.3 294 94.3-294zm349.4 88l-28.8-88-226.3 294 247.9-184c6.9-5.1 9.7-14 7.2-22zM425.7 24.9c-3.1-8.9-15.7-8.9-18.9 0l-56.6 174.8h132z"></path></svg> GitLab.</p>
</div>
</div>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Bonus: Adding transformations</h2>
<div class="paragraph">
  
  <p>We can go one step further and add transformations:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="5,8,18,22,25"><code class="language-js" data-lang=js>    const inlineImage = (node) =&gt; {
      if (node.getType() === 'icon' &amp;&amp; node.getDocument().isAttribute('icons', 'svg')) {
        const transform = {}
        if (node.hasAttribute('rotate')) {
          transform.rotate = node.getAttribute('rotate') <i class="conum" data-value="1"></i>
        }
        if (node.hasAttribute('flip')) {
          const flip = node.getAttribute('flip') <i class="conum" data-value="2"></i>
          if (flip === 'vertical' || flip === 'y' || flip === 'v') {
            transform.flipY = true
          } else {
            transform.flipX = true
          }
        }
        const options = {}
        options.transform = transform
        if (node.hasAttribute('title')) {
          options.title = node.getAttribute('title') <i class="conum" data-value="3"></i>
        }
        options.classes = []
        if (node.hasAttribute('size')) {
          options.classes.push(`fa-${node.getAttribute('size')}`) <i class="conum" data-value="4"></i>
        }
        if (node.getRoles()) {
          options.classes = node.getRoles().map(value =&gt; value.trim()) <i class="conum" data-value="5"></i>
        }
        const meta = {}
        if (node.hasAttribute('prefix')) {
          meta.prefix = node.getAttribute('prefix')
        }
        meta.iconName = node.getTarget()
        const faIcon = icon(meta, options)
        if (faIcon) {
          return faIcon.html
        }
      } else {
        return this.baseConverter.$inline_image(node)
      }
    }</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>Use the <code>rotate</code> attribute to rotate the icon</td>
          </tr>
<tr>
          <td><i class="conum" data-value="2"></i><b>2</b></td>
          <td>Use the <code>flip</code> attribute to flip the icon vertically or horizontally</td>
          </tr>
<tr>
          <td><i class="conum" data-value="3"></i><b>3</b></td>
          <td>Set the <code>title</code> attribute if the <code>title</code> is defined</td>
          </tr>
<tr>
          <td><i class="conum" data-value="4"></i><b>4</b></td>
          <td>Add the <code>size</code> attribute as a class (prefixed by <code>fa-</code>)</td>
          </tr>
<tr>
          <td><i class="conum" data-value="5"></i><b>5</b></td>
          <td>Add the roles as HTML classes</td>
          </tr>
</table>
</div>
<div class="paragraph">
  
  <p>Here&#8217;s an example of what we can do:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-adoc" data-lang=adoc>.Size &amp; title
Do you want to drink a small icon:cocktail[sm] or a tall icon:beer[2x,title=pint] ?

.Fixed-width
icon:ruler-vertical[fw] vertical ruler +
icon:ruler-horizontal[fw] horizontal ruler

.Rotate
icon:flag[rotate=90] +
icon:flag[rotate=180] +
icon:flag[rotate=270] +
icon:flag[flip=horizontal] +
icon:flag[flip=vertical]

.Spin and pulse
We are working on it icon:cog[spin], please wait icon:spinner[role=fa-pulse]

.Roles
icon:heart[role=is-primary] icon:heart[role=is-success] icon:heart[role=is-warning] icon:heart[role=is-danger]</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>And here&#8217;s the result:</p>
</div>
<div class="exampleblock">
<div class="content">
<div class="paragraph">
  <div class="title">Size &amp; title</div>
  <p>Do you want to drink a small <svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="cocktail" class="svg-inline--fa fa-cocktail fa-w-18 fa-sm" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path fill="currentColor" d="M296 464h-56V338.78l168.74-168.73c15.52-15.52 4.53-42.05-17.42-42.05H24.68c-21.95 0-32.94 26.53-17.42 42.05L176 338.78V464h-56c-22.09 0-40 17.91-40 40 0 4.42 3.58 8 8 8h240c4.42 0 8-3.58 8-8 0-22.09-17.91-40-40-40zM432 0c-62.61 0-115.35 40.2-135.18 96h52.54c16.65-28.55 47.27-48 82.64-48 52.93 0 96 43.06 96 96s-43.07 96-96 96c-14.04 0-27.29-3.2-39.32-8.64l-35.26 35.26C379.23 279.92 404.59 288 432 288c79.53 0 144-64.47 144-144S511.53 0 432 0z"></path></svg> or a tall <svg aria-labelledby="svg-inline--fa-title-4yQMQ0N4CN6C" data-prefix="fa" data-icon="beer" class="svg-inline--fa fa-beer fa-w-14 fa-2x" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><title id="svg-inline--fa-title-4yQMQ0N4CN6C">pint</title><path fill="currentColor" d="M368 96h-48V56c0-13.255-10.745-24-24-24H24C10.745 32 0 42.745 0 56v400c0 13.255 10.745 24 24 24h272c13.255 0 24-10.745 24-24v-42.11l80.606-35.977C429.396 365.063 448 336.388 448 304.86V176c0-44.112-35.888-80-80-80zm16 208.86a16.018 16.018 0 0 1-9.479 14.611L320 343.805V160h48c8.822 0 16 7.178 16 16v128.86zM208 384c-8.836 0-16-7.164-16-16V144c0-8.836 7.164-16 16-16s16 7.164 16 16v224c0 8.836-7.164 16-16 16zm-96 0c-8.836 0-16-7.164-16-16V144c0-8.836 7.164-16 16-16s16 7.164 16 16v224c0 8.836-7.164 16-16 16z"></path></svg> ?</p>
</div>
<div class="paragraph">
  <div class="title">Fixed-width</div>
  <p><svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="ruler-vertical" class="svg-inline--fa fa-ruler-vertical fa-w-8 fa-fw" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512"><path fill="currentColor" d="M168 416c-4.42 0-8-3.58-8-8v-16c0-4.42 3.58-8 8-8h88v-64h-88c-4.42 0-8-3.58-8-8v-16c0-4.42 3.58-8 8-8h88v-64h-88c-4.42 0-8-3.58-8-8v-16c0-4.42 3.58-8 8-8h88v-64h-88c-4.42 0-8-3.58-8-8v-16c0-4.42 3.58-8 8-8h88V32c0-17.67-14.33-32-32-32H32C14.33 0 0 14.33 0 32v448c0 17.67 14.33 32 32 32h192c17.67 0 32-14.33 32-32v-64h-88z"></path></svg> vertical ruler<br>
<svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="ruler-horizontal" class="svg-inline--fa fa-ruler-horizontal fa-w-18 fa-fw" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path fill="currentColor" d="M544 128h-48v88c0 4.42-3.58 8-8 8h-16c-4.42 0-8-3.58-8-8v-88h-64v88c0 4.42-3.58 8-8 8h-16c-4.42 0-8-3.58-8-8v-88h-64v88c0 4.42-3.58 8-8 8h-16c-4.42 0-8-3.58-8-8v-88h-64v88c0 4.42-3.58 8-8 8h-16c-4.42 0-8-3.58-8-8v-88h-64v88c0 4.42-3.58 8-8 8H88c-4.42 0-8-3.58-8-8v-88H32c-17.67 0-32 14.33-32 32v192c0 17.67 14.33 32 32 32h512c17.67 0 32-14.33 32-32V160c0-17.67-14.33-32-32-32z"></path></svg> horizontal ruler</p>
</div>
<div class="paragraph">
  <div class="title">Rotate</div>
  <p><svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="flag" class="svg-inline--fa fa-flag fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" style="transform-origin: 0.5em 0.5em;"><g transform="translate(256 256)"><g transform="translate(0, 0)  scale(1, 1)  rotate(90 0 0)"><path fill="currentColor" d="M349.565 98.783C295.978 98.783 251.721 64 184.348 64c-24.955 0-47.309 4.384-68.045 12.013a55.947 55.947 0 0 0 3.586-23.562C118.117 24.015 94.806 1.206 66.338.048 34.345-1.254 8 24.296 8 56c0 19.026 9.497 35.825 24 45.945V488c0 13.255 10.745 24 24 24h16c13.255 0 24-10.745 24-24v-94.4c28.311-12.064 63.582-22.122 114.435-22.122 53.588 0 97.844 34.783 165.217 34.783 48.169 0 86.667-16.294 122.505-40.858C506.84 359.452 512 349.571 512 339.045v-243.1c0-23.393-24.269-38.87-45.485-29.016-34.338 15.948-76.454 31.854-116.95 31.854z" transform="translate(-256 -256)"></path></g></g></svg><br>
<svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="flag" class="svg-inline--fa fa-flag fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" style="transform-origin: 0.5em 0.5em;"><g transform="translate(256 256)"><g transform="translate(0, 0)  scale(1, 1)  rotate(180 0 0)"><path fill="currentColor" d="M349.565 98.783C295.978 98.783 251.721 64 184.348 64c-24.955 0-47.309 4.384-68.045 12.013a55.947 55.947 0 0 0 3.586-23.562C118.117 24.015 94.806 1.206 66.338.048 34.345-1.254 8 24.296 8 56c0 19.026 9.497 35.825 24 45.945V488c0 13.255 10.745 24 24 24h16c13.255 0 24-10.745 24-24v-94.4c28.311-12.064 63.582-22.122 114.435-22.122 53.588 0 97.844 34.783 165.217 34.783 48.169 0 86.667-16.294 122.505-40.858C506.84 359.452 512 349.571 512 339.045v-243.1c0-23.393-24.269-38.87-45.485-29.016-34.338 15.948-76.454 31.854-116.95 31.854z" transform="translate(-256 -256)"></path></g></g></svg><br>
<svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="flag" class="svg-inline--fa fa-flag fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" style="transform-origin: 0.5em 0.5em;"><g transform="translate(256 256)"><g transform="translate(0, 0)  scale(1, 1)  rotate(270 0 0)"><path fill="currentColor" d="M349.565 98.783C295.978 98.783 251.721 64 184.348 64c-24.955 0-47.309 4.384-68.045 12.013a55.947 55.947 0 0 0 3.586-23.562C118.117 24.015 94.806 1.206 66.338.048 34.345-1.254 8 24.296 8 56c0 19.026 9.497 35.825 24 45.945V488c0 13.255 10.745 24 24 24h16c13.255 0 24-10.745 24-24v-94.4c28.311-12.064 63.582-22.122 114.435-22.122 53.588 0 97.844 34.783 165.217 34.783 48.169 0 86.667-16.294 122.505-40.858C506.84 359.452 512 349.571 512 339.045v-243.1c0-23.393-24.269-38.87-45.485-29.016-34.338 15.948-76.454 31.854-116.95 31.854z" transform="translate(-256 -256)"></path></g></g></svg><br>
<svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="flag" class="svg-inline--fa fa-flag fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" style="transform-origin: 0.5em 0.5em;"><g transform="translate(256 256)"><g transform="translate(0, 0)  scale(-1, 1)  rotate(0 0 0)"><path fill="currentColor" d="M349.565 98.783C295.978 98.783 251.721 64 184.348 64c-24.955 0-47.309 4.384-68.045 12.013a55.947 55.947 0 0 0 3.586-23.562C118.117 24.015 94.806 1.206 66.338.048 34.345-1.254 8 24.296 8 56c0 19.026 9.497 35.825 24 45.945V488c0 13.255 10.745 24 24 24h16c13.255 0 24-10.745 24-24v-94.4c28.311-12.064 63.582-22.122 114.435-22.122 53.588 0 97.844 34.783 165.217 34.783 48.169 0 86.667-16.294 122.505-40.858C506.84 359.452 512 349.571 512 339.045v-243.1c0-23.393-24.269-38.87-45.485-29.016-34.338 15.948-76.454 31.854-116.95 31.854z" transform="translate(-256 -256)"></path></g></g></svg><br>
<svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="flag" class="svg-inline--fa fa-flag fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" style="transform-origin: 0.5em 0.5em;"><g transform="translate(256 256)"><g transform="translate(0, 0)  scale(1, -1)  rotate(0 0 0)"><path fill="currentColor" d="M349.565 98.783C295.978 98.783 251.721 64 184.348 64c-24.955 0-47.309 4.384-68.045 12.013a55.947 55.947 0 0 0 3.586-23.562C118.117 24.015 94.806 1.206 66.338.048 34.345-1.254 8 24.296 8 56c0 19.026 9.497 35.825 24 45.945V488c0 13.255 10.745 24 24 24h16c13.255 0 24-10.745 24-24v-94.4c28.311-12.064 63.582-22.122 114.435-22.122 53.588 0 97.844 34.783 165.217 34.783 48.169 0 86.667-16.294 122.505-40.858C506.84 359.452 512 349.571 512 339.045v-243.1c0-23.393-24.269-38.87-45.485-29.016-34.338 15.948-76.454 31.854-116.95 31.854z" transform="translate(-256 -256)"></path></g></g></svg></p>
</div>
<div class="paragraph">
  <div class="title">Spin and pulse</div>
  <p>We are working on it <svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="cog" class="svg-inline--fa fa-cog fa-w-16 fa-spin" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M487.4 315.7l-42.6-24.6c4.3-23.2 4.3-47 0-70.2l42.6-24.6c4.9-2.8 7.1-8.6 5.5-14-11.1-35.6-30-67.8-54.7-94.6-3.8-4.1-10-5.1-14.8-2.3L380.8 110c-17.9-15.4-38.5-27.3-60.8-35.1V25.8c0-5.6-3.9-10.5-9.4-11.7-36.7-8.2-74.3-7.8-109.2 0-5.5 1.2-9.4 6.1-9.4 11.7V75c-22.2 7.9-42.8 19.8-60.8 35.1L88.7 85.5c-4.9-2.8-11-1.9-14.8 2.3-24.7 26.7-43.6 58.9-54.7 94.6-1.7 5.4.6 11.2 5.5 14L67.3 221c-4.3 23.2-4.3 47 0 70.2l-42.6 24.6c-4.9 2.8-7.1 8.6-5.5 14 11.1 35.6 30 67.8 54.7 94.6 3.8 4.1 10 5.1 14.8 2.3l42.6-24.6c17.9 15.4 38.5 27.3 60.8 35.1v49.2c0 5.6 3.9 10.5 9.4 11.7 36.7 8.2 74.3 7.8 109.2 0 5.5-1.2 9.4-6.1 9.4-11.7v-49.2c22.2-7.9 42.8-19.8 60.8-35.1l42.6 24.6c4.9 2.8 11 1.9 14.8-2.3 24.7-26.7 43.6-58.9 54.7-94.6 1.5-5.5-.7-11.3-5.6-14.1zM256 336c-44.1 0-80-35.9-80-80s35.9-80 80-80 80 35.9 80 80-35.9 80-80 80z"></path></svg>, please wait <svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="spinner" class="svg-inline--fa fa-spinner fa-w-16 fa-pulse" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M304 48c0 26.51-21.49 48-48 48s-48-21.49-48-48 21.49-48 48-48 48 21.49 48 48zm-48 368c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zm208-208c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zM96 256c0-26.51-21.49-48-48-48S0 229.49 0 256s21.49 48 48 48 48-21.49 48-48zm12.922 99.078c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.491-48-48-48zm294.156 0c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.49-48-48-48zM108.922 60.922c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.491-48-48-48z"></path></svg></p>
</div>
<div class="paragraph">
  <div class="title">Roles</div>
  <p><svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="heart" class="svg-inline--fa fa-heart fa-w-16 is-primary" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M462.3 62.6C407.5 15.9 326 24.3 275.7 76.2L256 96.5l-19.7-20.3C186.1 24.3 104.5 15.9 49.7 62.6c-62.8 53.6-66.1 149.8-9.9 207.9l193.5 199.8c12.5 12.9 32.8 12.9 45.3 0l193.5-199.8c56.3-58.1 53-154.3-9.8-207.9z"></path></svg> <svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="heart" class="svg-inline--fa fa-heart fa-w-16 is-success" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M462.3 62.6C407.5 15.9 326 24.3 275.7 76.2L256 96.5l-19.7-20.3C186.1 24.3 104.5 15.9 49.7 62.6c-62.8 53.6-66.1 149.8-9.9 207.9l193.5 199.8c12.5 12.9 32.8 12.9 45.3 0l193.5-199.8c56.3-58.1 53-154.3-9.8-207.9z"></path></svg> <svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="heart" class="svg-inline--fa fa-heart fa-w-16 is-warning" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M462.3 62.6C407.5 15.9 326 24.3 275.7 76.2L256 96.5l-19.7-20.3C186.1 24.3 104.5 15.9 49.7 62.6c-62.8 53.6-66.1 149.8-9.9 207.9l193.5 199.8c12.5 12.9 32.8 12.9 45.3 0l193.5-199.8c56.3-58.1 53-154.3-9.8-207.9z"></path></svg> <svg aria-hidden="true" focusable="false" data-prefix="fa" data-icon="heart" class="svg-inline--fa fa-heart fa-w-16 is-danger" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M462.3 62.6C407.5 15.9 326 24.3 275.7 76.2L256 96.5l-19.7-20.3C186.1 24.3 104.5 15.9 49.7 62.6c-62.8 53.6-66.1 149.8-9.9 207.9l193.5 199.8c12.5 12.9 32.8 12.9 45.3 0l193.5-199.8c56.3-58.1 53-154.3-9.8-207.9z"></path></svg></p>
</div>
</div>
</div>
</section>]]></content:encoded>
  </item>
<item>
    <title><![CDATA[Awesome Asciidoctor.js: Create PDF using Web technologies]]></title>
    <description><![CDATA[Learn how to create a PDF from an AsciiDoc document using Web technologies!]]></description>
    <link>undefined</link>
    <category><![CDATA[Asciidoctor.js]]></category>
<category><![CDATA[Converter]]></category>
<category><![CDATA[PDF]]></category>
<category><![CDATA[JavaScript]]></category>
<category><![CDATA[CSS]]></category>
<category><![CDATA[Paged Media]]></category>
    <dc:creator><![CDATA[Guillaume Grossetie]]></dc:creator>
    <pubDate>Sun, 29 Mar 2020 13:00:00 GMT</pubDate>
    <media:content url="https://blog.yuzutech.fr/_/images/print.jpg" medium="image"/>
    <content:encoded><![CDATA[<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
  
  <p>The first question you might ask is: <strong>does it make sense to use Web technologies for print?</strong><br>
It actually makes a lot of sense!</p>
</div>
</div>
</div>
<section class="section is-small">
<h2 class="title is-4">Why Web technologies make sense for print</h2>
<div class="paragraph">
  
  <p>First of all, you can create complex layout using Flexbox and Grid.
Just take a look at a few experiments by <a href="https://twitter.com/julesforrest">Jules Forrest</a>:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://codepen.io/julesforrest/full/xLBbVb/">Explicit</a></p>
</li>
<li>
<p><a href="https://codepen.io/julesforrest/full/yowMPw/">IL magazine</a></p>
</li>
<li>
<p><a href="https://codepen.io/julesforrest/full/oeVKjg/">Americanistica</a></p>
</li>
</ul>
</div>
<div class="paragraph">
  
  <p>You can also check out the great <a href="https://labs.jensimmons.com/">experimental layout lab of Jen Simmons</a>.
Here are my favorite ones:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://labs.jensimmons.com/2017/02-004.html">Futurismo Trentino exhibition poster</a></p>
</li>
<li>
<p><a href="https://labs.jensimmons.com/2018/03-004.html">Bauhaus</a></p>
</li>
<li>
<p><a href="https://labs.jensimmons.com/2017/01-007.html">Die Neue Typographie</a></p>
</li>
</ul>
</div>
<div class="paragraph">
  
  <p>Pretty neat, right? 🔥</p>
</div>
<div class="paragraph">
  
  <p>Furthermore, much of the CSS you already know will be useful when formatting for print.
But there&#8217;s more, CSS has two specifications which deal specifically with CSS for print:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://www.w3.org/TR/css-page-3/">Paged Media module</a></p>
</li>
<li>
<p><a href="https://www.w3.org/TR/css-gcpm-3/">Generated Content for Paged Media Module</a></p>
</li>
</ul>
</div>
<div class="paragraph">
  
  <p>You can define page size, page margins, page orientation, bleed area, crop and registration marks, footnotes, page numbering&#8230;&#8203; and more!</p>
</div>
<div class="box tip">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-tip">
          <span class="fa-layers"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="circle" class="svg-inline--fa fa-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8z"></path></svg><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="lightbulb" class="svg-inline--fa fa-lightbulb fa-w-11 fa-inverse" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 352 512" style="transform-origin: 0.21875em 0.5em;"><g transform="translate(176 256)"><g transform="translate(-64, 0)  scale(0.5, 0.5)  rotate(0 0 0)"><path fill="currentColor" d="M96.06 454.35c.01 6.29 1.87 12.45 5.36 17.69l17.09 25.69a31.99 31.99 0 0 0 26.64 14.28h61.71a31.99 31.99 0 0 0 26.64-14.28l17.09-25.69a31.989 31.989 0 0 0 5.36-17.69l.04-38.35H96.01l.05 38.35zM0 176c0 44.37 16.45 84.85 43.56 115.78 16.52 18.85 42.36 58.23 52.21 91.45.04.26.07.52.11.78h160.24c.04-.26.07-.51.11-.78 9.85-33.22 35.69-72.6 52.21-91.45C335.55 260.85 352 220.37 352 176 352 78.61 272.91-.3 175.45 0 73.44.31 0 82.97 0 176zm176-80c-44.11 0-80 35.89-80 80 0 8.84-7.16 16-16 16s-16-7.16-16-16c0-61.76 50.24-112 112-112 8.84 0 16 7.16 16 16s-7.16 16-16 16z" transform="translate(-176 -256)"></path></g></g></svg></span>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>Recommended articles by <a href="https://twitter.com/rachelandrew">Rachel Andrew</a> from <a href="https://www.smashingmagazine.com/">Smashing Magazine</a> to learn more about print CSS:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://www.smashingmagazine.com/2018/05/print-stylesheets-in-2018/" class="bare">www.smashingmagazine.com/2018/05/print-stylesheets-in-2018/</a></p>
</li>
<li>
<p><a href="https://www.smashingmagazine.com/2015/01/designing-for-print-with-css/" class="bare">www.smashingmagazine.com/2015/01/designing-for-print-with-css/</a></p>
</li>
<li>
<p><a href="https://www.smashingmagazine.com/2019/06/create-pdf-web-application/" class="bare">www.smashingmagazine.com/2019/06/create-pdf-web-application/</a></p>
</li>
</ul>
</div>
      </div>
    </div>
  </article>
</div>
<div class="paragraph">
  
  <p>So, basically we have everything we need, right?
Well&#8230;&#8203; currently, very few things are natively supported by browsers 😞</p>
</div>
<div class="paragraph">
  
  <p>But don&#8217;t despair, there&#8217;s hope!</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Paged.js to the rescue! ⛑️</h2>
<div class="paragraph">
  
  <p><a href="https://www.pagedjs.org/">Paged.js</a> is a free and open source JavaScript library that paginates content in the browser to create PDF output from any HTML content.
Paged.js follows the Paged Media standards published by the W3C.
In effect, Paged.js acts as a polyfill for the CSS modules to print content using features that are not yet natively supported by browsers.</p>
</div>
<div class="paragraph">
  
  <p>So, while browsers don&#8217;t support natively all the great features specified by the W3C, we can use Paged.js to fill the gap!</p>
</div>
<div class="paragraph">
  
  <p>Moreover, in February this year, the <a href="https://www.w3.org/community/cssprint/">CSS Print Community Group</a> has been launched and Paged.js is part of it!
The goal of this community group is to gather use cases, help with specifications, and advocate for more and better implementations in browsers.</p>
</div>
<div class="paragraph">
  
  <p>So things are moving and the future of CSS print is bright!🌻</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">What about Asciidoctor.js?</h2>
<div class="paragraph">
  
  <p><a href="https://github.com/asciidoctor/asciidoctor.js">Asciidoctor.js</a> can convert AsciiDoc content to HTML5 using the built-in converter or <a href="https://blog.yuzutech.fr/blog/custom-converter/index.html">a custom HTML5 converter</a>.
So, we already have everything we need to produce a "print-ready" HTML5 page from an AsciiDoc document.</p>
</div>
<div class="paragraph">
  
  <p>But we still need to open this Web page in a browser and instruct the browser to print it to PDF&#8230;&#8203;
and that&#8217;s exactly what <a href="https://github.com/puppeteer/puppeteer">Puppeteer</a> can do!<br>
Puppeteer is a Node library which provides a high-level API to control Chrome over the DevTools Protocol.
Puppeteer runs headless by default and provides an API to generate a PDF of the page with <code>print</code> css media.</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Summary</h2>
<div class="paragraph">
  
  <p>Let&#8217;s recap quickly:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>CSS is awesome and provide a great set of features for printing</p>
</li>
<li>
<p>Browsers don&#8217;t support natively all these features but Paged.js is here to fill the gap</p>
</li>
<li>
<p>Asciidoctor.js can produce a "print-ready" HTML5 page from an AsciiDoc document</p>
</li>
<li>
<p>Puppeteer can run a headless browser and print a Web page to PDF</p>
</li>
</ul>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Putting it all together!</h2>
<div class="paragraph">
  
  <p>Introducing <a href="https://github.com/mogztter/asciidoctor-pdf.js#asciidoctor-pdf">Asciidoctor Web PDF</a> 🎉</p>
</div>
<div class="paragraph">
  
  <p>This project provides a PDF converter for AsciiDoc based on Web technologies using:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Asciidoctor.js</p>
</li>
<li>
<p>Paged.js</p>
</li>
<li>
<p>Puppeteer</p>
</li>
</ul>
</div>
<div class="paragraph">
  
  <p>The project is at an early stage but it already has a few interesting features:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Complex layouts with CSS and JavaScript</p>
</li>
<li>
<p>SVG icons with Font Awesome 5</p>
</li>
<li>
<p>PDF document outline (i.e., bookmarks)</p>
</li>
<li>
<p>Table Of Contents</p>
</li>
<li>
<p>Document metadata (title, authors, subject, keywords, etc)</p>
</li>
<li>
<p>Fully customizable template</p>
</li>
<li>
<p>Syntax highlighting with Highlight.js</p>
</li>
<li>
<p>Page numbering</p>
</li>
<li>
<p>Preview mode</p>
</li>
<li>
<p>STEM support with MathJax 3</p>
</li>
</ul>
</div>
<div class="paragraph">
  
  <p>If you have Node installed, you can give it a try:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code>$ npm i asciidoctor-pdf
$ asciidoctor-pdf doc.adoc</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Have fun! 😀</p>
</div>
</section>]]></content:encoded>
  </item>
<item>
    <title><![CDATA[Awesome Asciidoctor.js: Write your own HTML5 converter]]></title>
    <description><![CDATA[Asciidoctor.js provides a built-in HTML5 converter. In this article, we are going to see how to override the converter methods used to convert almost any individual AsciiDoc element.]]></description>
    <link>undefined</link>
    <category><![CDATA[Asciidoctor.js]]></category>
<category><![CDATA[Converter]]></category>
<category><![CDATA[JavaScript]]></category>
    <dc:creator><![CDATA[Guillaume Grossetie]]></dc:creator>
    <pubDate>Fri, 16 Nov 2018 17:45:00 GMT</pubDate>
    <media:content url="https://blog.yuzutech.fr/_/images/build.jpg" medium="image"/>
    <content:encoded><![CDATA[<div class="paragraph">
  
  <p>The goal of a HTML5 converter is to convert an AsciiDoc document to an HTML5 page.
By default Asciidoctor.js provides a built-in HTML5 converter but you can have the full control over how elements are converted.</p>
</div>
<div class="paragraph">
  
  <p>In the following example, we are going to define how the <code>paragraph</code> element should be converted.
The other elements will be converted using the built-in HTML5 converter.
In other words, we override how the <code>paragraph</code> element is converted and we delegate to the built-in HTML5 converter the rest:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="5,7,13,14,16,19"><code class="language-javascript" data-lang=javascript>const asciidoctor = require('asciidoctor.js')()

class TemplateConverter {
  constructor () {
    this.baseConverter = asciidoctor.Html5Converter.$new() <i class="conum" data-value="1"></i>
    this.templates = {
      paragraph: (node) =&gt; `&lt;p class="paragraph"&gt;${node.getContent()}&lt;/p&gt;` <i class="conum" data-value="2"></i>
    }
  }

  convert (node, transform, opts) {
    const template = this.templates[transform || node.node_name]
    if (template) { <i class="conum" data-value="3"></i>
      return template(node) <i class="conum" data-value="4"></i>
    }
    return this.baseConverter.convert(node, transform, opts) <i class="conum" data-value="5"></i>
  }
}
asciidoctor.ConverterFactory.register(new TemplateConverter(), ['html5']) <i class="conum" data-value="6"></i>

// convert your document...</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>Instantiate the built-in HTML5 converter</td>
          </tr>
<tr>
          <td><i class="conum" data-value="2"></i><b>2</b></td>
          <td>Define how the <code>paragraph</code> element will be converted</td>
          </tr>
<tr>
          <td><i class="conum" data-value="3"></i><b>3</b></td>
          <td>Check if there&#8217;s a dedicated template for the element</td>
          </tr>
<tr>
          <td><i class="conum" data-value="4"></i><b>4</b></td>
          <td>If it&#8217;s the case, call the template (function) with the node</td>
          </tr>
<tr>
          <td><i class="conum" data-value="5"></i><b>5</b></td>
          <td>Otherwise call the base converter (built-in HTML5 converter)</td>
          </tr>
<tr>
          <td><i class="conum" data-value="6"></i><b>6</b></td>
          <td>Finally register the custom converter for the <code>html5</code> backend</td>
          </tr>
</table>
</div>
<div class="paragraph">
  
  <p>In the above example, we are using <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals">Template Literals</a> but you can use your favorite template engine.
You can also override other elements.
Here&#8217;s the complete list:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>document</p>
</li>
<li>
<p>embedded</p>
</li>
<li>
<p>outline</p>
</li>
<li>
<p>section</p>
</li>
<li>
<p>admonition</p>
</li>
<li>
<p>audio</p>
</li>
<li>
<p>colist</p>
</li>
<li>
<p>dlist</p>
</li>
<li>
<p>example</p>
</li>
<li>
<p>floating-title</p>
</li>
<li>
<p>image</p>
</li>
<li>
<p>listing</p>
</li>
<li>
<p>literal</p>
</li>
<li>
<p>stem</p>
</li>
<li>
<p>olist</p>
</li>
<li>
<p>open</p>
</li>
<li>
<p>page_break</p>
</li>
<li>
<p>paragraph</p>
</li>
<li>
<p>preamble</p>
</li>
<li>
<p>quote</p>
</li>
<li>
<p>thematic_break</p>
</li>
<li>
<p>sidebar</p>
</li>
<li>
<p>table</p>
</li>
<li>
<p>toc</p>
</li>
<li>
<p>ulist</p>
</li>
<li>
<p>verse</p>
</li>
<li>
<p>video</p>
</li>
<li>
<p>inline_anchor</p>
</li>
<li>
<p>inline_break</p>
</li>
<li>
<p>inline_button</p>
</li>
<li>
<p>inline_callout</p>
</li>
<li>
<p>inline_footnote</p>
</li>
<li>
<p>inline_image</p>
</li>
<li>
<p>inline_indexterm</p>
</li>
<li>
<p>inline_kbd</p>
</li>
<li>
<p>inline_menu</p>
</li>
<li>
<p>inline_quoted</p>
</li>
</ul>
</div>
<div class="paragraph">
  
  <p>Using a custom HTML5 converter is extremely powerful and should be used only when you want to have full control over the converter.
For instance, when you want to build your own blog generator, or create a converter for the latest HTML5 presentation framework.</p>
</div>
<div class="paragraph">
  
  <p>Written with Asciidoctor.js 1.5.9.</p>
</div>]]></content:encoded>
  </item>
<item>
    <title><![CDATA[Generate a FlameGraph using an embeddable profiler]]></title>
    <description><![CDATA[Learn how to generate a FlameGraph using an embeddable profiler in a JVM application.]]></description>
    <link>undefined</link>
    <category><![CDATA[FlameGraph]]></category>
<category><![CDATA[Java]]></category>
<category><![CDATA[Clojure]]></category>
<category><![CDATA[JVM]]></category>
    <dc:creator><![CDATA[Guillaume Grossetie]]></dc:creator>
    <pubDate>Mon, 25 Feb 2019 20:00:00 GMT</pubDate>
    <media:content url="https://blog.yuzutech.fr/_/images/fire.jpeg" medium="image"/>
    <content:encoded><![CDATA[<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
  
  <p>Flame graphs are a visualization of profiled software, allowing the most frequent code-paths to be identified quickly and accurately.
If you want to learn more, you should definitely read <a href="http://www.brendangregg.com/flamegraphs.html">this article from the creator of Flame graphs, Brendan Gregg</a>.</p>
</div>
</div>
</div>
<section class="section is-small">
<h2 class="title is-4">Where it all started</h2>
<div class="paragraph">
  
  <p>Recently, I was investigating a performance issue in a JRuby application, namely AsciidoctorJ with the Asciidoctor diagram extension enabled.
The same code was almost two times slower in JRuby 9 than in JRuby 1.7.</p>
</div>
<div class="paragraph">
  
  <p>Dominic, who reported this issue, has created a <em>short-living</em> application to reproduce it.
The application was written in Clojure and was able to generate a flame graph for a particular function:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-clojure" data-lang=clojure>(ns io.github.asciidoctor
  (:require
    [clj-async-profiler.core :as profiler])
  (:import
    [org.asciidoctor
     Asciidoctor
     Asciidoctor$Factory]
    [java.io File]))

(defn asciidoctor ^Asciidoctor []
  (doto
    (Asciidoctor$Factory/create)
    (.requireLibrary (into-array String ["asciidoctor-diagram"]))))

(defn -main
  [&amp; _]
  (let [asciidoctor (asciidoctor)
        f (File. "doc.adoc")]
    ;; Warm up the JIT... <i class="conum" data-value="1"></i>
    (println
      (.getAbsolutePath
        (profiler/profile <i class="conum" data-value="2"></i>
          {:return-file true}
          (dotimes [_ 100] <i class="conum" data-value="3"></i>
            (.readDocumentHeader asciidoctor f)))))
    (System/exit 0)))</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>Warm up the JIT by doing some work</td>
          </tr>
<tr>
          <td><i class="conum" data-value="2"></i><b>2</b></td>
          <td>Profile a function</td>
          </tr>
<tr>
          <td><i class="conum" data-value="3"></i><b>3</b></td>
          <td>Execute 100 times the function <code>readDocumentHeader</code></td>
          </tr>
</table>
</div>
<div class="paragraph">
  
  <p>If you are not familiar with Clojure, don&#8217;t worry, the important thing to remember is that this application can generate a Flame graph for a given function.<br>
Here, the function is execute 100 times <code>readDocumentHeader</code>.</p>
</div>
<div class="paragraph">
  
  <p>I was really impressed because typically if you want to generate a Flame graph, you will have to:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>package your application,</p>
</li>
<li>
<p>attach an agent or start a profiler for a given <code>pid</code>,</p>
</li>
<li>
<p>and then convert the raw output to a nice SVG visualization</p>
</li>
</ul>
</div>
<div class="paragraph">
  
  <p>Here we can just run the application and it will generate a Flame graph for a given function.
Don&#8217;t get me wrong, using the technique described above is working great but in this case it&#8217;s not really practical because we don&#8217;t want to include the warm up, and the application is not running for long.</p>
</div>
<div class="paragraph">
  
  <p>Now you may be wondering, "how is it working ?"</p>
</div>
<div class="paragraph">
  
  <p>Actually, the <code>profiler/profile</code> function is provided by the <a href="https://github.com/clojure-goes-fast/clj-async-profiler">clj-async-profiler</a> library.</p>
</div>
<div class="box important">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-important">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="exclamation-circle" class="svg-inline--fa fa-exclamation-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zm-248 50c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>Please note that <em>clj-async-profiler</em> is only supported on GNU/Linux and MacOS.
If you are running GNU/Linux, you need to do ensure that <code>perf_event_paranoid</code> is set to 1:</p>
</div>
<div class="literalblock ">
<div class="content">
<pre>cat /proc/sys/kernel/perf_event_paranoid</pre> 
</div>
</div>
<div class="paragraph">
  
  <p>If it prints 2, it means you are running a newer Linux kernel.
You will have to set it to 1 to allow async-profiler to use kernel profiling data:</p>
</div>
<div class="literalblock ">
<div class="content">
<pre>$ echo 1 | sudo tee /proc/sys/kernel/perf_event_paranoid</pre> 
</div>
</div>
      </div>
    </div>
  </article>
</div>
<div class="paragraph">
  
  <p>This library is a really convenient wrapper around the excellent <a href="https://github.com/jvm-profiling-tools/async-profiler">async-profiler</a> and <a href="https://github.com/brendangregg/FlameGraph">FlameGraph</a>.
With this library, you can just call a function in your application and it will generate a Flame graph!</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">From Clojure to Java</h2>
<div class="paragraph">
  
  <p>While I was trying to pinpoint the root cause of performance issue, I though maybe it could be an interaction between Clojure dynamic classloader and JRuby.<br>
In order to remove this assumption, I decided to write the same application in Java to compare the two Flame graphs.</p>
</div>
<div class="paragraph">
  
  <p>And here&#8217;s roughly the same application in Java:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="11"><code class="language-java" data-lang=java>package org.asciidoctor;

import java.io.File;

public class App {
  public static void main(String[] args) {
    Asciidoctor asciidoctor = Asciidoctor.Factory.create();
    asciidoctor.requireLibrary("asciidoctor-diagram");
    File file = new File("doc.adoc");
    // Warm up the JIT... <i class="conum" data-value="1"></i>
    for (int i = 0; i &lt; 100; i++) { <i class="conum" data-value="2"></i>
      asciidoctor.readDocumentHeader(file);
    }
    System.exit(0);
  }
}</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>Warm up the JIT by doing some work</td>
          </tr>
<tr>
          <td><i class="conum" data-value="2"></i><b>2</b></td>
          <td>Execute 100 times the method <code>readDocumentHeader</code></td>
          </tr>
</table>
</div>
<div class="paragraph">
  
  <p>Using the following Maven dependency:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-xml" data-lang=xml>&lt;dependency&gt;
  &lt;groupId&gt;org.jruby&lt;/groupId&gt;
  &lt;artifactId&gt;jruby-complete&lt;/artifactId&gt;
  &lt;version&gt;9.2.6.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
  &lt;groupId&gt;org.asciidoctor&lt;/groupId&gt;
  &lt;artifactId&gt;asciidoctorj&lt;/artifactId&gt;
  &lt;version&gt;1.6.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
  &lt;groupId&gt;org.asciidoctor&lt;/groupId&gt;
  &lt;artifactId&gt;asciidoctorj-diagram&lt;/artifactId&gt;
  &lt;version&gt;1.5.12&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Now we need to produce a Flame graph so we can compare the two.</p>
</div>
<div class="paragraph">
  
  <p>I did some research but found nothing close to the ease of use of the <em>clj-async-profiler</em> library.
So why don&#8217;t we just use it in Java?</p>
</div>
<div class="paragraph">
  
  <p>Clojure provides a package to bootstrap Clojure access from other JVM languages.
In other words, we can call <a href="https://clojure.org/reference/java_interop#_calling_clojure_from_java">Clojure from Java</a>.</p>
</div>
<div class="paragraph">
  
  <p>To do so, we need to add the following dependencies:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-xml" data-lang=xml>&lt;dependency&gt;
  &lt;groupId&gt;com.clojure-goes-fast&lt;/groupId&gt;
  &lt;artifactId&gt;clj-async-profiler&lt;/artifactId&gt;
  &lt;version&gt;0.3.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
  &lt;groupId&gt;org.clojure&lt;/groupId&gt;
  &lt;artifactId&gt;clojure&lt;/artifactId&gt;
  &lt;version&gt;1.10.0&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>And then, we can use the API to invoke <code>clj-async-profiler</code> functions:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="6,8,12"><code class="language-java" data-lang=java>import clojure.java.api.Clojure;
import clojure.lang.IFn;

Clojure
  .var("clojure.core", "require")
  .invoke(Clojure.read("clj-async-profiler.core")); <i class="conum" data-value="1"></i>

Clojure.var("clj-async-profiler.core", "start").invoke(); <i class="conum" data-value="2"></i>

// code to profile...

System.out.println(Clojure.var("clj-async-profiler.core", "stop").invoke()); <i class="conum" data-value="3"></i>

// ...</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>Require the <code>core</code> package from the <code>clj-async-profiler</code> library</td>
          </tr>
<tr>
          <td><i class="conum" data-value="2"></i><b>2</b></td>
          <td>Start the profiler by calling the <code>start</code> function</td>
          </tr>
<tr>
          <td><i class="conum" data-value="3"></i><b>3</b></td>
          <td>Stop the profiler by calling the <code>stop</code> function and output the result</td>
          </tr>
</table>
</div>
<div class="paragraph">
  
  <p>The <code>stop</code> function will stop the profiler and return the path to the generated SVG visualization.</p>
</div>
<div class="paragraph">
  
  <p>And here&#8217;s the full example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-java" data-lang=java>package org.asciidoctor;

import clojure.java.api.Clojure;

import java.io.File;

public class App {
  public static void main(String[] args) {
    Asciidoctor asciidoctor = Asciidoctor.Factory.create();
    asciidoctor.requireLibrary("asciidoctor-diagram");
    File file = new File("doc.adoc");
    // Warm up the JIT...

    Clojure.var("clojure.core", "require")
      .invoke(Clojure.read("clj-async-profiler.core"));

    Clojure.var("clj-async-profiler.core", "start").invoke();
    for (int i = 0; i &lt; 100; i++) {
      asciidoctor.readDocumentHeader(file);
    }
    System.out.println(Clojure.var("clj-async-profiler.core", "stop").invoke());

    System.exit(0);
  }
}</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>When running this application, it will output the path to the generated SVG, for instance:</p>
</div>
<div class="literalblock ">
<div class="content">
<pre>/tmp/clj-async-profiler/results/flamegraph-2019-02-25-11-56-25.svg</pre> 
</div>
</div>
<div class="paragraph">
  
  <p>You can then open this file in your browser.</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Final outcome</h2>
<div class="paragraph">
  
  <p>In the end, Clojure had nothing to do with this performance issue.
We&#8217;ve discovered that the root cause was actually an overhead in the JRuby <code>Kernel#require_relative</code> method: <a href="https://github.com/jruby/jruby/issues/5618" class="bare">github.com/jruby/jruby/issues/5618</a>.
We&#8217;ve also made a few changes in the Asciidoctor diagram extension to call <code>require_relative</code> less frequently.</p>
</div>
<div class="paragraph">
  
  <p>Now AsciidoctorJ with the Asciidoctor diagram extension enabled is faster on JRuby 9 than on JRuby 1.7!<br>
And we also learned in the process how to easily generate a Flame graph using <em>clj-async-profiler</em> 🍻</p>
</div>
</section>]]></content:encoded>
  </item>
<item>
    <title><![CDATA[Awesome Antora: Migrate from GitBook to Antora]]></title>
    <description><![CDATA[😱 GitBook has dropped support for AsciiDoc! No worries, let's migrate to Antora where we can use AsciiDoc to its fullest extent.]]></description>
    <link>undefined</link>
    <category><![CDATA[Antora]]></category>
<category><![CDATA[Migration]]></category>
    <dc:creator><![CDATA[Guillaume Grossetie]]></dc:creator>
    <pubDate>Sat, 16 Feb 2019 09:00:00 GMT</pubDate>
    <media:content url="https://blog.yuzutech.fr/_/images/hiking.jpeg" medium="image"/>
    <content:encoded><![CDATA[<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
  
  <p>As you may already know, the new version of <a href="https://docs.gitbook.com/v2-changes/important-differences#asciidoc-support">GitBook has dropped support for AsciiDoc</a>.
And since you&#8217;re here, you probably enjoy writing documentation in <em>AsciiDoc</em> and you want to keep using it!
I have good news for you and it&#8217;s called <em>Antora</em>.</p>
</div>
</div>
</div>
<section class="section is-small">
<h2 class="title is-4">Antora</h2>
<div class="paragraph">
  
  <p><a href="https://antora.org/">Antora</a> is a documentation site generator and <em>AsciiDoc</em> is Antora&#8217;s native content markup language.
<a href="https://opendevise.com/">OpenDevise</a>, the company behind <em>Antora</em>, is also actively working on <em>Asciidoctor</em>, the reference implementation of the AsciiDoc syntax.</p>
</div>
<div class="paragraph">
  
  <p>In other words, the <em>AsciiDoc</em> syntax is a first class citizen in <em>Antora</em> and <em>Asciidoctor</em> is used at its full potential.</p>
</div>
<div class="paragraph">
  
  <p>Without further ado, let&#8217;s migrate from GitBook to Antora!</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Documentation component and modules</h2>
<div class="paragraph">
  
  <p>A collection of documentation files organized under Antora&#8217;s <a href="https://docs.antora.org/antora/2.0/component-structure/">standard project structure</a> is called a <em>documentation component</em>.<br>
In Antora&#8217;s terminology, a GitBook corresponds to a single documentation component in a single git repository.<br>
So the first thing you will need to do is to create a <a href="https://docs.antora.org/antora/2.0/component-structure/">documentation component</a> named <code>book</code> with a <a href="https://docs.antora.org/antora/2.0/modules/">module</a> named <code>ROOT</code>.</p>
</div>
<div class="box note">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-note">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>Here the module named <code>ROOT</code> will contain everything,
but depending on your use case you could create as many modules (or documentation components) as you want.</p>
</div>
      </div>
    </div>
  </article>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Create the structure</p>
<div class="literalblock ">
<div class="content">
<pre>$ mkdir -p book/modules/ROOT/pages</pre> 
</div>
</div>
</li>
<li>
<p>Move every *.adoc file to <em class="path">pages</em></p>
<div class="literalblock ">
<div class="content">
<pre>$ mv *.adoc book/modules/ROOT/pages</pre> 
</div>
</div>
</li>
</ol>
</div>
<div class="paragraph">
  
  <p>If you have images, attachments or videos, you will need to create the following subdirectories in your module:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><em class="path">assets/attachments</em></p>
</li>
<li>
<p><em class="path">assets/images</em></p>
</li>
<li>
<p><em class="path">assets/videos</em></p>
</li>
</ul>
</div>
<div class="paragraph">
  
  <p>And here&#8217;s the complete tree structure:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code>.
└── book
    └── modules
        └── ROOT
            ├── assets
            │   ├── attachments
            │   ├── images
            │   └── videos
            └── pages

8 directories</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>If your book is structured in chapters, you do not necessarily need to create a module for each chapter.
You can instead create &#8217;topic&#8217; subfolders in the <em class="path">pages</em> directory.</p>
</div>
<div class="paragraph">
  
  <p>Next, we need to describe our documentation component.</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Component descriptor</h2>
<div class="paragraph">
  
  <p>A documentation component must contain a <a href="https://docs.antora.org/antora/2.0/component-descriptor/">component descriptor</a> file named <code>antora.yml</code>.</p>
</div>
<div class="paragraph">
  
  <p>So let&#8217;s create a file named <code>antora.yml</code> in the <em class="path">book/</em> directory:</p>
</div>
<div class="listingblock">
<div class="listing-title">book/antora.yml</div>
<div class="content">
<pre class="nowrap"><code class="language-yml" data-lang=yml>name: book
title: Book
version: 'latest'
start_page: ROOT:overview.adoc</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>The keys and values are pretty much self explanatory.
Our component will be named <code>book</code>, its title will be <code>Book</code> and its version will be <code>latest</code>.</p>
</div>
<div class="paragraph">
  
  <p>We also explicitly define the start page.
By default, Antora looks for a file named <code>index.adoc</code> in the <code>ROOT</code> module.
So if your start page is already named <code>index.adoc</code>, you can remove the <code>start_page</code> key.</p>
</div>
<div class="box note">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-note">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>The name of the component is determined from the <code>name</code> key in the component descriptor.
In this migration guide, the component root directory is named <code>book</code> but this does not affect the name of the component (defined in the component descriptor file).</p>
</div>
      </div>
    </div>
  </article>
</div>
<div class="paragraph">
  
  <p>Check out the <a href="https://docs.antora.org/antora/2.0/component-descriptor/">component description documentation</a> to learn more.</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Playbook</h2>
<div class="paragraph">
  
  <p>GitBook allows you to customize your book using a configuration file named <code>book.json</code>.<br>
Similarly, Antora uses a <a href="https://docs.antora.org/antora/2.0/playbook/">playbook file</a> to control
what content is included in your site,
what user interface (UI) is applied to it,
and where the site is published.<br>
Playbooks can be written in YAML, JSON, and TOML.</p>
</div>
<div class="paragraph">
  
  <p>In the following examples, we will be using YAML (but you&#8217;re free to use JSON or TOML):</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Content</h2>
<div class="paragraph">
  
  <p>In the previous section we&#8217;ve created a documentation component called <code>book</code>.
The next step is to register this documentation component in our playbook.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Create a file named <code>antora-playbook.yml</code> at the root of your git repository:</p>
<div class="listingblock">
<div class="listing-title">antora-playbook.yml</div>
<div class="content">
<pre class="nowrap"><code class="language-yml" data-lang=yml>content:
  sources:
  - url: .
    start_path: book</code></pre>
</div>
</div>
</li>
</ol>
</div>
<div class="paragraph">
  
  <p>Since we are working with a local repository we are using the value dot (<code>.</code>).<br>
The path will be resolved relative to the location of the playbook file.</p>
</div>
<div class="paragraph">
  
  <p>The <code>start_path</code> value points to our documentation component located in the <code>book</code> directory (and also named <code>book</code>).</p>
</div>
<div class="box note">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-note">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>For ease of migration, this guide is recommending a particular very simple, but restrictive, layout in a single git repository.
In a playbook <code>sources</code> entry, there are two keys expressing the relationship between the playbook, the git repository of the source, and the location of the component descriptor.
For a local repository, the <code>url</code> will be the path from the playbook to the root of the git repository.
The <code>start_path</code> is the path from the root of the git repository to the <code>antora.yml</code> component descriptor.</p>
</div>
      </div>
    </div>
  </article>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Attributes</h2>
<div class="paragraph">
  
  <p>The <code>attributes</code> key in your playbook file can be used to define global (i.e. site-wide) AsciiDoc document attributes.</p>
</div>
<div class="listingblock">
<div class="listing-title">antora-playbook.yml</div>
<div class="content">
<pre class="nowrap"><code class="language-yml" data-lang=yml>asciidoc:
  attributes:
    spark-version: '2.1.0'
    sourcedir: 'src/main/scala'</code></pre>
</div>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Google Analytics</h2>
<div class="paragraph">
  
  <p>Antora has built-in support for Google Analytics.
To enable it, you will need to configure your key in <code>site.keys.google_analytics</code>.</p>
</div>
<div class="listingblock">
<div class="listing-title">antora-playbook.yml</div>
<div class="content">
<pre class="nowrap"><code class="language-yml" data-lang=yml>site:
  keys:
    google_analytics: 'UA-86782445-4'</code></pre>
</div>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Navigation</h2>
<div class="paragraph">
  
  <p>With Antora, you can create your site&#8217;s navigation with AsciiDoc and store it right alongside your documentation files.</p>
</div>
<div class="paragraph">
  
  <p>GitBook uses a <code>SUMMARY.adoc</code> file to define the structure of chapters and subchapters of the book.
Here&#8217;s an example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-adoc" data-lang=adoc>= Summary

. link:part1/README.adoc[Part I]
.. link:part1/writing.adoc[Writing is nice]
.. link:part1/antora.adoc[Antora is nice]
. link:part2/README.adoc[Part II]
.. link:part2/feedback_please.adoc[We love feedback]
.. link:part2/better_tools.adoc[Better tools for authors]</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>In Antora, you need to define the key <code>nav</code> in the <code>antora.yml</code> file:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Edit the file <code>antora.yml</code> in the <em class="path">book/</em> directory:</p>
<div class="listingblock">
<div class="listing-title">book/antora.yml</div>
<div class="content">
<pre class="nowrap"><code class="language-yml" data-lang=yml>name: book
title: Book
version: 'latest'
start_page: ROOT:overview.adoc
nav:
- modules/ROOT/nav.adoc</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>The <code>nav</code> key accepts a list of navigation files.
Each value specifies the path to a navigation file (e.g., modules/module-name/nav.adoc).
The order of the values dictates the order the contents of the navigation files are assembled in the published component menu.</p>
</div>
</li>
<li>
<p>Create a file named <code>nav.adoc</code> in the <em class="path">book/modules/ROOT</em> directory:</p>
<div class="listingblock">
<div class="listing-title">book/modules/ROOT/nav.adoc</div>
<div class="content">
<pre class="nowrap"><code class="language-adoc" data-lang=adoc>.xref:index.adoc[In-module page]
* xref:a-page-in-this-module.adoc[Another in-module page]
** xref:another-page.adoc#and-fragment[An in-module page deep link]
* xref:topic/page.adoc[In-module page in a topic folder]</code></pre>
</div>
</div>
</li>
</ol>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Links between pages</h2>
<div class="paragraph">
  
  <p>If you use the published URL in your links, I would recommend to start using cross-references.
In Antora, you can create a link between pages using the <code>xref</code> macro.
For instance, to create a link to a page in the same module, you should use:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-adoc" data-lang=adoc>xref:error-handling.adoc[Error Handling]</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>And here&#8217;s the syntax to create a link to a page in a topic folder:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-adoc" data-lang=adoc>xref:concept/index.adoc[Key Concepts]</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>As we&#8217;ve seen before images are stored in a directory named <em class="path">assets/images</em>.
To insert an image, we need to use the AsciiDoc block image macro (<code>image::[]</code>).
Let&#8217;s say we have an image called <em>pipeline-workflow.png</em> in <em class="path">assets/images</em>.
Here&#8217;s the syntax to add it to a page.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-adoc" data-lang=adoc>image::pipeline-workflow.png[a diagram illustrating the pipeline stages]</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>As you can see, we don&#8217;t need to use a relative path or to define the <code>imagesdir</code>.
So in most cases, you should be able to simplify the path to your linked resources.</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Example</h2>
<div class="paragraph">
  
  <p>We will be using the "Spark Streaming Notebook" as an example.
The source code of this book is available on GitHub: <a href="https://github.com/jaceklaskowski/spark-streaming-notebook" class="bare">github.com/jaceklaskowski/spark-streaming-notebook</a></p>
</div>
<div class="paragraph">
  
  <p>Here&#8217;s the <code>book.json</code> file:</p>
</div>
<div class="listingblock">
<div class="listing-title">book.json</div>
<div class="content">
<pre class="nowrap"><code class="language-json" data-lang=json>{
  "structure": {
    "readme": "book-intro.adoc"
  },
  "variables": {
    "spark.version": "2.1.0",
    "sourcedir": "src/main/scala"
  },
  "plugins": ["ga"],
  "pluginsConfig": {
    "ga": {
      "token": "UA-86782445-4"
    }
  }
}</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>And here&#8217;s the equivalent configuration in Antora:</p>
</div>
<div class="listingblock">
<div class="listing-title">antora-playbook.yml</div>
<div class="content">
<pre class="nowrap"><code class="language-yml" data-lang=yml>site:
  title: Spark Streaming
  url: https://jaceklaskowski.github.io/spark-streaming-notebook
  start_page: book::intro.adoc
  keys:
    google_analytics: 'UA-86782445-4'
content:
  sources:
  - url: .
    start_path: book
asciidoc:
  attributes:
    spark-version: '2.1.0'
    sourcedir: 'src/main/scala'</code></pre>
</div>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Generate your site</h2>
<div class="paragraph">
  
  <p>To get you started quickly, Antora provides a default UI.
To use it, edit your <code>antora-playbook.yml</code> file and add the following content:</p>
</div>
<div class="listingblock">
<div class="listing-title">antora-playbook.yml</div>
<div class="content">
<pre class="nowrap"><code class="language-yml" data-lang=yml>ui:
  bundle:
    url: https://gitlab.com/antora/antora-ui-default/-/jobs/artifacts/master/raw/build/ui-bundle.zip?job=bundle-stable
    snapshot: true</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Then, configure the output directory to define where the generated site will be published.
Again, edit your <code>antora-playbook.yml</code> file and add the following content:</p>
</div>
<div class="listingblock">
<div class="listing-title">antora-playbook.yml</div>
<div class="content">
<pre class="nowrap"><code class="language-yml" data-lang=yml>output:
  dir: ./public</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>We&#8217;re almost done.
If that&#8217;s not already the case, please <a href="https://docs.antora.org/antora/2.0/install/install-antora/">install Antora</a> on your machine.
Then, open a terminal and type:</p>
</div>
<div class="literalblock ">
<div class="content">
<pre>$ antora antora-playbook.yml</pre> 
</div>
</div>
<div class="paragraph">
  
  <p>Your site should be generated in the <code>public/</code> directory 🚀</p>
</div>
</section>]]></content:encoded>
  </item>
<item>
    <title><![CDATA[Awesome Asciidoctor.js: Catch processing errors and warnings using an in-memory logger]]></title>
    <description><![CDATA[Since Asciidoctor.js 1.5.7, all warning and error messages are now routed through a logger. With this new feature, we will see how to catch processing errors and warnings using the built-in in-memory logger.]]></description>
    <link>undefined</link>
    <category><![CDATA[Asciidoctor.js]]></category>
<category><![CDATA[Logger]]></category>
<category><![CDATA[JavaScript]]></category>
    <dc:creator><![CDATA[Guillaume Grossetie]]></dc:creator>
    <pubDate>Thu, 15 Nov 2018 12:20:00 GMT</pubDate>
    <media:content url="https://blog.yuzutech.fr/_/images/pipeline.jpg" medium="image"/>
    <content:encoded><![CDATA[<div class="paragraph">
  
  <p>The new logging system introduces in Asciidoctor.js, can be used to catch processing errors and warnings.
It can be really useful in a CI build when you want to make sure that your documentation is perfect before publishing it.</p>
</div>
<div class="paragraph">
  
  <p>The in-memory logger stores every warning and error messages generated by the Asciidoctor.js processor.
Once the processing is done, you can retrieve all these messages using the <code>getMessages</code> function:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-js" data-lang=js>const asciidoctor = require('asciidoctor.js')()
const loggerManager = asciidoctor.LoggerManager
const memoryLogger = asciidoctor.MemoryLogger.$new()
loggerManager.setLogger(memoryLogger)

asciidoctor.convert('input')

memoryLogger.getMessages() // returns an array of Message</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>For every message, you can get the following information:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="2,3,4,6,7,8,9"><code class="language-js" data-lang=js>const message = memoryLogger.getMessages()[0]
console.log(message.getSeverity()) <i class="conum" data-value="1"></i>
console.log(message.getText()) <i class="conum" data-value="2"></i>
const sourceLocation = message.getSourceLocation() <i class="conum" data-value="3"></i>
if (sourceLocation) {
  console.log(sourceLocation.getLineNumber()) <i class="conum" data-value="4"></i>
  console.log(sourceLocation.getFile()) <i class="conum" data-value="5"></i>
  console.log(sourceLocation.getDirectory()) <i class="conum" data-value="6"></i>
  console.log(sourceLocation.getPath()) <i class="conum" data-value="7"></i>
}</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>returns the severity (<code>ERROR</code> or <code>WARNING</code>)</td>
          </tr>
<tr>
          <td><i class="conum" data-value="2"></i><b>2</b></td>
          <td>returns the error or warning text message</td>
          </tr>
<tr>
          <td><i class="conum" data-value="3"></i><b>3</b></td>
          <td>returns the context about the source location (can be undefined)</td>
          </tr>
<tr>
          <td><i class="conum" data-value="4"></i><b>4</b></td>
          <td>returns the source line number associated to the message</td>
          </tr>
<tr>
          <td><i class="conum" data-value="5"></i><b>5</b></td>
          <td>returns the file name associated to the message (or <code>undefined</code> when converting from a String)</td>
          </tr>
<tr>
          <td><i class="conum" data-value="6"></i><b>6</b></td>
          <td>returns the absolute path to the source file parent directory, or the execution path when converting from a String</td>
          </tr>
<tr>
          <td><i class="conum" data-value="7"></i><b>7</b></td>
          <td>returns the path associated to the message (or <code>&lt;stdin&gt;</code> when converting from a String)</td>
          </tr>
</table>
</div>
<div class="paragraph">
  
  <p>You could then check if there&#8217;s any error and fail your CI build using <code>process.exit()</code> function:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-js" data-lang=js>const messages = memoryLogger.getMessages()
const errors = messages.filter(message =&gt; message.getSeverity() === 'ERROR')
if (errors &amp;&amp; errors.length &gt; 0) {
  console.log(`${errors.length} errors thrown during the documentation generation, exiting.`)
  process.exit(1)
} else {
  // all good, continuing...
}</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Written with Asciidoctor.js 1.5.9.</p>
</div>]]></content:encoded>
  </item>
<item>
    <title><![CDATA[Awesome GraalVM: Create a Java API on top of a JavaScript library]]></title>
    <description><![CDATA[Let's see how we can use the GraalVM Polyglot API to create a Java API on top of the chroma JavaScript library.]]></description>
    <link>undefined</link>
    <category><![CDATA[GraalVM]]></category>
<category><![CDATA[JavaScript]]></category>
<category><![CDATA[Java]]></category>
    <dc:creator><![CDATA[Guillaume Grossetie]]></dc:creator>
    <pubDate>Thu, 22 Nov 2018 20:40:00 GMT</pubDate>
    <media:content url="https://blog.yuzutech.fr/_/images/us.jpg" medium="image"/>
    <content:encoded><![CDATA[<div class="paragraph">
  
  <p>The Graal Polyglot API lets you embed and run code from guest languages in JVM-based host applications.
In this article, we will cover how we create a Java API on top of a JavaScript library.</p>
</div>
<div class="paragraph">
  
  <p>With more than 700 000 packages <a href="https://www.npmjs.com/">npmjs</a> is the world&#8217;s largest repository of code!
You can find literally everything you need (or not).</p>
</div>
<div class="paragraph">
  
  <p>For our example we will use the excellent <a href="https://gka.github.io/chroma.js/#color-rgba">chroma.js</a> library.
<em>chroma.js</em> is a tiny JavaScript library (but really useful) for dealing with colors!<br>
Here&#8217;s an example for a simple read / manipulate / output chain:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-js" data-lang=js>chroma('pink').darken().saturate(2).hex() // "#ff6d93"</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Pretty cool right ?<br>
Now let&#8217;s see how we can use this library in a Java application that runs on GraalVM.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>First download and copy <a href="https://raw.github.com/gka/chroma.js/master/chroma.min.js">chroma.min.js</a> to your project <em>resources</em>.</p>
</li>
<li>
<p>Add a dependency on the GraalVM SDK (that contains the Polyglot API):</p>
<div class="listingblock">
<div class="listing-title">maven</div>
<div class="content">
<pre class="nowrap"><code class="language-xml" data-lang=xml>&lt;dependency&gt;
  &lt;groupId&gt;org.graalvm&lt;/groupId&gt;
  &lt;artifactId&gt;graal-sdk&lt;/artifactId&gt;
  &lt;version&gt;1.0.0-rc7&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
</div>
</div>
<div class="listingblock">
<div class="listing-title">gradle</div>
<div class="content">
<pre class="nowrap"><code>compile 'org.graalvm:graal-sdk:1.0.0-rc7'</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>If you are using another package manager, <a href="https://search.maven.org/artifact/org.graalvm/graal-sdk/1.0.0-rc7/jar">follow the instructions on Maven Central</a>.</p>
</div>
</li>
<li>
<p>Use the GraalVM Polyglot API to evaluate the <em>chroma</em> library.<br>
Now that we can use the <code>org.graalvm.polyglot</code> API in our code,
we are going to create a singleton class named <code>GraalVMChroma</code> in the <code>org.chroma</code> package:</p>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="18,20,21,22"><code class="language-java" data-lang=java>package org.chroma;

import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;

public class GraalVMChroma {

  private final Value chroma;
  private static GraalVMChroma instance = null;

  private GraalVMChroma() {
    Context context = Context.create(); <i class="conum" data-value="1"></i>
    URL chromaResource = Thread.currentThread().getContextClassLoader().getResource("chroma.min.js");
    String content = new String(Files.readAllBytes(Paths.get(chromaResource.toURI()))); <i class="conum" data-value="2"></i>
    context.eval("js", content); <i class="conum" data-value="3"></i>
    chroma = context.eval("js", "chroma"); <i class="conum" data-value="4"></i>
  }

  public static GraalVMChroma create() {
    if (instance == null) {
      instance = new GraalVMChroma();
    }
    return instance;
  }

  public Value getChroma() {
    return chroma;
  }
}</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>Create a GraalVM <code>Context</code></td>
          </tr>
<tr>
          <td><i class="conum" data-value="2"></i><b>2</b></td>
          <td>Read the file <em>chroma.min.js</em> into a <code>String</code></td>
          </tr>
<tr>
          <td><i class="conum" data-value="3"></i><b>3</b></td>
          <td>Evaluate the library code</td>
          </tr>
<tr>
          <td><i class="conum" data-value="4"></i><b>4</b></td>
          <td>Get the <code>chroma</code> object as a GraalVM <code>Value</code></td>
          </tr>
</table>
</div>
<div class="paragraph">
  
  <p>In the code above, the file <em>chroma.min.js</em> will be read from the classpath and turned into a <code>String</code>.
Then we evaluate the <em>chroma</em> library code, using the <code>eval</code> method on the <code>context</code>.
And finally, we use <code>eval("js", "chroma")</code> to get the <code>chroma</code> object.</p>
</div>
<div class="box note">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-note">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>The GraalVM <code>Value</code> represents a polyglot value that can be accessed using a set of language agnostic operations.
Polyglot values have one of the following types:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>Null</code></p>
</li>
<li>
<p><code>Number</code></p>
</li>
<li>
<p><code>Boolean</code></p>
</li>
<li>
<p><code>String</code></p>
</li>
<li>
<p><code>Host Object</code></p>
</li>
<li>
<p><code>Proxy Object</code></p>
</li>
<li>
<p><code>Native Pointer</code></p>
</li>
</ul>
</div>
<div class="paragraph">
  
  <p>In addition any value may have one or more of the following traits:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>Array Elements</code></p>
</li>
<li>
<p><code>Members</code></p>
</li>
<li>
<p><code>Executable</code></p>
</li>
<li>
<p><code>Instantiable</code></p>
</li>
</ul>
</div>
<div class="paragraph">
  
  <p>If you want to learn more about GraalVM <code>Value</code>, please read the  <a href="https://www.graalvm.org/sdk/javadoc/index.html?org/graalvm/polyglot/Value.html">official documentation</a>.</p>
</div>
      </div>
    </div>
  </article>
</div>
<div class="paragraph">
  
  <p>In our case, the <code>chroma</code> object is an <em>Instantiable</em> as we can instantiate a new <em>chroma</em> object with <code>chroma('hotpink')</code>.</p>
</div>
</li>
<li>
<p>Build a Java API.<br>
We create a <code>Chroma</code> interface in the <code>org.chroma</code> package:</p>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="21,22,23"><code class="language-java" data-lang=java>package org.chroma;

import org.graalvm.polyglot.Value;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

public interface Chroma {

  Chroma darken();

  Chroma saturate(int value);

  String hex();

  List&lt;Integer&gt; rgba();

  static Chroma create(String color) {
    try {
      Value chroma = GraalVMChroma.create().getChroma(); <i class="conum" data-value="1"></i>
      Value instance = chroma.newInstance(color); <i class="conum" data-value="2"></i>
      return new ChromaInstance(instance); <i class="conum" data-value="3"></i>
    } catch (IOException | URISyntaxException e) {
      throw new RuntimeException("Unable to instantiate Chroma GraalVM");
    }
  }
}</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>Get the <code>chroma</code> object on the singleton</td>
          </tr>
<tr>
          <td><i class="conum" data-value="2"></i><b>2</b></td>
          <td>Instantiate the <code>chroma</code> object with a color</td>
          </tr>
<tr>
          <td><i class="conum" data-value="3"></i><b>3</b></td>
          <td>Instantiate a Java class named <code>ChromaInstance</code> with the <em>chroma</em> instance</td>
          </tr>
</table>
</div>
</li>
<li>
<p>Implement the API.<br>
The <code>ChromaInstance</code> implements the <code>Chroma</code> interface:</p>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="13,18,23,28,34"><code class="language-java" data-lang=java>package org.chroma;

import org.graalvm.polyglot.Value;

import java.util.ArrayList;
import java.util.List;

public class ChromaInstance implements Chroma {

  private Value chromaInstance;

  public ChromaInstance(Value chromaInstance) {
    this.chromaInstance = chromaInstance; <i class="conum" data-value="1"></i>
  }

  @Override
  public Chroma darken() {
    return new ChromaInstance(chromaInstance.getMember("darken").execute()); <i class="conum" data-value="2"></i>
  }

  @Override
  public Chroma saturate(int value) {
    return new ChromaInstance(chromaInstance.getMember("saturate").execute(value)); <i class="conum" data-value="3"></i>
  }

  @Override
  public String hex() {
    return chromaInstance.getMember("hex").execute().asString(); <i class="conum" data-value="4"></i>
  }

  @Override
  public List&lt;Integer&gt; rgba() {
    List&lt;Integer&gt; result = new ArrayList&lt;&gt;();
    Value value = chromaInstance.getMember("rgba").execute(); <i class="conum" data-value="5"></i>
    if (value.hasArrayElements()) {
      for (int i = 0; i &lt; value.getArraySize(); i++) {
        result.add(value.getArrayElement(i).asInt());
      }
    }
    return result;
  }
}</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>Save the reference to the <em>chroma</em> instance</td>
          </tr>
<tr>
          <td><i class="conum" data-value="2"></i><b>2</b></td>
          <td>Get the member called <code>darken</code> on the <em>chroma</em> instance and execute the function</td>
          </tr>
<tr>
          <td><i class="conum" data-value="3"></i><b>3</b></td>
          <td>Get the member called <code>saturate</code> on the <em>chroma</em> instance and execute the function with a value</td>
          </tr>
<tr>
          <td><i class="conum" data-value="4"></i><b>4</b></td>
          <td>Get the member called <code>hex</code> on the <em>chroma</em> instance, execute the function and return a <code>String</code></td>
          </tr>
<tr>
          <td><i class="conum" data-value="5"></i><b>5</b></td>
          <td>Get the member called <code>rgba</code> on the <em>chroma</em> instance, execute the function and build a Java <code>List</code> from the <em>Array Elements</em> <code>Value</code></td>
          </tr>
</table>
</div>
</li>
</ol>
</div>
<div class="paragraph">
  
  <p>And now we can use the <code>chroma</code> library in our Java application as follow:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-java" data-lang=java>Chroma.create("pink").darken().saturate(2).hex() // "#ff6d93"

Chroma.create("orange").rgba() // List(255, 165, 0, 1)</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Written with GraalVM 1.0.0-rc7 and Java 1.8.<br>
<svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="github-alt" class="svg-inline--fa fa-github-alt fa-w-15" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 512"><path fill="currentColor" d="M186.1 328.7c0 20.9-10.9 55.1-36.7 55.1s-36.7-34.2-36.7-55.1 10.9-55.1 36.7-55.1 36.7 34.2 36.7 55.1zM480 278.2c0 31.9-3.2 65.7-17.5 95-37.9 76.6-142.1 74.8-216.7 74.8-75.8 0-186.2 2.7-225.6-74.8-14.6-29-20.2-63.1-20.2-95 0-41.9 13.9-81.5 41.5-113.6-5.2-15.8-7.7-32.4-7.7-48.8 0-21.5 4.9-32.3 14.6-51.8 45.3 0 74.3 9 108.8 36 29-6.9 58.8-10 88.7-10 27 0 54.2 2.9 80.4 9.2 34-26.7 63-35.2 107.8-35.2 9.8 19.5 14.6 30.3 14.6 51.8 0 16.4-2.6 32.7-7.7 48.2 27.5 32.4 39 72.3 39 114.2zm-64.3 50.5c0-43.9-26.7-82.6-73.5-82.6-18.9 0-37 3.4-56 6-14.9 2.3-29.8 3.2-45.1 3.2-15.2 0-30.1-.9-45.1-3.2-18.7-2.6-37-6-56-6-46.8 0-73.5 38.7-73.5 82.6 0 87.8 80.4 101.3 150.4 101.3h48.2c70.3 0 150.6-13.4 150.6-101.3zm-82.6-55.1c-25.8 0-36.7 34.2-36.7 55.1s10.9 55.1 36.7 55.1 36.7-34.2 36.7-55.1-10.9-55.1-36.7-55.1z"></path></svg> The full source code is available on GitHub: <a href="https://github.com/yuzutech/chroma-graalvm" class="bare">github.com/yuzutech/chroma-graalvm</a></p>
</div>]]></content:encoded>
  </item>
<item>
    <title><![CDATA[Delicious Docker: Build minimal containers]]></title>
    <description><![CDATA[🐳 Build minimal containers for your application written in Go, Haskell, Rust, Node.js or Java!]]></description>
    <link>undefined</link>
    <category><![CDATA[Docker]]></category>
    <dc:creator><![CDATA[Guillaume Grossetie]]></dc:creator>
    <pubDate>Mon, 13 Apr 2020 19:00:00 GMT</pubDate>
    <media:content url="https://blog.yuzutech.fr/_/images/ant.jpeg" medium="image"/>
    <content:encoded><![CDATA[<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
  
  <p>It&#8217;s a common best practice in the Docker community to keep containers as small as possible.
There are a few reasons for this:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>small images are faster to copy around,</p>
</li>
<li>
<p>they are faster to start,</p>
</li>
<li>
<p>by removing unnecessary components from your image, you reduce the attack surface.</p>
</li>
</ul>
</div>
<div class="paragraph">
  
  <p>While working on <a href="https://kroki.io" target="_blank" rel="noopener">Kroki</a>, one of my goal was to build minimal containers.
To give you a bit of context, Kroki provides a unified API on top of more than a dozen diagrams libraries.
And as you might have guessed, each diagram library has specific requirements and runtime!
As a matter of fact, they are written in various programming language: Haskell, Go, Java, Node.js, Python&#8230;&#8203;</p>
</div>
</div>
</div>
<section class="section is-small">
<h2 class="title is-4">Action plan</h2>
<div class="paragraph">
  
  <p>I took the following approach:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>create an image from <a href="https://hub.docker.com/_/scratch" target="_blank" rel="noopener">scratch</a> (literally <code>FROM scratch</code>).</p>
</li>
<li>
<p>build a statically linked binary (for each diagram library) that can run on top of <em>scratch</em>!</p>
</li>
</ol>
</div>
<div class="paragraph">
  
  <p>In this article, I will describe a few tools and techniques I&#8217;ve discovered along the way.
Let&#8217;s start with the easiest first!</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Haskell</h2>
<div class="paragraph">
  
  <p>For reference, I&#8217;ve never written a single line of Haskell and I&#8217;m not familiar with the Haskell ecosystem.
But surprisingly, it was relatively easy to create a statically linked binary thanks to this <a href="https://vaibhavsagar.com/blog/2018/01/03/static-haskell-nix/" target="_blank" rel="noopener">great article by Vaibhav Sagar</a>.</p>
</div>
<div class="paragraph">
  
  <p>One thing led to another, <a href="https://github.com/nh2" target="_blank" rel="noopener">Niklas Hambüchen</a> and <a href="https://github.com/mmzx" target="_blank" rel="noopener">Akos Marton</a> helped me to setup an even easier build based on <em>Stack</em>.</p>
</div>
<div class="paragraph">
  
  <p>My goal here was to build a statically linked binary of <a href="https://github.com/BurntSushi/erd" target="_blank" rel="noopener">Erd</a>.
If you don&#8217;t know this utility, it can translate a plain text description of a relational database schema to a graphical entity-relationship diagram.
The visualization is produced by using dot from <em>GraphViz</em>.</p>
</div>
<div class="paragraph">
  
  <p>Starting with Docker 17.05, we can use <a href="https://docs.docker.com/develop/develop-images/multistage-build/" target="_blank" rel="noopener">multi-stage build</a>.
Basically, we can use different base images, and each of them begins a new stage of the build.</p>
</div>
<div class="paragraph">
  
  <p>In our case, we will define two steps:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The first step will use an Ubuntu image to build the project and create a static binary using <em>stack</em>.</p>
</li>
<li>
<p>The second step will copy the static binary built at the first step in a <em>scratch</em> image.</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-dockerfile" data-lang=dockerfile># step 1: build a static binary
FROM ubuntu:18.04 AS builder

RUN apt-get update &amp;&amp; apt-get install -y graphviz curl git

RUN curl -sSL https://get.haskellstack.org/ | sh

RUN git clone https://github.com/BurntSushi/erd.git

WORKDIR erd

RUN git checkout v0.2.0.0

RUN /usr/local/bin/stack install --ghc-options="-fPIC" \
  --ghc-options="-static" \
  --ghc-options="-optl=-static" \
  --ghc-options="-optc=-static"

# step 2: build a small image
FROM scratch

COPY --from=builder /root/.local/bin/erd /haskell/bin/erd

ENTRYPOINT ["/haskell/bin/erd"]</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>And here&#8217;s the result, a 21 MB image:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code>REPOSITORY         TAG           SIZE
scratch-erd        latest        21MB</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>For reference, here&#8217;s the size of the <code>haskell:8</code> image:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code>REPOSITORY         TAG           SIZE
haskell            8.8.3         1.47GB</code></pre>
</div>
</div>
<div class="box note">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-note">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>Please note that, in this specific example, the GraphViz library is still required at runtime.</p>
</div>
<div class="paragraph">
  
  <p>To workaround this issue, we could instead use an <a href="https://hub.docker.com/_/alpine" target="_blank" rel="noopener">Alpine</a> base image and install GraphViz using <code>RUN apk add --update --no-cache graphviz</code>.</p>
</div>
      </div>
    </div>
  </article>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Rust</h2>
<div class="paragraph">
  
  <p>Stefan Seemayer describes in a blog post <a href="https://blog.semicolonsoftware.de/building-minimal-docker-containers-for-rust-applications/" target="_blank" rel="noopener">how to statically compile an 'Hello World' server in Rust</a>.
In this article, Stefan is <em>not</em> using a multi-stage build.
Instead, the current working directory is mapped into the container:</p>
</div>
<div class="literalblock ">
<div class="content">
<pre>$ alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src ekidd/rust-musl-builder'
$ rust-musl-builder cargo build --release</pre> 
</div>
</div>
<div class="paragraph">
  
  <p>To be consistent, we will use the <code>ekidd/rust-musl-builder</code> image in a multi-stage build:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-dockerfile" data-lang=dockerfile># step 1: build a static binary
FROM ekidd/rust-musl-builder:stable AS builder

RUN cargo install --version 0.4.2 svgbob_cli

# step 2: build a small image
FROM scratch

COPY --from=builder /home/rust/.cargo/bin/svgbob /rust/bin/svgbob

ENTRYPOINT ["/rust/bin/svgbob"]</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Nothing fancy here, we are using the <code>cargo</code> command line to install a pre-built binary of <code>svgbob</code> from <a href="https://crates.io/crates/svgbob_cli" target="_blank" rel="noopener">crates.io</a>.</p>
</div>
<div class="paragraph">
  
  <p>And here&#8217;s the result, a 4 MB image:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code>REPOSITORY        TAG       SIZE
scratch-svgbob    latest    4.01MB</code></pre>
</div>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Go</h2>
<div class="paragraph">
  
  <p>It comes at no surprise that someone already wrote a great blog post on <a href="https://medium.com/@chemidy/create-the-smallest-and-secured-golang-docker-image-based-on-scratch-4752223b7324" target="_blank" rel="noopener">how to create the smallest Golang Docker image</a>.
In this blog post, Cyrille Hemidy, points out that the <em>official</em> Docker image for Go is 779 MB!</p>
</div>
<div class="paragraph">
  
  <p>Here, we&#8217;re using the same approach described above with a multi-stage build:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-dockerfile" data-lang=dockerfile># step 1: build a static binary
FROM golang:alpine AS builder

RUN apk add --update --no-cache git

RUN git clone https://github.com/yuzutech/kroki-cli.git
WORKDIR kroki-cli
RUN git checkout v0.3.0

RUN go get -d -v

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o /go/bin/kroki

# step 2: build a small image
FROM scratch

COPY --from=builder /go/bin/kroki /go/bin/kroki

ENTRYPOINT ["/go/bin/kroki"]</code></pre>
</div>
</div>
<div class="box important">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-important">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="exclamation-circle" class="svg-inline--fa fa-exclamation-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zm-248 50c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>If you are using Go &lt; 1.10, dont forget to add <code>CGO_ENABLED=0</code> otherwise you will get the following error when trying to run the binary:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code>standard_init_linux.go:211: exec user process caused "no such file or directory"</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>This obscure message means that a dynamic library is missing because the binary is not statically linked.</p>
</div>
      </div>
    </div>
  </article>
</div>
<div class="paragraph">
  
  <p>And here&#8217;s the result, from 779 MB to less than 10 MB:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code>REPOSITORY         TAG           SIZE
scratch-kroki      latest        8.91MB</code></pre>
</div>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Node.js</h2>
<div class="paragraph">
  
  <p>As we&#8217;ve seen above, building a statically linked binary is relatively easy in an Haskell, Rust or Go ecosystem.
But what about Node.js?</p>
</div>
<div class="paragraph">
  
  <p>Thanks to <a href="https://github.com/zeit/pkg" target="_blank" rel="noopener">pkg</a>, it&#8217;s possible to package a Node.js application into an executable that can be run even on containers without Node.js installed.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-dockerfile" data-lang=dockerfile># step 1: build a single binary
FROM node:12.16.2-alpine3.11 AS builder

# Workaround: https://github.com/nodejs/docker-node/issues/813#issuecomment-407339011
# Error: could not get uid/gid
# [ 'nobody', 0 ]
RUN npm config set unsafe-perm true

RUN npm install -g pkg pkg-fetch
ENV NODE node10
ENV PLATFORM alpine
ENV ARCH x64
RUN /usr/local/bin/pkg-fetch ${NODE} ${PLATFORM} ${ARCH}

RUN apk add --update --no-cache git

RUN git clone https://github.com/skanaar/nomnoml.git
WORKDIR nomnoml
RUN git checkout v0.6.2

RUN npm i
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM}-${ARCH} dist/nomnoml-cli.js -o nomnoml.bin

# step 2: build a small image
FROM alpine:3.11

COPY --from=builder /nomnoml/nomnoml.bin /node/bin/nomnoml

RUN apk add --no-cache libstdc++

ENTRYPOINT ["/node/bin/nomnoml"]</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>In the example above, we are using <code>pkg</code> to create a binary from the <a href="https://github.com/skanaar/nomnoml" target="_blank" rel="noopener">Nomnoml</a> diagram library but the logic can be applied to almost any Node.js project.
As you can see, we get the sources from GitHub, then we install the dependencies using <code>npm i</code>, and finally we execute the <code>pkg</code> command line to produce a binary named <code>nomnoml.bin</code> from the <code>dist/nomnoml-cli.js</code> file.</p>
</div>
<div class="box important">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-important">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="exclamation-circle" class="svg-inline--fa fa-exclamation-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zm-248 50c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>Please note that the binary is not statically linked. If you run <code>ldd</code> on the binary you will get:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-console" data-lang=console>$ ldd /nomnoml/nomnoml.bin
	/lib/ld-musl-x86_64.so.1 (0x7fc3d3bc4000)
	libstdc++.so.6 =&gt; /usr/lib/libstdc++.so.6 (0x7fc3d168a000)
	libgcc_s.so.1 =&gt; /usr/lib/libgcc_s.so.1 (0x7fc3d1676000)
	libc.musl-x86_64.so.1 =&gt; /lib/ld-musl-x86_64.so.1 (0x7fc3d3bc4000)</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>That&#8217;s why we are not building the image <code>FROM scratch</code> but <code>FROM alpine:3.11</code> to make sure that the system shared libraries will be available and compatible.</p>
</div>
      </div>
    </div>
  </article>
</div>
<div class="paragraph">
  
  <p>And here&#8217;s the result:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code>REPOSITORY         TAG           SIZE
alpine-nomnoml     latest        50.9MB</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>That&#8217;s still not bad for an Alpine based image.
For reference, the builder base image <code>node:12.16.2-alpine3.11</code> (also based on Alpine) is about 90MB.</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Java</h2>
<div class="paragraph">
  
  <p>With <a href="https://www.graalvm.org/" target="_blank" rel="noopener">GraalVM</a> and <a href="https://quarkus.io/" target="_blank" rel="noopener">Quarkus</a> it&#8217;s now possible to build native images that generate a native binary but it has a few <a href="https://github.com/oracle/graal/blob/master/substratevm/LIMITATIONS.md" target="_blank" rel="noopener">limitations</a>.
If you can, you should definitely build a native binary but if you cannot then one solution is to use Alpine as a base image.</p>
</div>
<section class="section is-small">
<h2 class="title is-5">Alpine Linux</h2>
<div class="paragraph">
  
  <p>The main benefit is that Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.
But the main caveat is that it does use <a href="http://www.musl-libc.org/" target="_blank" rel="noopener">musl libc</a> instead of <a href="http://www.etalabs.net/compare_libcs.html" target="_blank" rel="noopener">glibc and friends</a>, so certain software might run into issues depending on the depth of their libc requirements.
However, most software doesn&#8217;t have an issue with this, so this variant is usually a very safe choice.<br></p>
</div>
<div class="paragraph">
  
  <p>Keep in mind that, since Alpine is not officially supported, the OpenJDK organization on Docker only publish Early Access versions of the JDK on Alpine.
So, if you want to use a stable version of the JDK, you should instead use the Docker images produced by the <a href="https://adoptopenjdk.net/" target="_blank" rel="noopener">AdoptOpenJDK</a> organization.</p>
</div>
<div class="paragraph">
  
  <p>They come in two flavors, a "slim" JDK image and and JRE image, both based on Alpine:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code>REPOSITORY                    TAG                          SIZE
adoptopenjdk/openjdk11        jre-11.0.6_10-alpine         147MB
adoptopenjdk/openjdk11        jdk-11.0.6_10-alpine-slim    253MB</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>For comparison, here&#8217;s an image based on Ubuntu Bionic and another one based on Debian Buster "slim":</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code>REPOSITORY            TAG                            SIZE
adoptopenjdk          13.0.2_8-jre-hotspot-bionic    225MB
openjdk               11.0.6-jre-slim-buster         204MB</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>As you can see, they are relatively small and the image based on Alpine Linux is "only" 27% smaller.
At the same time, if you are using a JRE instead of a JDK on Alpine Linux, you will get a 40% smaller image.</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-5">jlink</h2>
<div class="paragraph">
  
  <p>I&#8217;m not using <code>jlink</code> (yet) but this tool, introduced in JDK 9, can be used to create a custom runtime image where only the required Java modules are included.
Combined with a multi-stage build, it&#8217;s possible to build a smaller runtime for your Java application.</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-5">fat-jar</h2>
<div class="paragraph">
  
  <p>Since my application is relatively lightweight, I&#8217;ve decided to use a single executable jar that contains all my dependencies (also known as "fat-jar").
As a result, the Dockerfile is really straightforward:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-dockerfile" data-lang=dockerfile># based on alpine 3.11
FROM adoptopenjdk/openjdk11:jre-11.0.6_10-alpine

EXPOSE 8000

COPY target/kroki-server.jar .

ENTRYPOINT exec java -jar kroki-server.jar</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>This approach is also useful because the application can be executed outside of Docker using the same command line: <code>java -jar kroki-server.jar</code>.</p>
</div>
<div class="box note">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-note">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>Using a single executable jar is convenient but it&#8217;s not the most optimal because the entire application is build as a single image layer.
So even when you change a single line of your code, the entire application layer will be rebuilt.</p>
</div>
<div class="paragraph">
  
  <p>If you are building an application with a lot of dependencies (and your build is slow), you should try <a href="https://github.com/GoogleContainerTools/jib" target="_blank" rel="noopener">jib</a>.</p>
</div>
      </div>
    </div>
  </article>
</div>
</section>
</section>
<section class="section is-small">
<h2 class="title is-4">Summary</h2>
<div class="paragraph">
  
  <p>The size of your Docker images matters but it should not be the only deciding factor.
For instance, you don&#8217;t want to spend days or weeks trying to make your application work on Alpine.
If your application is working fine on Debian, then use a minimal base image and carefully add additional packages.</p>
</div>
<div class="paragraph">
  
  <p>You should also think about security.
While it&#8217;s true that by removing unnecessary components from your image, you reduce the attack surface,
it is also true that it&#8217;s safer to use an active and well-maintained base image with security updates rather than a less reliable but smaller base image.</p>
</div>
<div class="paragraph">
  
  <p>And finally, you should think about troubleshooting.
If you cannot execute an interactive shell on the container (because you don&#8217;t even have one installed!) then it will be really hard to troubleshoot a problem.</p>
</div>
<div class="paragraph">
  
  <p>So the smallest image possible is not always the best solution!</p>
</div>
<div class="paragraph">
  
  <p>If you want to learn more, I recommend this great series by <a href="https://twitter.com/jpetazzo" target="_blank" rel="noopener">Jérôme Petazzoni</a>:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://www.ardanlabs.com/blog/2020/02/docker-images-part1-reducing-image-size.html" target="_blank" rel="noopener">Docker Images : Part I - Reducing Image Size</a></p>
</li>
<li>
<p><a href="https://www.ardanlabs.com/blog/2020/02/docker-images-part2-details-specific-to-different-languages.html" target="_blank" rel="noopener">Docker Images : Part II - Details Specific To Different Languages</a></p>
</li>
<li>
<p><a href="https://www.ardanlabs.com/blog/2020/04/docker-images-part3-going-farther-reduce-image-size.html" target="_blank" rel="noopener">Docker Images : Part III - Going Farther To Reduce Image Size</a></p>
</li>
</ul>
</div>
</section>]]></content:encoded>
  </item>
<item>
    <title><![CDATA[Nifty Node: Investigating a performance regression]]></title>
    <description><![CDATA[🤿 Let's take a deep dive into Node to identify the root cause of a major performance regression.]]></description>
    <link>undefined</link>
    <category><![CDATA[Node]]></category>
<category><![CDATA[V8]]></category>
<category><![CDATA[JavaScript]]></category>
<category><![CDATA[performance]]></category>
    <dc:creator><![CDATA[Guillaume Grossetie]]></dc:creator>
    <pubDate>Sat, 27 Mar 2021 16:10:00 GMT</pubDate>
    <media:content url="https://blog.yuzutech.fr/_/images/investigation.jpeg" medium="image"/>
    <content:encoded><![CDATA[<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
  
  <p>It all started when <a href="https://twitter.com/mojavelinux">Dan Allen</a> told me that he noticed that Antora&#8201;&#8212;&#8201;a documentation site generator based on Asciidoctor.js&#8201;&#8212;&#8201;was 40% slower on Node 12 compared to Node 10.<br>
Dan quickly identified that <code>Asciidoctor.convert</code> was significantly slower.<br>
At this point, I was really surprised because the V8 JavaScript engine, used in Node, is renowned to run faster from one version to a newer one.</p>
</div>
<div class="paragraph">
  
  <p>Since the Asciidoctor.js repository contains a benchmark script, I was able to measure precisely how much slower Asciidoctor.js was on Node 12 compared to Node 10.
For reference, the benchmark script measures how much time it takes to convert the <a href="https://raw.githubusercontent.com/asciidoc/asciidoc/d43faae38c4a8bf366dcba545971da99f2b2d625/doc/asciidoc.txt">AsciiDoc User Guide</a>.</p>
</div>
<div class="paragraph">
  
  <p>Without further ado, the result:</p>
</div>
<div class="literalblock ">
<div class="title">Node 10.22.1</div>
<div class="content">
<pre>Load scripts: 0.08s
avg: 494.40
stddev: 68.72
50th: 469.50
75th: 497.50
90th: 530.80
99th: 674.98</pre> 
</div>
</div>
<div class="literalblock ">
<div class="title">Node 12.18.4</div>
<div class="content">
<pre>Load scripts: 0.058s
avg: 2406.50
stddev: 72.72
50th: 2380.00
75th: 2417.75
90th: 2477.40
99th: 2585.94</pre> 
</div>
</div>
<div class="paragraph">
  
  <p>On this benchmark, Node 12 is 3.8x to 5x slower compared to Node 10.<br>
My reaction was basically 😱😱😱</p>
</div>
<div class="box note">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-note">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        In this article I will compare Node 10 to Node 12, but I get similar results between Node 10 and Node 14 and even between Node 10 and the recently released Node 15.
      </div>
    </div>
  </article>
</div>
</div>
</div>
<section class="section is-small">
<h2 class="title is-4">Flamegraph profiling</h2>
<div class="paragraph">
  
  <p>Flamegraphs are great to discover bottlenecks and hot paths.<br>
On the JVM, you can use the excellent <a href="https://blog.yuzutech.fr/blog/flamegraph-embeddable-profiler/index.html">async-profiler</a> to generate flamegraphs.
While looking for a similar tool in the Node ecosystem, I found <a href="https://github.com/davidmarkclements/0x">0x</a>.
<code>0x</code> can profile and generate an interactive flamegraph for a Node process with a single command, and it&#8217;s working wonders, I highly recommend it! 🎉</p>
</div>
<div class="paragraph">
  
  <p>In this case, the goal is to generate one flamegraph when running on Node 10 and another one when running on Node 12.
Hopefully, we should be able to spot differences between the two flamegraphs.
We might even be able to visualize where the time is spent and which calls are slower.</p>
</div>
<div class="paragraph">
  
  <p>Here are the flamegraphs:</p>
</div>
<div class="imageblock">
<div class="content">
<img src="../_images/flamegraph-asciidoctor-js-node-10.png" alt="flamegraph asciidoctor js node 10">
</div>
<div class="title">Figure 1. Node 10.22.1</div>
</div>
<div class="imageblock">
<div class="content">
<img src="../_images/flamegraph-asciidoctor-js-node-12.png" alt="flamegraph asciidoctor js node 12">
</div>
<div class="title">Figure 2. Node 12.18.4</div>
</div>
<div class="paragraph">
  
  <p>Can you find the culprit?<br>
I can give you a clue. Take a close look at the dark orange blocks.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="paragraph">
  
  <p>Can you zoom and enhance that? 🔍</p>
</div>
</blockquote>
</div>
<div class="paragraph">
  
  <p>Sure I can!</p>
</div>
<div class="imageblock">
<div class="content">
<img src="../_images/flamegraph-asciidoctor-js-node-12-parser-next-line.png" alt="flamegraph asciidoctor js node 12 parser next line">
</div>
</div>
<div class="paragraph">
  
  <p>As you can see, <code>unshift</code> and <code>shift</code> are almost always on the top of the stack.
Let&#8217;s dig a bit further&#8230;&#8203; 🕵️</p>
</div>
<div class="paragraph">
  
  <p>As you might know, Asciidoctor.js is transpiled from Ruby to JavaScript using <a href="https://github.com/opal/opal">Opal</a>.
As a result, the <code>unshift</code> and <code>shift</code> are actually Ruby methods implemented in JavaScript:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://ruby-doc.org/core-2.7.0/Array.html#method-i-shift">Array#shift</a></p>
</li>
<li>
<p><a href="https://ruby-doc.org/core-2.7.0/Array.html#method-i-unshift">Array#unshift</a></p>
</li>
</ul>
</div>
<div class="paragraph">
  
  <p>The implementation in Opal is actually pretty straightforward and delegates most of the work to <code>Array.prototype.splice</code>, <code>Array.prototype.shift</code> and <code>Array.prototype.unshift</code>.
So how comes that these functions are way slower in Node&nbsp;12? 🤔</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Micro-benchmark</h2>
<div class="paragraph">
  
  <p>Let&#8217;s write a micro-benchmark to compare the performance of <code>Array.prototype.splice</code> on Node&nbsp;10 and Node&nbsp;12.
In the following example, I&#8217;m using the excellent <a href="https://benchmarkjs.com/">Benchmark.js</a>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-js" data-lang=js>const Benchmark = require('benchmark')

const bench = new Benchmark('splice', () =&gt; {
  ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'].splice(0, 1)
})
console.log(bench.run().toString())</code></pre>
</div>
</div>
<div class="literalblock ">
<div class="title">Node 10.22.1</div>
<div class="content">
<pre>splice x 7,555,366 ops/sec ±3.04% (94 runs sampled)</pre> 
</div>
</div>
<div class="literalblock ">
<div class="title">Node 12.18.4</div>
<div class="content">
<pre>splice x 20,305,330 ops/sec ±0.71% (93 runs sampled)</pre> 
</div>
</div>
<div class="paragraph">
  
  <p>You read it right, <code>Array.prototype.splice</code> is approximately 2.5x times faster on Node 12 (not slower!). 😕<br>
While this result is counter-intuitive, it clearly indicates that <code>Array.prototype.splice</code> has been optimized between Node&nbsp;10 and Node&nbsp;12.
In other words, the implementation changed.</p>
</div>
<div class="paragraph">
  
  <p>Now let&#8217;s try to run the same test when the Opal runtime is loaded.</p>
</div>
<div class="literalblock ">
<div class="title">Node 10.22.1 with Opal runtime</div>
<div class="content">
<pre>splice x 7,504,100 ops/sec ±3.26% (90 runs sampled)</pre> 
</div>
</div>
<div class="paragraph">
  
  <p>Nothing to report&#8230;&#8203; the performance is similar to what we had before when Opal runtime was not loaded.</p>
</div>
<div class="literalblock ">
<div class="title">Node 12.18.4 with Opal runtime</div>
<div class="content">
<pre>splice x 984,509 ops/sec ±0.41% (92 runs sampled)</pre> 
</div>
</div>
<div class="paragraph">
  
  <p>Oh oh!<br>
The code is now 20x times slower compared to Node 12.18.4 and 7x times slower compared to Node 10.22.1.</p>
</div>
<div class="paragraph">
  
  <p>Instinctively, it seems that when Opal runtime is loaded we are not benefiting from a performance optimization in V8&#8230;&#8203;
As a result, I decided to document myself about the V8 engine and found a couple of really well written articles by <a href="https://mathiasbynens.be/">Mathias Bynens</a>.</p>
</div>
<div class="paragraph">
  
  <p>In one of them, <a href="https://mathiasbynens.be/notes/prototypes">"JavaScript engine fundamentals: optimizing prototypes"</a>, we can read:</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="paragraph">
  
  <p>Based on this knowledge, we identified a practical JavaScript coding tip that can help boost performance: don’t mess with prototypes (or if you really, really need to, then at least do it before other code runs).</p>
</div>
</blockquote>
<div class="attribution">
&#8212; Mathias Bynens
</div>
</div>
<div class="paragraph">
  
  <p>All of a sudden, I connected the dots! 💡</p>
</div>
<div class="paragraph">
  
  <p><a href="https://github.com/opal/opal">Opal</a> relies on prototypes to augment built-in objects and implement Ruby inheritance model.<br>
In fact, Opal will actually replace the prototype on the <code>Array</code> built-in object using <code>Object.setPrototypeOf</code>.<br>
I was now able to reproduce this issue adding a single line of code:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-js" data-lang=js>Object.setPrototypeOf(Array.prototype, {})</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Once <code>Array.prototype</code> has been altered, several <code>Array</code> operations are not benefiting anymore from the optimizations in V8.</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">V8 mailing list</h2>
<div class="paragraph">
  
  <p>Since I had a simple reproduction case, and a better idea of what was going on,
I decided to post a question on the <a href="https://groups.google.com/g/v8-users/c/Sr19goTi5d8/m/wtW6WHu3BwAJ">v8-users mailing list</a>.</p>
</div>
<div class="paragraph">
  
  <p><a href="https://github.com/bnoordhuis">Ben Noordhuis</a> kindly answered my question:</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="paragraph">
  
  <p><code>Array.p.splice()</code> returns a new array. <code>array-splice.tq</code> has a fast path for that (<code>ExtractFastJSArray</code>, defined in <em>src/codegen/code-stub-assembler.cc</em>)
but that&#8217;s only sound when <code>Array.prototype</code> is unmodified, hence the <code>IsPrototypeInitialArrayPrototype()</code> check.<br>
Older versions of V8 called out to this JS-with-extensions code: <a href="https://github.com/v8/v8/blob/7.0.1/src/js/array.js#L599-L642" class="bare">github.com/v8/v8/blob/7.0.1/src/js/array.js#L599-L642</a></p>
</div>
</blockquote>
<div class="attribution">
&#8212; Ben Noordhuis
</div>
</div>
<div class="paragraph">
  
  <p>For reference, Node 10.22 is using V8 version &lt; 7.0 and Node 12.18 is using V8 version 7.8.
As pointed by Ben, the implementation changed, and now the fast path is only available when <code>Array.prototype</code> is pristine.</p>
</div>
<div class="paragraph">
  
  <p>It all makes sense now, and I guess "don&#8217;t mess with prototypes" is pretty good advice! 😅</p>
</div>
<div class="paragraph">
  
  <p>But unfortunately that&#8217;s not always possible.
In our case, Asciidoctor.js relies on Opal and Opal relies on prototypes&#8230;&#8203;</p>
</div>
<div class="paragraph">
  
  <p>In his reply, Ben also suggested to "open-code" a faster version of <code>Array.prototype.splice</code>:</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="paragraph">
  
  <p>If <code>Array.p.splice()</code> performance is vital to you, you can try open-coding it.
I did something similar in Node.js a few years ago, to great effect: <a href="https://github.com/nodejs/node/commit/d3f8db124463e478420d8bba6fa5cf13af7b4ecb" class="bare">github.com/nodejs/node/commit/d3f8db124463e478420d8bba6fa5cf13af7b4ecb</a></p>
</div>
</blockquote>
<div class="attribution">
&#8212; Ben Noordhuis
</div>
</div>
<div class="paragraph">
  
  <p>In the next article, we will put Ben&#8217;s suggestion into practice! 🚀</p>
</div>
</section>]]></content:encoded>
  </item>
<item>
    <title><![CDATA[Awesome Asciidoctor.js: Use PlantUML extension to render diagrams]]></title>
    <description><![CDATA[Extensions in Asciidoctor.js are very powerful. This article will show you how to use extension to render PlantUML diagrams.]]></description>
    <link>undefined</link>
    <category><![CDATA[Asciidoctor.js]]></category>
<category><![CDATA[PlantUML]]></category>
<category><![CDATA[JavaScript]]></category>
    <dc:creator><![CDATA[Guillaume Grossetie]]></dc:creator>
    <pubDate>Sun, 04 Nov 2018 08:45:00 GMT</pubDate>
    <media:content url="https://blog.yuzutech.fr/_/images/blueprint.jpg" medium="image"/>
    <content:encoded><![CDATA[<div class="paragraph">
  
  <p>Extensions in Asciidoctor.js are very powerful because they open up the language to new use cases.
One popular use case is to render PlantUML diagrams.
To do that we are going to use the <a href="https://github.com/eshepelyuk/asciidoctor-plantuml.js">PlantUML extension</a> written by <a href="https://github.com/eshepelyuk">Evgeny Shepelyuk</a>.</p>
</div>
<div class="paragraph">
  
  <p>In the following example document, we define a simple diagram:</p>
</div>
<div class="listingblock">
<div class="listing-title">document.adoc</div>
<div class="content">
<pre class="nowrap"><code class="language-asciidoc" data-lang=asciidoc>= PlantUML diagram

== First section

[plantuml,format=svg,role=sequence]
....
alice -&gt; bob
....</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>To render this document, we need to install the dependencies using <code>npm</code>:</p>
</div>
<div class="literalblock ">
<div class="content">
<pre>$ npm i asciidoctor.js asciidoctor-plantuml</pre> 
</div>
</div>
<div class="box note">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-note">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>If you prefer <code>Yarn</code> over <code>npm</code>, use this command instead:</p>
</div>
<div class="literalblock ">
<div class="content">
<pre>$ yarn add asciidoctor.js asciidoctor-plantuml</pre> 
</div>
</div>
      </div>
    </div>
  </article>
</div>
<div class="listingblock">
<div class="listing-title">convert.js</div>
<div class="content">
<pre class="nowrap"><code class="language-js" data-lang=js>const asciidoctor = require('asciidoctor.js')()
const plantuml = require('asciidoctor-plantuml')

plantuml.register(asciidoctor.Extensions)
asciidoctor.convertFile('document.adoc')</code></pre>
</div>
</div>
<div class="box important">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-important">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="exclamation-circle" class="svg-inline--fa fa-exclamation-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zm-248 50c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>By default the PlantUML extension will use a remote PlantUML server available at <a href="http://www.plantuml.com/plantuml" class="bare">www.plantuml.com/plantuml</a>.<br>
Make sure that you have access to this server before generating your documentation.</p>
</div>
<div class="paragraph">
  
  <p>You can also run the server locally using Docker:</p>
</div>
<div class="literalblock ">
<div class="content">
<pre>$ docker run -d -p 8080:8080 plantuml/plantuml-server:jetty</pre> 
</div>
</div>
<div class="paragraph">
  
  <p>Then you will need to override the attribute <code>plantuml-server-url</code> to point to your local server:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-js" data-lang=js>const options = {
  attributes: {
    'plantuml-server-url': 'http://localhost:8080'
  }
}
asciidoctor.convertFile('document.adoc', options)</code></pre>
</div>
</div>
      </div>
    </div>
  </article>
</div>
<div class="paragraph">
  
  <p>Since version 0.10.0 of the PlantUML extension, you can also generate Ditaa and Graphviz diagrams:</p>
</div>
<div class="listingblock">
<div class="listing-title">document.adoc</div>
<div class="content">
<pre class="nowrap"><code class="language-asciidoc" data-lang=asciidoc>= Ditaa diagram

== First section

[ditaa]
....
+----------+   +-------------+
|cAAA      |   |             |
|          +---+ Application |
| Database |   |      cRED{d}|
|       {s}|   +-------------+
+----------+
....</code></pre>
</div>
</div>
<div class="listingblock">
<div class="listing-title">document.adoc</div>
<div class="content">
<pre class="nowrap"><code class="language-asciidoc" data-lang=asciidoc>= Graphviz (DOT) diagram

== First section

[graphviz]
....
digraph foo {
  node [style=rounded]
  node1 [shape=box]
  node2 [fillcolor=yellow, style="rounded,filled", shape=diamond]
  node3 [shape=record, label="{ a | b | c }"]
   node1 -&gt; node2 -&gt; node3
}
....</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>If you want to learn about the PlantUML extension, you can read the project <a href="https://github.com/eshepelyuk/asciidoctor-plantuml.js/blob/master/README.adoc">README on GitHub</a>.</p>
</div>
<div class="paragraph">
  
  <p>Written with Asciidoctor.js 1.5.9 and Asciidoctor.js PlantUML extension 0.10.0.</p>
</div>]]></content:encoded>
  </item>
<item>
    <title><![CDATA[Awesome Antora: Sort and hide components and versions]]></title>
    <description><![CDATA[You would like custom sorting of Antora components and versions, or to hide components.]]></description>
    <link>undefined</link>
    <category><![CDATA[Antora]]></category>
<category><![CDATA[Sorting Components]]></category>
    <dc:creator><![CDATA[David Jencks]]></dc:creator>
    <pubDate>Mon, 28 Sep 2020 14:25:00 GMT</pubDate>
    <media:content url="https://blog.yuzutech.fr/_/images/sort.jpg" medium="image"/>
    <content:encoded><![CDATA[<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
  
  <p>A frequent request is to sort the components and their versions in the default Antora UI component explorer in a customized order.
Fortunately, this is quite easy to do using a couple of files in a supplemental UI or in a customized UI.</p>
</div>
<div class="paragraph">
  
  <p>I&#8217;d like to thank Bob Roro and Ewan Edwards for a lot of hints about what to do and answers about how to do it.
Their invaluable help pushed me into figuring out how this works!
I&#8217;d also like to thank Dan Allen for pointing to an existing implementation (for a completely custom UI).</p>
</div>
</div>
</div>
<section class="section is-small">
<h2 class="title is-4">Where do we sort?</h2>
<div class="paragraph">
  
  <p>Here&#8217;s the default UI&#8217;s partial that sets up the component explorer contents:</p>
</div>
<div class="listingblock">
<div class="listing-title">nav-explore.hbs (original)</div>
<div class="content">
<pre class="nowrap" data-line="9"><code class="language-handlebars" data-lang=handlebars>&lt;div class="nav-panel-explore{{#unless page.navigation}} is-active{{/unless}}" data-panel="explore"&gt;
  {{#if page.component}}
    &lt;div class="context"&gt;
      &lt;span class="title"&gt;{{page.component.title}}&lt;/span&gt;
      &lt;span class="version"&gt;{{page.componentVersion.displayVersion}}&lt;/span&gt;
    &lt;/div&gt;
  {{/if}}
  &lt;ul class="components"&gt;
    {{#each site.components}} <i class="conum" data-value="1"></i>
      &lt;li class="component{{#if (eq this @root.page.component)}} is-current{{/if}}"&gt;
        &lt;span class="title"&gt;{{{./title}}}&lt;/span&gt;
        &lt;ul class="versions"&gt;
          {{#each ./versions}}
            &lt;li class="version
          {{~#if (and (eq .. @root.page.component) (eq this @root.page.componentVersion))}} is-current{{/if~}}
              {{~#if (eq this ../latestVersion)}} is-latest{{/if}}"&gt;
              &lt;a href="{{{relativize ./url}}}"&gt;{{./displayVersion}}&lt;/a&gt;
            &lt;/li&gt;
          {{/each}}
        &lt;/ul&gt;
      &lt;/li&gt;
    {{/each}}
  &lt;/ul&gt;
&lt;/div&gt;</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>The crucial line!</td>
          </tr>
</table>
</div>
<div class="paragraph">
  
  <p>Here, <code>{{#each site.components}}</code> iterates over the object <code>site.components</code> in the default order.
All we have to do is use a Javascript helper to change the order, as in <code>{{#each (mySorter site.components)}}</code>.
For this the Javascript helper signature would be <code>module.exports = (components) &#8658; {&#8230;&#8203;}</code>.
Note that <code>#each</code> works on either arrays or objects, so, although <code>site.components</code> is an object, we can return an array of components in the desired order.</p>
</div>
<div class="paragraph">
  
  <p>Now let&#8217;s consider plausible sources of information for the sorter.
First of all, we need the collection of components.
This is actually available in two ways, as <code>site.components</code> or by calling <code>getComponents</code> on the content catalog model as <code>site.contentCatalog</code>.
We could pass the entire <code>site</code> model to our helper, but let&#8217;s use <code>site.components</code> like the default.</p>
</div>
<div class="paragraph">
  
  <p>This much is adequate to hard-code a sort, for instance by listing the order of components explicitly.</p>
</div>
<div class="paragraph">
  
  <p>Let&#8217;s start with a possibly silly example that demonstrates a sorting algorithm that does not need to be configured.</p>
</div>
<div class="paragraph">
  
  <p>Here&#8217;s the <code>nav-explore.hbs</code> modified to work with a sorter:</p>
</div>
<div class="listingblock">
<div class="listing-title">nav-explore.hbs (with automonous component sorting)</div>
<div class="content">
<pre class="nowrap"><code class="language-handlebars" data-lang=handlebars>&lt;div class="nav-panel-explore{{#unless page.navigation}} is-active{{/unless}}" data-panel="explore"&gt;
  {{#if page.component}}
    &lt;div class="context"&gt;
      &lt;span class="title"&gt;{{page.component.title}}&lt;/span&gt;
      &lt;span class="version"&gt;{{page.componentVersion.displayVersion}}&lt;/span&gt;
    &lt;/div&gt;
  {{/if}}
  &lt;ul class="components"&gt;
    {{#each (componentSorter site.components)}}
      &lt;li class="component{{#if (eq this @root.page.component)}} is-current{{/if}}"&gt;
        &lt;span class="title"&gt;{{{./title}}}&lt;/span&gt;
        &lt;ul class="versions"&gt;
          {{#each ./versions}}
            &lt;li class="version
          {{~#if (and (eq .. @root.page.component) (eq this @root.page.componentVersion))}} is-current{{/if~}}
              {{~#if (eq this ../latestVersion)}} is-latest{{/if}}"&gt;
              &lt;a href="{{{relativize ./url}}}"&gt;{{./displayVersion}}&lt;/a&gt;
            &lt;/li&gt;
          {{/each}}
        &lt;/ul&gt;
      &lt;/li&gt;
    {{/each}}
  &lt;/ul&gt;
&lt;/div&gt;
autonomous</code></pre>
</div>
</div>
<div class="listingblock">
<div class="listing-title">componentSorter.js (Reverse sorting)</div>
<div class="content">
<pre class="nowrap"><code class="language-javascript" data-lang=javascript>'use strict'

module.exports = (components) =&gt; Object.values(components).reverse()</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Here, all we&#8217;ve done is to reverse the original sort order.
As with all these sorters, the code would go in <code>supplemental_ui/helpers/componentSorter.js</code> or, for a UI project, <code>src/helpers/componentSorter.js</code>.</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Sorting components based on configuration</h2>
<div class="paragraph">
  
  <p>This is simple, but it&#8217;s convenient to be able to configure the sorting.
Let&#8217;s do that with a page attribute <code>page-component-sort-order</code>, expected to be set in the playbook.
If you want to confuse your viewers, you could set it differently in each <code>antora.yml</code> component descriptor, or even on each page.</p>
</div>
<div class="paragraph">
  
  <p>Something similar could be done for version sort order, but this can be configured more easily in the component descriptors.</p>
</div>
<div class="paragraph">
  
  <p>With these choices, our Handlebars partial will look like this:</p>
</div>
<div class="listingblock">
<div class="listing-title">nav-explore.hbs (with component sorting)</div>
<div class="content">
<pre class="nowrap"><code class="language-handlebars" data-lang=handlebars>&lt;div class="nav-panel-explore{{#unless page.navigation}} is-active{{/unless}}" data-panel="explore"&gt;
  {{#if page.component}}
    &lt;div class="context"&gt;
      &lt;span class="title"&gt;{{page.component.title}}&lt;/span&gt;
      &lt;span class="version"&gt;{{page.componentVersion.displayVersion}}&lt;/span&gt;
    &lt;/div&gt;
  {{/if}}
  &lt;ul class="components"&gt;
    {{#each (componentSorter site.components page.attributes.component-sort-order)}}
      &lt;li class="component{{#if (eq this @root.page.component)}} is-current{{/if}}"&gt;
        &lt;span class="title"&gt;{{{./title}}}&lt;/span&gt;
        &lt;ul class="versions"&gt;
          {{#each ./versions}}
            &lt;li class="version
          {{~#if (and (eq .. @root.page.component) (eq this @root.page.componentVersion))}} is-current{{/if~}}
              {{~#if (eq this ../latestVersion)}} is-latest{{/if}}"&gt;
              &lt;a href="{{{relativize ./url}}}"&gt;{{./displayVersion}}&lt;/a&gt;
            &lt;/li&gt;
          {{/each}}
        &lt;/ul&gt;
      &lt;/li&gt;
    {{/each}}
  &lt;/ul&gt;
&lt;/div&gt;</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>In a project with supplemental UI, this would be <code>supplemental_ui/partials/nav-explore.hbs</code>.
In a UI project based on the Antora default UI, this would be <code>src/partials/nav-explore.hbs</code>.</p>
</div>
<div class="paragraph">
  
  <p>Now let&#8217;s consider a configurable example, where you specify the exact order of components, and any components not mentioned are skipped.</p>
</div>
<div class="listingblock">
<div class="listing-title">componentSorter.js (Simple configurable sorting)</div>
<div class="content">
<pre class="nowrap"><code class="language-javascript" data-lang=javascript>'use strict'

module.exports = (components, sortOrder = undefined) =&gt; {
  if (sortOrder) {
    const sort = sortOrder.split(',').map((componentName) =&gt; componentName.trim())
    return sort.reduce((accum, name) =&gt; {
      if (components[name]) {
        accum.push(components[name])
      } else {
        console.log(`no such component to sort: ${name}`)
      }
      return accum
    }, [])
  } else {
    return components
  }
}</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>And, finally for this section, an example with a wildcard and explicit "hide" instructions.
(This is heavily influenced by Dan&#8217;s <a href="https://gitlab.com/opendevise/oss/antora-site-generator-ms/-/blob/v2.3.x/lib/custom-sort-components.js">example</a>).</p>
</div>
<div class="listingblock">
<div class="listing-title">componentSorter.js (with component sorting and hiding, and wildcards)</div>
<div class="content">
<pre class="nowrap"><code class="language-javascript" data-lang=javascript>'use strict'

module.exports = (components, sortOrder = undefined) =&gt; {
  if (sortOrder) {
    components = Object.assign({}, components)
    sortOrder = sortOrder.split(',').map((componentName) =&gt; componentName.trim())

    let restIdx
    let i = 0
    const sortedComponents = sortOrder.reduce((accum, name) =&gt; {
      if (name === '*') {
        restIdx = i
      } else if (name.startsWith('!')) {
        if ((name = name.slice(1)) in components) {
          delete components[name]
        } else {
          console.log(`no such component to omit named: ${name}`)
        }
      } else if (name in components) {
        i++
        accum.push(components[name])
        delete components[name]
      } else {
        console.log(`no such component named: ${name}`)
      }
      return accum
    }, [])
    if (restIdx !== undefined) {
      sortedComponents.splice(restIdx, 0, ...Object.values(components))
    } else if (Object.keys(components).length) {
      console.log(`Components ${Object.keys(components).join(', ')} not ordered or hidden`)
    }
    return sortedComponents
  } else {
    return components
  }
}</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>These implementations are going to be very noisy if you specify a component that isn&#8217;t present or leave out a component (in the last implementation).
Leaving out the console logging or only logging once is an easy solution.
The component-version sorter has a more sophisticated solution.</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-4">Sorting Versions</h2>
<div class="paragraph">
  
  <p>Versions occur in two places in the UI: the component explorer and the page version selector.
Thus, we need to modify two <code>partials</code> Handlebars templates.
It would be most convenient to have two helpers, one for each sorting task, but since helpers cannot require each other due to how they are loaded from a virtual file system, we need to get both sorters into the same helper.
We&#8217;ll do this by specifying the type of sort as the first parameter.</p>
</div>
<section class="section is-small">
<h2 class="title is-5">Specifying version sort order</h2>
<div class="paragraph">
  
  <p>Since there&#8217;s only one component descriptor for each component-version, we can do version sorting by putting a key in each component descriptor.
This strategy doesn&#8217;t work well for components, since the key would have to be the same for every version of the component.
Another possible version sorting strategy, that we will not pursue, would be to have a global complex sorting key, where each component name is associated with an explicit version sort order.
For instance:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-yaml" data-lang=yaml>asciidoc:
  attributes:
    page-component-sort-order: component-a[v3,v1,vx],component-c[v1,vy,va],component-b[z,y,x]</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Implementing this is left as an exercise for the reader.</p>
</div>
<div class="paragraph">
  
  <p>To get back to what we will demonstrate, we&#8217;ll have an Asciidoc attribute in each component descriptor with a string-valued sort key:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-yaml" data-lang=yaml>name: component-a
version: 1.0
title: My Fabulous A
display-version: Version One Point Zero

asciidoc:
  attributes:
    version-sort-key: zanzibar</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>Since we&#8217;ll be getting the <code>version-sort-key</code> value from the version object rather than the page attributes exposed in the UI model, the key name doesn&#8217;t need to start with the <code>page-</code> prefix.</p>
</div>
</section>
<section class="section is-small">
<h2 class="title is-5">Handlebars template modifications</h2>
<div class="paragraph">
  
  <p>We&#8217;re already supplying all the necessary information to the sorting helper, so the <code>nav-explore.hbs</code> Handlebars template doesn&#8217;t need significant modification.
In order to avoid modifying the existing component objects, we&#8217;ll copy them, so the component comparison code needs to be a little more careful, comparing names rather than objects.</p>
</div>
<div class="listingblock">
<div class="listing-title">nav-explore.hbs (with component and version sorting)</div>
<div class="content">
<pre class="nowrap"><code class="language-handlebars" data-lang=handlebars>&lt;div class="nav-panel-explore{{#unless page.navigation}} is-active{{/unless}}" data-panel="explore"&gt;
  {{#if page.component}}
    &lt;div class="context"&gt;
      &lt;span class="title"&gt;{{page.component.title}}&lt;/span&gt;
      &lt;span class="version"&gt;{{page.componentVersion.displayVersion}}&lt;/span&gt;
    &lt;/div&gt;
  {{/if}}
  &lt;ul class="components"&gt;
    {{#each (componentVersionSorter "components" site.components page.attributes.component-sort-order)}}
      &lt;li class="component{{#if (eq this.name @root.page.component.name)}} is-current{{/if}}"&gt;
        &lt;span class="title"&gt;{{{./title}}}&lt;/span&gt;
        &lt;ul class="versions"&gt;
          {{#each ./versions}}
            &lt;li class="version
          {{~#if (and (eq ../name @root.page.component.name) (eq this @root.page.componentVersion))}} is-current{{/if~}}
              {{~#if (eq this ../latestVersion)}} is-latest{{/if}}"&gt;
              &lt;a href="{{{relativize ./url}}}"&gt;{{./displayVersion}}&lt;/a&gt;
            &lt;/li&gt;
          {{/each}}
        &lt;/ul&gt;
      &lt;/li&gt;
    {{/each}}
  &lt;/ul&gt;
&lt;/div&gt;</code></pre>
</div>
</div>
<div class="listingblock">
<div class="listing-title">page-versions.hbs</div>
<div class="content">
<pre class="nowrap"><code class="language-handlebars" data-lang=handlebars>{{#with (componentVersionSorter "versions" page.versions)}}
  &lt;div class="page-versions"&gt;
    &lt;button class="version-menu-toggle" title="Show other versions of page"&gt;{{@root.page.componentVersion.displayVersion}}&lt;/button&gt;
    &lt;div class="version-menu"&gt;
      {{#each this}}
        &lt;a class="version
      {{~#if (eq ./version @root.page.version)}} is-current{{/if~}}
          {{~#if ./missing}} is-missing{{/if}}" href="{{{relativize ./url}}}"&gt;{{./displayVersion}}&lt;/a&gt;
      {{/each}}
    &lt;/div&gt;
  &lt;/div&gt;
{{/with}}</code></pre>
</div>
</div>
</section>
<section class="section is-small">
<h2 class="title is-5">Sorting helper</h2>
<div class="paragraph">
  
  <p>We need to add version sorting logic to the sorting helper and make it callable separately.
We&#8217;ll do this by adding a first parameter describing the type of sort requested.</p>
</div>
<div class="listingblock">
<div class="listing-title">componentVersionSorter.js</div>
<div class="content">
<pre class="nowrap"><code class="language-javascript" data-lang=javascript>'use strict'

const VERSION_SORT_KEY = 'version-sort-key'

module.exports = (what, data, sortOrder = undefined) =&gt; {
  if (what === 'components') {
    return sortComponents(data, sortOrder)
  } else if (what === 'versions') {
    return sortVersions(data)
  } else {
    throw new Error(`unexpected sort request: ${what}. Expected 'components' or 'versions`)
  }
}

function sortComponents (components, sortOrder = undefined) {
  if (sortOrder) {
    components = Object.assign({}, components)
    sortOrder = sortOrder.split(',').map((componentName) =&gt; componentName.trim())

    let restIdx
    let i = 0
    let omitAll
    const sortedComponents = sortOrder.reduce((accum, name) =&gt; {
      let ignoreIfMissing = name.endsWith('?')
      ignoreIfMissing &amp;&amp; (name = name.slice(0, name.length - 2))
      if (name === '*') {
        restIdx = i
      } else if (name === '!*') {
        omitAll = true
      } else if (name.startsWith('!')) {
        if ((name = name.slice(1)) in components) {
          delete components[name]
        } else {
          ignoreIfMissing || console.log(`no such component to omit named: ${name}`)
        }
      } else if (name in components) {
        i++
        accum.push(components[name])
        delete components[name]
      } else {
        ignoreIfMissing || console.log(`no such component named: ${name}`)
      }
      return accum
    }, [])
    if (restIdx !== undefined) {
      sortedComponents.splice(restIdx, 0, ...Object.values(components))
    } else if (Object.keys(components).length) {
      omitAll || console.log(`Components ${Object.keys(components).join(', ')} not ordered or hidden`)
    }
    return sortComponentVersions(sortedComponents)
  } else {
    return sortComponentVersions(Object.values(components))
  }
}

function sortComponentVersions (components) {
  return components.map((component) =&gt; {
    component = Object.assign({ name: component.name, title: component.title }, component)
    component.versions = sortVersions(component.versions)
    return component
  })
}

function sortVersions (versions) {
  const sortedVersions = (versions || []).slice()
    .filter((v) =&gt; v.asciidoc.attributes[VERSION_SORT_KEY] !== '!')
    .sort((v1, v2) =&gt; {
      const k1 = v1.asciidoc.attributes[VERSION_SORT_KEY]
      const k2 = v2.asciidoc.attributes[VERSION_SORT_KEY]
      if (k1) {
        if (k2) {
          return k2.localeCompare(k1)
        }
        return -1
      }
      if (k2) return 1
      return versions.indexOf(v1) - versions.indexOf(v2)
    })
  return sortedVersions
}</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>The version sorting is in reverse order, just like the default sorting.
Versions without a <code>version-sort-order</code> key are placed last, in their original order.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Component sorting configuration (playbook <code>asciidoc.attributes.page-component-sort-order</code> key)</dt>
<dd>
<p>The key value is a comma-separated list of specifiers:</p>
<div class="dlist">
<dl>
<dt class="hdlist1">Required component</dt>
<dd>
<p>An explicit component name is placed in the order specified if present and warned if missing.</p>
</dd>
<dt class="hdlist1">Optional component</dt>
<dd>
<p>A component name suffixed with '?' is placed in the order specified if present.</p>
</dd>
<dt class="hdlist1">Hidden component</dt>
<dd>
<p>A component name prefixed with '!' is hidden if present and warned if missing.</p>
</dd>
<dt class="hdlist1">Optional hidden component</dt>
<dd>
<p>A component name prefixed with '!' and suffixed with '?' is hidden if present.</p>
</dd>
<dt class="hdlist1">Wildcard include</dt>
<dd>
<p>A '*' includes all components not otherwise mentioned, in their original order, at the position of the '*'</p>
</dd>
<dt class="hdlist1">Wildcard hide</dt>
<dd>
<p>A '!*' causes all components not otherwise mentioned to be hidden.</p>
</dd>
</dl>
</div>
</dd>
<dt class="hdlist1">Version sorting configuration, per component</dt>
<dd>
<div class="ulist">
<ul>
<li>
<p>Version sorting is specified in the component descriptor with the <code>asciidoc.attributes.version-sort-key</code> key.</p>
</li>
<li>
<p>Versions with this key are ordered in reverse lexicographical order of key value.</p>
</li>
<li>
<p>Versions without this key are ordered after those with the key, in the original order.</p>
</li>
<li>
<p>The key value of '!' causes the version to be hidden.</p>
</li>
</ul>
</div>
</dd>
</dl>
</div>
<div class="paragraph">
  
  <p>There&#8217;s a small project demonstrating all this at <a href="https://gitlab.com/djencks/antora-component-sorting-example" class="bare">gitlab.com/djencks/antora-component-sorting-example</a>.</p>
</div>
<div class="paragraph">
  
  <p>While this implementation can specify any desired sort, it may not always allow an easy or appropriate way to specify that sort.
Nevertheless this should provide an indication of how to implement and use more specific sorting strategies.</p>
</div>
<div class="paragraph">
  
  <p>Comments and suggestions would be appreciated!</p>
</div>
</section>
</section>]]></content:encoded>
  </item>
<item>
    <title><![CDATA[Awesome Asciidoctor.js: Write an extension to embed a gist into your document]]></title>
    <description><![CDATA[Extensions are central to the success of Asciidoctor because they open up the language to new use cases. Asciidoctor.js allows extensions to be written using the full power of the JavaScript language. Let's find out how we can use an extension to embed a gist into our documentation.]]></description>
    <link>undefined</link>
    <category><![CDATA[Asciidoctor.js]]></category>
<category><![CDATA[Extension]]></category>
<category><![CDATA[JavaScript]]></category>
    <dc:creator><![CDATA[Guillaume Grossetie]]></dc:creator>
    <pubDate>Mon, 19 Nov 2018 15:00:00 GMT</pubDate>
    <media:content url="https://blog.yuzutech.fr/_/images/extension.jpg" medium="image"/>
    <content:encoded><![CDATA[<div class="paragraph">
  
  <p>Asciidoctor.js offers a list of extension points that open up the language to new use cases.
The following extension points are currently available:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Preprocessor</dt>
<dd>
<p>Processes the raw source lines before they are passed to the parser.</p>
</dd>
<dt class="hdlist1">Tree processor</dt>
<dd>
<p>Processes the Asciidoctor.Document (AST) once parsing is complete.</p>
</dd>
<dt class="hdlist1">Postprocessor</dt>
<dd>
<p>Processes the output after the document has been converted, but before it&#8217;s written to disk.</p>
</dd>
<dt class="hdlist1">Docinfo Processor</dt>
<dd>
<p>Adds additional content to the header or footer regions of the generated document.</p>
</dd>
<dt class="hdlist1">Block processor</dt>
<dd>
<p>Processes a block of content marked with a custom block style (i.e., <code>[custom]</code>).</p>
</dd>
<dt class="hdlist1">Block macro processor</dt>
<dd>
<p>Registers a custom block macro and processes it (e.g., <code>gist::12345[]</code>).</p>
</dd>
<dt class="hdlist1">Inline macro processor</dt>
<dd>
<p>Registers a custom inline macro and processes it (e.g., <code>btn:[Save]</code>).</p>
</dd>
<dt class="hdlist1">Include processor</dt>
<dd>
<p>Processes the <code>include::&lt;filename&gt;[]</code> directive.</p>
</dd>
</dl>
</div>
<div class="paragraph">
  
  <p>In this article we are going to use a <em>Block macro processor</em> named <code>gist</code>.<br>
To register an extension, it&#8217;s recommended to create a dedicated registry.
We can then enable the registry using the <code>extension_registry</code> option.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap" data-line="1,6,19"><code class="language-js" data-lang=js>const registry = asciidoctor.Extensions.create() <i class="conum" data-value="1"></i>
/*
 * A block macro that embeds a Gist into the output document
 * Usage: gist::12345[]
 */
registry.blockMacro(function () { <i class="conum" data-value="2"></i>
  const self = this
  self.named('gist')
  self.process(function (parent, target, attrs) {
    const titleHTML = attrs.title ? `&lt;div class="title"&gt;${attrs.title}&lt;/div&gt;\n` : ''
    const html = `&lt;div class="openblock gist"&gt;
  ${titleHTML}&lt;div class="content"&gt;
    &lt;script src="https://gist.github.com/${target}.js"&gt;&lt;/script&gt;
  &lt;/div&gt;
&lt;/div&gt;`
    return self.createBlock(parent, 'pass', html, attrs, {})
  });
});
const options = { extension_registry: registry } <i class="conum" data-value="3"></i>
const result = asciidoctor.convert('gist::4b44db7b60724ceb3d969a449f30a48a[]', options)</code></pre>
</div>
</div>
<div class="colist arabic ">
<table>
<tr>
          <td><i class="conum" data-value="1"></i><b>1</b></td>
          <td>Create a <code>registry</code></td>
          </tr>
<tr>
          <td><i class="conum" data-value="2"></i><b>2</b></td>
          <td>Register the gist extension</td>
          </tr>
<tr>
          <td><i class="conum" data-value="3"></i><b>3</b></td>
          <td>Define the <code>extension_registry</code> option (the gist extension will be enabled)</td>
          </tr>
</table>
</div>
<div class="paragraph">
  
  <p>In you document you can now reference a Gist using the syntax <code>gist::12345[]</code>.<br>
And here&#8217;s the result with for <code>gist::4b44db7b60724ceb3d969a449f30a48a[]</code></p>
</div>
<div class="openblock gist">
  <div class="content">
    <script src="https://gist.github.com/4b44db7b60724ceb3d969a449f30a48a.js"></script>
  </div>
</div>
<div class="box note">
  <article class="media">
    <div class="media-left">
      <figure class="image">
        <span class="icon has-text-note">
          <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>
        </span>
      </figure>
    </div>
    <div class="media-content">
      <div class="content">
        <div class="paragraph">
  
  <p>It&#8217;s also possible to register an extension globally using <code>asciidoctor.Extensions.register</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="nowrap"><code class="language-js" data-lang=js>asciidoctor.Extensions.register(function () {
  this.blockMacro(function () { /* ... */ })
})</code></pre>
</div>
</div>
<div class="paragraph">
  
  <p>In this case you don&#8217;t need to specify the <code>extension_registry</code> option since the extension will be enabled globally.<br>
To unregister all the extensions, you can use <code>asciidoctor.Extensions.unregisterAll()</code> function.</p>
</div>
      </div>
    </div>
  </article>
</div>
<div class="paragraph">
  
  <p>If you want to learn more about Asciidoctor.js extensions, please read the <a href="https://asciidoctor-docs.netlify.com/asciidoctor.js/extend/extensions/">User Manual</a>.</p>
</div>
<div class="paragraph">
  
  <p>Written with Asciidoctor.js 1.5.9.</p>
</div>]]></content:encoded>
  </item>
    </channel>
  </rss>