Class: Oembed::PostProvider
- Inherits:
-
Object
- Object
- Oembed::PostProvider
- Defined in:
- app/services/oembed/post_provider.rb
Overview
Consumer-facing oEmbed provider for WarmlyYours blog posts (Radiant Journal).
Unlike the product / video / image / faq providers — which serve the Redactor
editor's embed pickers — this one is outbound: it backs the
<link rel="alternate" type="application/json+oembed"> discovery tags on
blog-post pages so embedders (iframely/Gamma, Slack, Notion, WordPress,
Discord, Microsoft Teams, …) resolve the post's canonical title, description,
and thumbnail instead of scraping the page's meta.
Why this exists: blog posts embed product cards whose oEmbed renderer also
emits standalone schema.org/Product JSON-LD (see ProductProvider).
Consumers that scrape structured data were promoting the last in-article
Product over our Open Graph tags, so a bathroom-safety article surfaced as
"Judy 36ʺ LED Mirror". A declared oEmbed endpoint outranks scraped meta, so
advertising one fixes every oEmbed consumer at once while leaving the Product
rich-results intact.
Returns an oEmbed 1.0 link-type response plus the widely honored
description extension (iframely, Slack, and Notion all read it).
Usage:
provider = Oembed::PostProvider.new
provider.handles?('https://www.warmlyyours.com/en-US/posts/some-slug') # => true
provider.get('https://www.warmlyyours.com/en-US/posts/some-slug')
=> { version: '1.0', type: 'link', title: '…', description: '…', … }
Defined Under Namespace
Classes: PostNotFoundError
Constant Summary collapse
- PROVIDER_NAME =
'WarmlyYours'- PROVIDER_URL =
WEB_URL- DESCRIPTION_LENGTH =
160- POST_PATH_REGEX =
Matches the slug segment of a blog-post path: /posts/ or
/en-US/posts/. Stops at the first /, ?, or # after the slug. %r{/posts/(?<slug>[^/?#]+)}
Instance Method Summary collapse
-
#get(url, _options = {}) ⇒ Hash
Build the oEmbed response hash for a blog-post URL.
-
#handles?(url) ⇒ Boolean
Does this URL look like a WarmlyYours blog-post URL we can resolve?.
Instance Method Details
#get(url, _options = {}) ⇒ Hash
Build the oEmbed response hash for a blog-post URL.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/services/oembed/post_provider.rb', line 64 def get(url, = {}) slug = slug_from_url(url) raise PostNotFoundError, "Not a blog-post URL: #{url}" if slug.blank? I18n.with_locale(locale_from_url(url)) do post = find_published_post(slug) raise PostNotFoundError, "Post not found: #{slug}" if post.nil? build_response(post) end end |
#handles?(url) ⇒ Boolean
Does this URL look like a WarmlyYours blog-post URL we can resolve?
47 48 49 50 51 52 53 54 55 |
# File 'app/services/oembed/post_provider.rb', line 47 def handles?(url) uri = URI.parse(url.to_s) return false if uri.host.blank? return false unless uri.host.include?('warmlyyours') || uri.host.end_with?(WEB_HOSTNAME_WITHOUT_PORT) uri.path.to_s.match?(POST_PATH_REGEX) rescue URI::InvalidURIError false end |