From b817cdf1fe71811efa65d4e3f9afe24304dce348 Mon Sep 17 00:00:00 2001 From: Robert Richter Date: Tue, 6 Sep 2016 10:36:16 -0500 Subject: [PATCH] Add JSON-LD to Universes --- app/models/universe.rb | 12 ++++++++++++ app/views/content/_show.html.erb | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/app/models/universe.rb b/app/models/universe.rb index d0c446fc..86a5a547 100644 --- a/app/models/universe.rb +++ b/app/models/universe.rb @@ -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, diff --git a/app/views/content/_show.html.erb b/app/views/content/_show.html.erb index 15d84723..d3ee89de 100644 --- a/app/views/content/_show.html.erb +++ b/app/views/content/_show.html.erb @@ -1,3 +1,10 @@ +<% if @content.present? && @content.respond_to?(:as_jsonld) %> + +<% end %> + + <% title @content.name %> <% content_for :sidebar_top do %>