Module: Goldencobra::ArticleConcerns::MetaTag

Extended by:
ActiveSupport::Concern
Included in:
Goldencobra::Article
Defined in:
app/models/goldencobra/article_concerns/meta_tag.rb

Overview

Meta Tags fuer einen Goldencobra::Article

Ueber diese Methoden kann einheitlich auf die Metatags zugegriffen werden. Die Regeln zur Erstellung der MetaTags und deren Fallbacks koennen so zentral gesteuert werden

Instance Method Summary collapse

Instance Method Details

#combined_meta_tagsObject



67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/models/goldencobra/article_concerns/meta_tag.rb', line 67

def combined_meta_tags
  {
    site: meta_tag_site,
    title: meta_tag_title_tag,
    separator: " ",
    reverse: true,
    description: meta_tag_meta_description,
    canonical: meta_tag_canonical_url,
    open_graph: combined_open_graph_tags,
    noindex: robots_no_index
  }.merge(meta_tag_static_custom)
end

#combined_open_graph_tagsObject



80
81
82
83
84
85
86
87
88
# File 'app/models/goldencobra/article_concerns/meta_tag.rb', line 80

def combined_open_graph_tags
  {
    title: meta_tag_open_graph_title,
    description: meta_tag_open_graph_description,
    type: meta_tag_open_graph_type,
    url: meta_tag_open_graph_url,
    image: meta_tag_open_graph_image
  }
end

#meta_tag_canonical_urlObject



49
50
51
# File 'app/models/goldencobra/article_concerns/meta_tag.rb', line 49

def meta_tag_canonical_url
  get_meta_value(:canonical_url, :absolute_public_url)
end

#meta_tag_meta_descriptionObject



19
20
21
# File 'app/models/goldencobra/article_concerns/meta_tag.rb', line 19

def meta_tag_meta_description
  get_meta_value(:metatag_meta_description, :teaser)
end

#meta_tag_open_graph_descriptionObject



27
28
29
# File 'app/models/goldencobra/article_concerns/meta_tag.rb', line 27

def meta_tag_open_graph_description
  get_meta_value(:metatag_open_graph_description, :metatag_meta_description, :teaser)
end

#meta_tag_open_graph_imageObject



39
40
41
42
43
44
45
46
47
# File 'app/models/goldencobra/article_concerns/meta_tag.rb', line 39

def meta_tag_open_graph_image
  if metatag_open_graph_image.present?
    og_image_url = metatag_open_graph_image
  else
    og_image_url = images.first.try(:image).try(:url)
  end
  og_image_fallback = Goldencobra::Setting.for_key("goldencobra.facebook.opengraph_default_image")
  og_image_url.present? ? og_image_url : og_image_fallback
end

#meta_tag_open_graph_titleObject



23
24
25
# File 'app/models/goldencobra/article_concerns/meta_tag.rb', line 23

def meta_tag_open_graph_title
  get_meta_value(:metatag_open_graph_title, :metatag_title_tag, :breadcrumb, :title)
end

#meta_tag_open_graph_typeObject



31
32
33
# File 'app/models/goldencobra/article_concerns/meta_tag.rb', line 31

def meta_tag_open_graph_type
  metatag_open_graph_type.present? ? metatag_open_graph_type : "website"
end

#meta_tag_open_graph_urlObject



35
36
37
# File 'app/models/goldencobra/article_concerns/meta_tag.rb', line 35

def meta_tag_open_graph_url
  get_meta_value(:metatag_open_graph_url, :absolute_public_url)
end

#meta_tag_siteObject



11
12
13
# File 'app/models/goldencobra/article_concerns/meta_tag.rb', line 11

def meta_tag_site
  Goldencobra::Setting.for_key("goldencobra.page.default_title_tag")
end

#meta_tag_static_customHash

Generate a hash of custom_tags in settings every children in goldencobra.page.custom_tags will by a custom meta_tag. Esisting tags (canonical, noindex,… ) will be overwritten by custom tags with the same name

Returns:

  • (Hash)

    “MyValue”, custom_tag: “otherValue”



59
60
61
62
63
64
65
# File 'app/models/goldencobra/article_concerns/meta_tag.rb', line 59

def meta_tag_static_custom
  custom_tag_settings = Goldencobra::Setting.where(title: "custom_tags").first
  return {} if custom_tag_settings.blank?
  if custom_tag_settings.present? && custom_tag_settings.parent_names == "goldencobra.page"
    Hash[custom_tag_settings.children.map { |s| [s.title.to_sym, s.value] }]
  end
end

#meta_tag_title_tagObject



15
16
17
# File 'app/models/goldencobra/article_concerns/meta_tag.rb', line 15

def meta_tag_title_tag
  get_meta_value(:metatag_title_tag, :breadcrumb)
end