# ogp.rb - add Open Graph Protocol tags to header # # Copyright (c) 2011 MATSUOKA Kohei # You can redistribute it and/or modify it under GPL2. # # @conf['ogp.facebook.app_id'] - your facebook application ID. # @conf['ogp.facebook.admins'] - your facebook ID. def ogp_description(html) @conf.shorten(remove_tag(html), 200) end def ogp_image(html) images = html.scan(/ @conf['ogp.facebook.app_id'], 'fb:admins' => @conf['ogp.facebook.admins'] } if @mode == 'day' # remove original og:image generated at 00default.rb ogp.gsub!(/]+>\n/, '') diary = @diaries[@date.strftime('%Y%m%d')] if diary sections = diary.instance_variable_get(:@sections) section_index = @cgi.params['p'][0] || sections.size section = sections[section_index.to_i - 1].body_to_html section_html = apply_plugin(section) headers['og:description'] = ogp_description(section_html) headers['og:image'] = ogp_image(section_html) end end ogp + "\n" + headers.select {|key, val| val && !val.empty? }.map {|key, val| %Q|| }.join("\n") end add_conf_proc('Open Graph Protocol', 'Open Graph Protocol') do if @mode == 'saveconf' @conf['ogp.facebook.app_id'] = @cgi.params['ogp.facebook.app_id'][0] @conf['ogp.facebook.admins'] = @cgi.params['ogp.facebook.admins'][0] end <<-HTML

Facebook Application ID

Facebook User ID

HTML end