content/photos/dog.jpg
content/photos/dog.yaml
:
alt: A *very* good doggo. Who’s a good girl? woof woof yes you are YOU ARE
Rules
:
# …
compile '/photos/*' do
# Write it to the exact same location
write item.identifier
end
# For each photo, additionaly create another representation (called `detail` here but it could be anything).
compile '/photos/*', rep: :detail do
filter :alt_to_content
filter :kramdown
layout '/default.*'
write ext: 'html'
end
lib/filters/alt-to-content.rb
:
Class.new(Nanoc::Filter) do
identifier :alt_to_content
# This filter applies to binary items, but returns textual content.
type :binary => :text
def run(content, params = {})
# Extract the alt text from the attributes
@item[:alt]
end
end