Welcome to mirror list, hosted at ThFree Co, Russian Federation.

meta_data_helper.rb « helpers « app - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4f12c3491b9d077645b62afcdc95c61be37ffe13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

module MetaDataHelper
  include ActionView::Helpers::AssetUrlHelper
  include ActionView::Helpers::TagHelper

  def og_prefix
    "og: https://ogp.me/ns# article: https://ogp.me/ns/article# profile: https://ogp.me/ns/profile#"
  end

  def site_url
    AppConfig.environment.url
  end

  def default_image_url
    asset_url("assets/branding/logos/asterisk.png", skip_pipeline: true)
  end

  def default_author_name
    AppConfig.settings.pod_name
  end

  def default_description
    AppConfig.settings.default_metas.description
  end

  def default_title
    AppConfig.settings.default_metas.title
  end

  def general_metas
    {
      description:    {name:     "description",  content: default_description},
      og_description: {property: "description",  content: default_description},
      og_site_name:   {property: "og:site_name", content: default_title},
      og_url:         {property: "og:url",       content: site_url},
      og_image:       {property: "og:image",     content: default_image_url},
      og_type:        {property: "og:type",      content: "website"}
    }
  end

  def metas_tags(attributes_list={}, with_general_metas=true)
    attributes_list = general_metas.merge(attributes_list) if with_general_metas
    attributes_list.map {|_, attributes| meta_tag attributes }.join("\n").html_safe
  end

  # recursively calls itself if attribute[:content] is an array
  # (metas such as og:image or og:tag can be present multiple times with different values)
  def meta_tag(attributes)
    return "" if attributes.empty?
    return tag(:meta, attributes) unless attributes[:content].respond_to?(:to_ary)
    items = attributes.delete(:content)
    items.map {|item| meta_tag(attributes.merge(content: item)) }.join("\n")
  end
end