diff --git a/plugins/metadata/lib/ext/profile.rb b/plugins/metadata/lib/ext/profile.rb index ce8c3f8..245c3f4 100644 --- a/plugins/metadata/lib/ext/profile.rb +++ b/plugins/metadata/lib/ext/profile.rb @@ -5,11 +5,8 @@ class Profile metadata_spec namespace: :og, tags: { type: proc{ |p, plugin| plugin.context.params[:og_type] || MetadataPlugin.og_types[:profile] || :profile }, image: proc{ |p, plugin| "#{p.environment.top_url}#{p.image.public_filename}" if p.image }, - title: proc{ |p, plugin| if p.nickname.present? then p.nickname else p.name end }, - url: proc do |p, plugin| - #force profile identifier for custom domains and fixed host. see og_url_for - plugin.og_url_for p.url.merge(profile: p.identifier) - end, + title: proc{ |p, plugin| if p.nickname.present? then p.nickname else p.name end }, + url: proc{ |p, plugin| plugin.og_url_for plugin.og_profile_url(p) }, description: proc{ |p, plugin| p.description }, updated_time: proc{ |p, plugin| p.updated_at.iso8601 }, 'locale:locale' => proc{ |p, plugin| p.environment.default_language }, diff --git a/plugins/metadata/lib/metadata_plugin/base.rb b/plugins/metadata/lib/metadata_plugin/base.rb index a54fee4..cfa9f5e 100644 --- a/plugins/metadata/lib/metadata_plugin/base.rb +++ b/plugins/metadata/lib/metadata_plugin/base.rb @@ -58,12 +58,7 @@ class MetadataPlugin::Base < Noosfero::Plugin end end - # context HELPERS - def og_url_for options - options.delete :port - options[:host] = self.class.config[:open_graph][:domain] rescue context.send(:environment).default_hostname - Noosfero::Application.routes.url_helpers.url_for options - end + include MetadataPlugin::UrlHelper def helpers self.context.class.helpers diff --git a/plugins/metadata/lib/metadata_plugin/url_helper.rb b/plugins/metadata/lib/metadata_plugin/url_helper.rb new file mode 100644 index 0000000..ed8a735 --- /dev/null +++ b/plugins/metadata/lib/metadata_plugin/url_helper.rb @@ -0,0 +1,23 @@ +module MetadataPlugin::UrlHelper + + def og_domain + MetadataPlugin.config[:open_graph][:domain] rescue context.send(:environment).default_hostname + end + + def og_url_for options + options.delete :port + options[:host] = self.og_domain + Noosfero::Application.routes.url_helpers.url_for options + end + + def og_profile_url profile + # open_graph client don't like redirects, give the exact url + if profile.home_page_id.present? + # force profile identifier for custom domains and fixed host. see og_url_for + profile.url.merge profile: profile.identifier + else + {controller: :profile, profile: profile.identifier} + end + end + +end -- libgit2 0.21.2