Module: Panda::CMS::SEOHelper

Defined in:
app/helpers/panda/cms/seo_helper.rb

Instance Method Summary collapse

Instance Method Details

#render_seo_meta_tags(resource) ⇒ String

Renders all SEO meta tags for a given page or post

Parameters:

Returns:

  • (String)

    HTML meta tags



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
# File 'app/helpers/panda/cms/seo_helper.rb', line 13

def render_seo_meta_tags(resource)
  return "" if resource.blank?

  tags = []

  # Basic SEO tags
  tags << tag.meta(name: "description", content: resource.effective_seo_description) if resource.effective_seo_description.present?
  tags << tag.meta(name: "keywords", content: resource.seo_keywords) if resource.seo_keywords.present?
  tags << tag.meta(name: "robots", content: resource.robots_meta_content)
  tags << tag.link(rel: "canonical", href: canonical_url_for(resource))

  # Open Graph tags
  tags << tag.meta(property: "og:title", content: resource.effective_og_title)
  tags << tag.meta(property: "og:description", content: resource.effective_og_description) if resource.effective_og_description.present?
  tags << tag.meta(property: "og:type", content: resource.og_type)
  tags << tag.meta(property: "og:url", content: canonical_url_for(resource))

  # Open Graph image
  if resource.og_image.attached?
    og_image_url = url_for(resource.og_image.variant(:og_share))
    tags << tag.meta(property: "og:image", content: og_image_url)
    tags << tag.meta(property: "og:image:width", content: "1200")
    tags << tag.meta(property: "og:image:height", content: "630")
  end

  # Twitter Card tags (with fallback to OG)
  tags << tag.meta(name: "twitter:card", content: "summary_large_image")
  tags << tag.meta(name: "twitter:title", content: resource.effective_og_title)
  tags << tag.meta(name: "twitter:description", content: resource.effective_og_description) if resource.effective_og_description.present?

  # Twitter image (same as OG)
  if resource.og_image.attached?
    tags << tag.meta(name: "twitter:image", content: url_for(resource.og_image.variant(:og_share)))
  end

  safe_join(tags, "\n")
end

#seo_title(resource, separator: " · ", site_name: nil) ⇒ String

Renders just the page title with SEO optimization

Parameters:

  • resource (Panda::CMS::Page, Panda::CMS::Post)

    The page or post

  • separator (String) (defaults to: " · ")

    Separator between page title and site name

  • site_name (String) (defaults to: nil)

    The site name (optional)

Returns:

  • (String)

    Formatted page title



60
61
62
63
64
# File 'app/helpers/panda/cms/seo_helper.rb', line 60

def seo_title(resource, separator: " · ", site_name: nil)
  parts = [resource.effective_seo_title]
  parts << site_name if site_name.present?
  safe_join(parts, separator)
end