Commit be35b4641d099338b2b2b8b92138c7652d707f93
1 parent
1df5fcff
Exists in
master
and in
9 other branches
metadata: give url without redirects for profiles
Showing
3 changed files
with
26 additions
and
11 deletions
Show diff stats
plugins/metadata/lib/ext/profile.rb
| @@ -5,11 +5,8 @@ class Profile | @@ -5,11 +5,8 @@ class Profile | ||
| 5 | metadata_spec namespace: :og, tags: { | 5 | metadata_spec namespace: :og, tags: { |
| 6 | type: proc{ |p, plugin| plugin.context.params[:og_type] || MetadataPlugin.og_types[:profile] || :profile }, | 6 | type: proc{ |p, plugin| plugin.context.params[:og_type] || MetadataPlugin.og_types[:profile] || :profile }, |
| 7 | image: proc{ |p, plugin| "#{p.environment.top_url}#{p.image.public_filename}" if p.image }, | 7 | image: proc{ |p, plugin| "#{p.environment.top_url}#{p.image.public_filename}" if p.image }, |
| 8 | - title: proc{ |p, plugin| if p.nickname.present? then p.nickname else p.name end }, | ||
| 9 | - url: proc do |p, plugin| | ||
| 10 | - #force profile identifier for custom domains and fixed host. see og_url_for | ||
| 11 | - plugin.og_url_for p.url.merge(profile: p.identifier) | ||
| 12 | - end, | 8 | + title: proc{ |p, plugin| if p.nickname.present? then p.nickname else p.name end }, |
| 9 | + url: proc{ |p, plugin| plugin.og_url_for plugin.og_profile_url(p) }, | ||
| 13 | description: proc{ |p, plugin| p.description }, | 10 | description: proc{ |p, plugin| p.description }, |
| 14 | updated_time: proc{ |p, plugin| p.updated_at.iso8601 }, | 11 | updated_time: proc{ |p, plugin| p.updated_at.iso8601 }, |
| 15 | 'locale:locale' => proc{ |p, plugin| p.environment.default_language }, | 12 | 'locale:locale' => proc{ |p, plugin| p.environment.default_language }, |
plugins/metadata/lib/metadata_plugin/base.rb
| @@ -58,12 +58,7 @@ class MetadataPlugin::Base < Noosfero::Plugin | @@ -58,12 +58,7 @@ class MetadataPlugin::Base < Noosfero::Plugin | ||
| 58 | end | 58 | end |
| 59 | end | 59 | end |
| 60 | 60 | ||
| 61 | - # context HELPERS | ||
| 62 | - def og_url_for options | ||
| 63 | - options.delete :port | ||
| 64 | - options[:host] = self.class.config[:open_graph][:domain] rescue context.send(:environment).default_hostname | ||
| 65 | - Noosfero::Application.routes.url_helpers.url_for options | ||
| 66 | - end | 61 | + include MetadataPlugin::UrlHelper |
| 67 | 62 | ||
| 68 | def helpers | 63 | def helpers |
| 69 | self.context.class.helpers | 64 | self.context.class.helpers |
| @@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
| 1 | +module MetadataPlugin::UrlHelper | ||
| 2 | + | ||
| 3 | + def og_domain | ||
| 4 | + MetadataPlugin.config[:open_graph][:domain] rescue context.send(:environment).default_hostname | ||
| 5 | + end | ||
| 6 | + | ||
| 7 | + def og_url_for options | ||
| 8 | + options.delete :port | ||
| 9 | + options[:host] = self.og_domain | ||
| 10 | + Noosfero::Application.routes.url_helpers.url_for options | ||
| 11 | + end | ||
| 12 | + | ||
| 13 | + def og_profile_url profile | ||
| 14 | + # open_graph client don't like redirects, give the exact url | ||
| 15 | + if profile.home_page_id.present? | ||
| 16 | + # force profile identifier for custom domains and fixed host. see og_url_for | ||
| 17 | + profile.url.merge profile: profile.identifier | ||
| 18 | + else | ||
| 19 | + {controller: :profile, profile: profile.identifier} | ||
| 20 | + end | ||
| 21 | + end | ||
| 22 | + | ||
| 23 | +end |