Skip to content

Instantly share code, notes, and snippets.

@xkraty
Created March 16, 2016 14:57
Show Gist options
  • Save xkraty/d36407ac14e1ee6adec2 to your computer and use it in GitHub Desktop.
Save xkraty/d36407ac14e1ee6adec2 to your computer and use it in GitHub Desktop.
class Frontend::MetaTagsCell < Cell::ViewModel
include MetaTags::ViewHelper
def set
translate = ['seo', controller.controller_name, controller.action_name]
set_meta_tags %i(title description).map { |m| [m, (I18n.translate!(m, scope: translate) rescue nil)] }.to_h
alternate = []
params = request.path_parameters
params[:locale] = I18n.default_locale
alternate << {
href: url_for(params),
rel: "alternate",
hreflang: "x-default"
}
I18n.available_locales.each do |l|
params[:locale] = l
tmp = {}
tmp[:href] = url_for(params)
tmp[:rel] = "alternate"
if I18n.locale == l
tmp[:rel] = "canonical"
else
tmp[:hreflang] = l
end
alternate << tmp
end
set_meta_tags alternate: alternate
render
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment