Class: JekyllAeo::Tags::AeoJsonLd

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-aeo/tags/aeo_json_ld.rb

Constant Summary collapse

BUILDERS =
[
  JekyllAeo::Schema::FaqPage,
  JekyllAeo::Schema::HowTo,
  JekyllAeo::Schema::BreadcrumbList,
  JekyllAeo::Schema::Organization,
  JekyllAeo::Schema::Speakable,
  JekyllAeo::Schema::Article
].freeze

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jekyll-aeo/tags/aeo_json_ld.rb', line 17

def render(context)
  site = context.registers[:site]
  page = context.registers[:page]

  aeo_config = JekyllAeo::Config.from_site(site)
  results = BUILDERS.filter_map { |builder| builder.build(page, site.config, aeo_config) }

  results.map do |schema|
    json = JSON.pretty_generate(schema).gsub("</", "<\\/")
    "<script type=\"application/ld+json\">\n#{json}\n</script>"
  end.join("\n")
end