Sha256: f46fd35ab1f5f393d3d941552129a4e274f7891f5914af187ba2d6999e23bb0f

Contents?: true

Size: 1.65 KB

Versions: 18

Compression:

Stored size: 1.65 KB

Contents

# ogp.rb - add Open Graph Protocol <meta> tags to header
#
# Copyright (c) 2011 MATSUOKA Kohei <kmachu@gmail.com>
# 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
	section_index = @cgi.params['p'][0]
	# section_index = "1"
	if @mode == 'day' and section_index
		diary = @diaries[@date.strftime('%Y%m%d')]
		sections = diary.instance_variable_get(:@sections)
		section = sections[section_index.to_i - 1].body_to_html
		@conf.shorten(apply_plugin(section, true), 200)
	else
		@conf.description
	end
end

add_header_proc do
	headers = {
		# TODO: og:urlへ対応
		'og:title' => title_tag.match(/>([^<]+)</).to_a[1],
		'og:site_name' => @conf.html_title,
		'og:description' => ogp_description,
		'og:image' => @conf.banner,
		'og:type' => (@mode == 'day') ? 'article' : 'blog',
		'og:author' => @conf.author_name,
		'fb:app_id' => @conf['ogp.facebook.app_id'],
		'fb:admins' => @conf['ogp.facebook.admins']
	}
	headers.select {|key, val|
		val && !val.empty?
	}.map {|key, val|
		%Q|<meta property="#{key}" content="#{CGI::escapeHTML(val)}">|
	}.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
	<h3>Facebook Application ID</h3>
	<p><input name="ogp.facebook.app_id" value="#{h(@conf['ogp.facebook.app_id'])}"></p>

	<h3>Facebook User ID</h3>
	<p><input name="ogp.facebook.admins" value="#{h(@conf['ogp.facebook.admins'])}"></p>
	HTML
end

Version data entries

18 entries across 17 versions & 2 rubygems

Version Path
tdiary-contrib-5.0.2 plugin/ogp.rb
tdiary-contrib-5.0.1 plugin/ogp.rb
tdiary-contrib-5.0.0 plugin/ogp.rb
tdiary-contrib-4.2.1 plugin/ogp.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/bundler/gems/tdiary-contrib-2ab36447ae2a/plugin/ogp.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/bundler/gems/tdiary-contrib-d189eb6688f1/plugin/ogp.rb
tdiary-contrib-4.2.0 plugin/ogp.rb
tdiary-contrib-4.1.3 plugin/ogp.rb
tdiary-contrib-4.1.2 plugin/ogp.rb
tdiary-contrib-4.1.1 plugin/ogp.rb
tdiary-contrib-4.1.0 plugin/ogp.rb
tdiary-contrib-4.0.5.1 plugin/ogp.rb
tdiary-contrib-4.0.4 plugin/ogp.rb
tdiary-contrib-4.0.3 plugin/ogp.rb
tdiary-contrib-4.0.2.1 plugin/ogp.rb
tdiary-contrib-4.0.2 plugin/ogp.rb
tdiary-contrib-3.2.2.20130614 plugin/ogp.rb
tdiary-contrib-3.2.2.20130518 plugin/ogp.rb