Class: Helios::Press::Post
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Helios::Press::Post
- Defined in:
- app/models/helios/press/post.rb
Instance Method Summary collapse
-
#og_image_url(view: nil) ⇒ Object
Absolute URL for the post's social-share image, sized to the OG- recommended 1200x630.
Instance Method Details
#og_image_url(view: nil) ⇒ Object
Absolute URL for the post's social-share image, sized to the OG-
recommended 1200x630. Prefers the explicit og_image override, then
falls back to the post's banner (the first attached image block). Returns
nil when neither exists, so helios-seo can fall back to its site-wide
default.
view is the ActionView context helios-seo passes into the resolver. We
use view.polymorphic_url so the result is the stable ActiveStorage
proxy/redirect URL (per the app's resolve_model_to_route) — absolute,
using the request host — NOT the short-lived signed service URL that
.url returns. Degrades to nil on any failure (e.g. no view context).
36 37 38 39 40 41 42 43 44 |
# File 'app/models/helios/press/post.rb', line 36 def og_image_url(view: nil) = og_image.attached? ? og_image : return nil unless && view variant = .variant(resize_to_limit: [ 1200, 630 ]) view.polymorphic_url(variant) rescue StandardError nil end |