Skip to content

Commit d3066e1

Browse files
committed
Use .jpg, .jpeg, or .png for OGP images in Docs
1 parent a2c5c75 commit d3066e1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

app/controllers/docs_controller.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ def show
2929
@content = Kramdown::Document.new(@doc.content, input: 'GFM').to_html
3030
@url = request.url
3131
@meta_image = Nokogiri::HTML.parse(@content).at("//img")&.attribute('data-src')&.value || "/img/ogp-docs.jpeg"
32+
if @meta_image.end_with? '.webp'
33+
# .webp -> .jpg
34+
# .webp -> .png
35+
@meta_image.gsub!('.webp', '.jpg') if File.exists? "public/#{@meta_image[0..-6]}.jpg"
36+
@meta_image.gsub!('.webp', '.jpeg') if File.exists? "public/#{@meta_image[0..-6]}.jpeg"
37+
@meta_image.gsub!('.webp', '.png') if File.exists? "public/#{@meta_image[0..-6]}.png"
38+
end
3239

3340
# Add here if you want to optimize meta description.
3441
case @doc.filename

0 commit comments

Comments
 (0)