actually wire up auto alt tags. Finally fixes #782
This commit is contained in:
parent
238f992551
commit
b813db397f
2 changed files with 6 additions and 33 deletions
|
@ -87,4 +87,9 @@ require "middleman-more/extensions/lorem"
|
||||||
# and automatically adds width and height attributes to their HTML
|
# and automatically adds width and height attributes to their HTML
|
||||||
# elements.
|
# elements.
|
||||||
require "middleman-more/extensions/automatic_image_sizes"
|
require "middleman-more/extensions/automatic_image_sizes"
|
||||||
Middleman::Extensions::AutomaticImageSizes.register
|
Middleman::Extensions::AutomaticImageSizes.register
|
||||||
|
|
||||||
|
# AutomaticAltTags uses the file name of the `image_tag` to generate
|
||||||
|
# a default `:alt` value.
|
||||||
|
require "middleman-more/extensions/automatic_alt_tags"
|
||||||
|
Middleman::Extensions::AutomaticAltTags.register
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
# Automatic Image alt tags from image names extension
|
|
||||||
class Middleman::Extensions::AutomaticAltTags < ::Middleman::Extension
|
|
||||||
|
|
||||||
def initialize(app, options_hash={}, &block)
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
helpers do
|
|
||||||
# Override default image_tag helper to automatically insert alt tag
|
|
||||||
# containing image name.
|
|
||||||
|
|
||||||
def image_tag(path)
|
|
||||||
if !path.include?("://")
|
|
||||||
params[:alt] ||= ""
|
|
||||||
|
|
||||||
real_path = path
|
|
||||||
real_path = File.join(images_dir, real_path) unless real_path.start_with?('/')
|
|
||||||
full_path = File.join(source_dir, real_path)
|
|
||||||
|
|
||||||
if File.exists?(full_path)
|
|
||||||
begin
|
|
||||||
alt_text = File.basename(full_path, ".*")
|
|
||||||
alt_text.capitalize!
|
|
||||||
params[:alt] = alt_text
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
super(path)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Add table
Reference in a new issue