mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
Add JSON-LD to Universes
This commit is contained in:
parent
ccc2aeef24
commit
b817cdf1fe
@ -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,
|
||||
|
||||
@ -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 %>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user