From 948a0919760c911b827d2a96dc717e0d14090cbf Mon Sep 17 00:00:00 2001 From: Arturo Fonseca Date: Fri, 21 Apr 2023 22:12:37 -0300 Subject: [PATCH] =?UTF-8?q?torna=20carregamento=20de=20imagens=20"lazy"=20?= =?UTF-8?q?com=20extens=C3=A3o=20do=20asciidoctor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Isso é feito criando uma extensão de pós-processamento do asciidoctor que adiciona, com regex, a string 'loading="lazy"' para cada elemento "img" no final do processamento do arquivo HTML de saída. --- build.sh | 2 +- ferramentas/addLazyLoadingImages.rb | 19 +++++++++++++++++++ livro.adoc | 3 +-- 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 ferramentas/addLazyLoadingImages.rb diff --git a/build.sh b/build.sh index 58267c1..7b4376a 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e # exit when any command fails -asciidoctor livro.adoc -o index.html +asciidoctor -r ./ferramentas/addLazyLoadingImages.rb livro.adoc -o index.html open index.html diff --git a/ferramentas/addLazyLoadingImages.rb b/ferramentas/addLazyLoadingImages.rb new file mode 100644 index 0000000..078986c --- /dev/null +++ b/ferramentas/addLazyLoadingImages.rb @@ -0,0 +1,19 @@ +include Asciidoctor + +class AddLazyLoadingImages < Asciidoctor::Extensions::Postprocessor + def process document, output + if document.basebackend? 'html' + replacement = %() + output = output.gsub(//m, replacement) + end + output + end +end + +Asciidoctor::Extensions.register do + postprocessor AddLazyLoadingImages +end + +Asciidoctor.convert_file 'livro.adoc', safe: :safe + + diff --git a/livro.adoc b/livro.adoc index 1c4c379..8c1d1ef 100644 --- a/livro.adoc +++ b/livro.adoc @@ -7,7 +7,6 @@ include::atributos-pt_BR.adoc[] :xrefstyle: short :sectnums: :sectlinks: -:data-uri: :toc: :toclevels: 2 :!chapter-signifier: @@ -159,4 +158,4 @@ include::capitulos/cap21.adoc[] == 🚧 Descritores de atributos -== 🚧 Metaprogramação com classes \ No newline at end of file +== 🚧 Metaprogramação com classes