Class: Panda::CMS::Post
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Panda::CMS::Post
- Includes:
- Editor::Content
- Defined in:
- app/models/panda/cms/post.rb
Instance Method Summary collapse
- #admin_param ⇒ Object
-
#effective_canonical_url ⇒ String
Returns the effective canonical URL for this post Falls back to the post’s own URL if not explicitly set.
-
#effective_og_description ⇒ String?
Returns the effective Open Graph description Falls back to SEO description or excerpt.
-
#effective_og_title ⇒ String
Returns the effective Open Graph title Falls back to SEO title, then post title.
-
#effective_seo_description ⇒ String?
Returns the effective SEO description for this post Falls back to excerpt if not set.
-
#effective_seo_title ⇒ String
Returns the effective SEO title for this post Falls back to post title if not set.
- #excerpt(length = 100, squish: true) ⇒ Object
- #month ⇒ Object
-
#robots_meta_content ⇒ String
Generates the robots meta tag content based on seo_index_mode.
- #route_params ⇒ Object
- #to_param ⇒ Object
- #year ⇒ Object
Instance Method Details
#admin_param ⇒ Object
96 97 98 |
# File 'app/models/panda/cms/post.rb', line 96 def admin_param id end |
#effective_canonical_url ⇒ String
Returns the effective canonical URL for this post Falls back to the post’s own URL if not explicitly set
167 168 169 |
# File 'app/models/panda/cms/post.rb', line 167 def effective_canonical_url canonical_url.presence || slug end |
#effective_og_description ⇒ String?
Returns the effective Open Graph description Falls back to SEO description or excerpt
156 157 158 |
# File 'app/models/panda/cms/post.rb', line 156 def effective_og_description og_description.presence || effective_seo_description end |
#effective_og_title ⇒ String
Returns the effective Open Graph title Falls back to SEO title, then post title
145 146 147 |
# File 'app/models/panda/cms/post.rb', line 145 def effective_og_title og_title.presence || effective_seo_title end |
#effective_seo_description ⇒ String?
Returns the effective SEO description for this post Falls back to excerpt if not set
134 135 136 |
# File 'app/models/panda/cms/post.rb', line 134 def effective_seo_description seo_description.presence || excerpt(160, squish: true) end |
#effective_seo_title ⇒ String
Returns the effective SEO title for this post Falls back to post title if not set
123 124 125 |
# File 'app/models/panda/cms/post.rb', line 123 def effective_seo_title seo_title.presence || title end |
#excerpt(length = 100, squish: true) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/models/panda/cms/post.rb', line 100 def excerpt(length = 100, squish: true) return "" if content.blank? text = if content.is_a?(Hash) && content["blocks"] content["blocks"] .select { |block| block["type"] == "paragraph" } .map { |block| block["data"]["text"] } .join(" ") else content.to_s end text = text.squish if squish text.truncate(length).html_safe end |
#month ⇒ Object
82 83 84 85 86 |
# File 'app/models/panda/cms/post.rb', line 82 def month return nil unless slug.match?(%r{\A/\d{4}/\d{2}/}) slug.split("/")[2] end |
#robots_meta_content ⇒ String
Generates the robots meta tag content based on seo_index_mode
177 178 179 180 181 182 183 184 185 186 |
# File 'app/models/panda/cms/post.rb', line 177 def case seo_index_mode when "visible" "index, follow" when "invisible" "noindex, nofollow" else "index, follow" # Default fallback end end |
#route_params ⇒ Object
88 89 90 91 92 93 94 |
# File 'app/models/panda/cms/post.rb', line 88 def route_params if year && month {year: year, month: month, slug: to_param} else {slug: to_param} end end |
#to_param ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'app/models/panda/cms/post.rb', line 66 def to_param # For date-based URLs, return just the slug portion parts = CGI.unescape(slug).delete_prefix("/").split("/") if parts.length == 3 # year/month/slug format parts.last else parts.first end end |
#year ⇒ Object
76 77 78 79 80 |
# File 'app/models/panda/cms/post.rb', line 76 def year return nil unless slug.match?(%r{\A/\d{4}/}) slug.split("/")[1] end |