Skip to content

Commit

Permalink
Support indexing Recording IIIF 3 manifests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed Feb 10, 2020
1 parent 37b96e7 commit 451f1ff
Show file tree
Hide file tree
Showing 6 changed files with 1,020 additions and 5 deletions.
5 changes: 3 additions & 2 deletions app/services/iiif_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ def compound_id
end

def ark_url
return unless manifest["rendering"] && manifest["rendering"]["@id"]
manifest["rendering"]["@id"]
first_rendering = Array.wrap(manifest["rendering"]).first
return unless first_rendering && first_rendering["@id"]
first_rendering["@id"]
end

def noid
Expand Down
25 changes: 24 additions & 1 deletion app/services/iiif_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@ def self.iiif_response(url)
end

def create_iiif_manifest(manifest, collection = nil)
IiifManifest.new(url: manifest['@id'], manifest: manifest, collection: collection)
IiifManifest.new(url: manifest['@id'] || manifest['id'], manifest: manifest, collection: collection)
end

def object
@object ||= ManifestParser.parse(JSON.parse(response))
end

def manifest?
object.is_a?(IIIF::Presentation::Manifest) || object.is_a?(ManifestParser::IIIF3Manifest)
end

class ManifestParser
def self.parse(json)
return IIIF::Service.parse(json.to_json) unless json["@context"]&.include?("http://iiif.io/api/presentation/3/context.json")
IIIF3Manifest.new(json)
end

# IIIF::Presentation doesn't support IIIF 3. Fortunately we don't use much
# of it, so a simple wrapper with a label for a manifest gets us there.
class IIIF3Manifest < SimpleDelegator
def label
Array.wrap(__getobj__["label"]).first["@none"]
end
end
end
end
7 changes: 5 additions & 2 deletions app/values/manifest_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

class ManifestMetadata < Spotlight::Resources::IiifManifest::Metadata
def jsonld_url
return unless @manifest["see_also"]
json_ld_see_also = Array.wrap(@manifest["see_also"]).find { |v| v["format"] == "application/ld+json" }
# IIIF 3 manifests will have it in seeAlso, it's in see_also for
# IIIF::Presentation manifests.
see_also = @manifest["see_also"] || @manifest["seeAlso"]
return unless see_also
json_ld_see_also = Array.wrap(see_also).find { |v| v["format"] == "application/ld+json" }
return unless json_ld_see_also
json_ld_see_also["@id"]
end
Expand Down
Loading

0 comments on commit 451f1ff

Please sign in to comment.