Add JSON-LD to Universes

This commit is contained in:
Robert Richter 2016-09-06 10:36:16 -05:00
parent ccc2aeef24
commit b817cdf1fe
No known key found for this signature in database
GPG Key ID: BEC39BF873A0103B
2 changed files with 19 additions and 0 deletions

View File

@ -6,6 +6,7 @@
#
# contains all canonically-related content created by Users
class Universe < ActiveRecord::Base
include PragmaticContext::Contextualizable
validates :name, presence: true
belongs_to :user
@ -15,6 +16,17 @@ class Universe < ActiveRecord::Base
scope :is_public, -> { where(privacy: "public") }
# Used for JSON-LD generation
contextualize_as_type 'http://schema.org/CreativeWork'
contextualize_with_id { |universe| Rails.application.routes.url_helpers.universe_url(universe) }
contextualize :user, as: 'http://schema.org/author'
contextualize :user, as: 'http://schema.org/copyrightHolder'
contextualize :characters, as: 'http://schema.org/character'
contextualize :items, as: 'http://schema.org/hasPart'
contextualize :locations, as: 'http://schema.org/hasPart'
contextualize :name, :as => 'http://schema.org/name'
contextualize :description, :as => 'http://schema.org/description'
def content_count
[
characters.length,

View File

@ -1,3 +1,10 @@
<% if @content.present? && @content.respond_to?(:as_jsonld) %>
<script type="application/ld+json">
<%= @content.as_jsonld.to_json.html_safe %>
</script>
<% end %>
<% title @content.name %>
<% content_for :sidebar_top do %>