Module: JekyllAeo::Schema::Article

Defined in:
lib/jekyll-aeo/schema/article.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
29
30
31
32
33
34
35
36
# File 'lib/jekyll-aeo/schema/article.rb', line 6

def self.build(page, site_config, _aeo_config = {})
  return nil unless page["date"]
  return nil if seo_tag_present?

  base_url = site_config["url"].to_s.chomp("/")
  baseurl = site_config["baseurl"].to_s.chomp("/")

  schema = {
    "@context" => "https://schema.org",
    "@type" => "Article",
    "headline" => page["title"] || "",
    "url" => "#{base_url}#{baseurl}#{page['url']}",
    "datePublished" => format_date(page["date"])
  }

  description = page["description"] || page["excerpt"]
  schema["description"] = description.to_s if description

  author = page["author"]
  if author
    schema["author"] = {
      "@type" => "Person",
      "name" => author
    }
  end

  lm = page["last_modified_at"]
  schema["dateModified"] = format_date(lm) if lm

  schema
end