Class: Panda::CMS::Page

Inherits:
ApplicationRecord show all
Defined in:
app/models/panda/cms/page.rb

Instance Method Summary collapse

Instance Method Details

#effective_canonical_urlString

Returns the effective canonical URL for this page Falls back to the page’s own URL if not explicitly set

Returns:

  • (String)

    The canonical URL to use



177
178
179
# File 'app/models/panda/cms/page.rb', line 177

def effective_canonical_url
  canonical_url.presence || path
end

#effective_og_descriptionString?

Returns the effective Open Graph description Falls back to SEO description

Returns:

  • (String, nil)

    The OG description to use



166
167
168
# File 'app/models/panda/cms/page.rb', line 166

def effective_og_description
  og_description.presence || effective_seo_description
end

#effective_og_titleString

Returns the effective Open Graph title Falls back to SEO title, then page title

Returns:

  • (String)

    The OG title to use



155
156
157
# File 'app/models/panda/cms/page.rb', line 155

def effective_og_title
  og_title.presence || effective_seo_title
end

#effective_seo_descriptionString?

Returns the effective SEO description for this page With optional inheritance from parent pages

Returns:

  • (String, nil)

    The SEO description to use



141
142
143
144
145
146
# File 'app/models/panda/cms/page.rb', line 141

def effective_seo_description
  return seo_description if seo_description.present?
  return nil unless inherit_seo

  self_and_ancestors.reverse.find { |p| p.seo_description.present? }&.seo_description
end

#effective_seo_titleString

Returns the effective SEO title for this page Falls back to page title if not set, with optional inheritance

Returns:

  • (String)

    The SEO title to use



126
127
128
129
130
131
132
# File 'app/models/panda/cms/page.rb', line 126

def effective_seo_title
  return seo_title if seo_title.present?
  return title unless inherit_seo

  # Traverse up tree to find inherited value
  self_and_ancestors.reverse.find { |p| p.seo_title.present? }&.seo_title || title
end

#last_updated_atTime

Returns the most recent update time between the page and its block contents Uses cached value for performance

Returns:

  • (Time)

    The most recent updated_at timestamp



101
102
103
# File 'app/models/panda/cms/page.rb', line 101

def last_updated_at
  cached_last_updated_at || updated_at
end

#refresh_last_updated_at!Time

Refresh the cached last updated timestamp Used when block contents are updated

Returns:

  • (Time)

    The updated timestamp



112
113
114
115
116
117
# File 'app/models/panda/cms/page.rb', line 112

def refresh_last_updated_at!
  block_content_updated_at = block_contents.maximum(:updated_at)
  new_timestamp = [updated_at, block_content_updated_at].compact.max
  update_column(:cached_last_updated_at, new_timestamp)
  new_timestamp
end

#robots_meta_contentString

Generates the robots meta tag content based on seo_index_mode

Returns:

  • (String)

    The robots meta tag content (e.g., “index, follow”)



187
188
189
190
191
192
193
194
195
196
# File 'app/models/panda/cms/page.rb', line 187

def robots_meta_content
  case seo_index_mode
  when "visible"
    "index, follow"
  when "invisible"
    "noindex, nofollow"
  else
    "index, follow" # Default fallback
  end
end

#update_auto_menusObject

Update any menus which include this page or its parent as a menu item

Returns:

  • nil



89
90
91
92
# File 'app/models/panda/cms/page.rb', line 89

def update_auto_menus
  menus.find_each(&:generate_auto_menu_items)
  menus_of_parent.find_each(&:generate_auto_menu_items)
end