Module: JekyllAeo::Schema::Speakable

Defined in:
lib/jekyll-aeo/schema/speakable.rb

Class Method Summary collapse

Class Method Details

.build(page, site_config, _aeo_config = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jekyll-aeo/schema/speakable.rb', line 6

def self.build(page, site_config, _aeo_config = {})
  return nil unless page["speakable"] == true

  base_url = site_config["url"].to_s.chomp("/")
  baseurl = site_config["baseurl"].to_s.chomp("/")
  url = "#{base_url}#{baseurl}#{page['url']}"

  selectors = [
    ".post-title, .page-title, h1",
    ".post-content p:first-of-type, .page-content p:first-of-type"
  ]

  {
    "@context" => "https://schema.org",
    "@type" => "WebPage",
    "name" => page["title"] || "",
    "url" => url,
    "speakable" => {
      "@type" => "SpeakableSpecification",
      "cssSelector" => selectors
    }
  }
end