Skip to content

Commit

Permalink
Merge pull request #629 from tdiary/fix-multiple-og-image
Browse files Browse the repository at this point in the history
fix multiple og:image meta tags
  • Loading branch information
tdtds committed May 19, 2017
2 parents 350e5bf + ce5bbad commit cf7aebe
Showing 1 changed file with 22 additions and 30 deletions.
52 changes: 22 additions & 30 deletions lib/tdiary/plugin/00default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def doctype
#{author_mail_tag}
#{index_page_tag}
#{icon_tag}
#{default_ogp}
#{ogp_tag}
#{description_tag}
#{css_tag.chomp}
#{jquery_tag.chomp}
Expand Down Expand Up @@ -322,37 +322,29 @@ def icon_tag
end
end

def default_ogp
if @conf.options2['sp.selected'] && @conf.options2['sp.selected'].include?('ogp.rb')
if defined?(@conf.banner)
%Q[<meta content="#{base_url}images/ogimage.png" property="og:image">]
end
def ogp_tag
uri = @conf.index.dup
uri[0, 0] = base_url if %r|^https?://|i !~ @conf.index
uri.gsub!( %r|/\./|, '/' )
image = (@conf.banner.nil? || @conf.banner == '') ? File.join(uri, "#{theme_url}/ogimage.png") : @conf.banner
ogp = {
'og:title' => title_tag.gsub(/<[^>]*>/, ""),
'og:image' => image,
}
if @mode == 'day' then
ogp['og:type'] = 'article'
ogp['article:author'] = @conf.author_name
ogp['og:site_name'] = @conf.html_title
ogp['og:url'] = uri + anchor( @date.strftime( '%Y%m%d' ) )
else
uri = @conf.index.dup
uri[0, 0] = base_url if %r|^https?://|i !~ @conf.index
uri.gsub!( %r|/\./|, '/' )
image = @conf.banner.nil? ? File.join(uri, "#{theme_url}/ogimage.png") : @conf.banner
ogp = {
'og:title' => title_tag.gsub(/<[^>]*>/, ""),
'og:image' => (h image),
}
ogp['fb:app_id'] = @conf['ogp.facebook.app_id']
ogp['fb:admins'] = @conf['ogp.facebook.admins']
if @mode == 'day' then
ogp['og:type'] = 'article'
ogp['article:author'] = @conf.author_name
ogp['og:site_name'] = @conf.html_title
ogp['og:url'] = h(uri + anchor( @date.strftime( '%Y%m%d' ) ))
else
ogp['og:type'] = 'website'
ogp['og:description'] = h(@conf.description)
ogp['og:url'] = h(uri)
end

ogp.map { |k, v|
%Q|<meta property="#{k}" content="#{v}">|
}.join("\n")
ogp['og:type'] = 'website'
ogp['og:description'] = @conf.description
ogp['og:url'] = uri
end

ogp.map { |k, v|
%Q|<meta property="#{k}" content="#{h(v)}">|
}.join("\n")
end

def description_tag
Expand Down

0 comments on commit cf7aebe

Please sign in to comment.