Skip to content

Torna carregamento de imagens "lazy" com extensão do asciidoctor (extensão asciidoctor) #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions ferramentas/addLazyLoadingImages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
include Asciidoctor

class AddLazyLoadingImages < Asciidoctor::Extensions::Postprocessor
def process document, output
if document.basebackend? 'html'
replacement = %(<img loading="lazy" \\1>)
output = output.gsub(/<img(.*?)>/m, replacement)
end
output
end
end

Asciidoctor::Extensions.register do
postprocessor AddLazyLoadingImages
end

Asciidoctor.convert_file 'livro.adoc', safe: :safe


3 changes: 1 addition & 2 deletions livro.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ include::atributos-pt_BR.adoc[]
:xrefstyle: short
:sectnums:
:sectlinks:
:data-uri:
:toc:
:toclevels: 2
:!chapter-signifier:
Expand Down Expand Up @@ -159,4 +158,4 @@ include::capitulos/cap21.adoc[]

== 🚧 Descritores de atributos

== 🚧 Metaprogramação com classes
== 🚧 Metaprogramação com classes