diff --git a/app/models/concerns/blacklight_iiif_search/iiif_search_annotation_behavior.rb b/app/models/concerns/blacklight_iiif_search/iiif_search_annotation_behavior.rb index e1170cf4..56863980 100644 --- a/app/models/concerns/blacklight_iiif_search/iiif_search_annotation_behavior.rb +++ b/app/models/concerns/blacklight_iiif_search/iiif_search_annotation_behavior.rb @@ -71,7 +71,28 @@ def fetch_and_parse_coords end def emory_iiif_id_url - "http://#{ENV['HOSTNAME'] || 'localhost:3000'}/iiif/#{parent_document[:id]}/manifest" + "#{manifest_base_uri}/iiif/#{parent_document[:id]}/manifest" + end + + def manifest_base_uri + pulled_uri = parsed_uri + pulled_uri.to_s[/\A.*(?=#{pulled_uri.path}\z)/] + end + + def presenter + Hyrax::CurateGenericWorkPresenter.new(parent_document, ManifestAbility.new) + end + + def manifest + @manifest ||= ManifestBuilderService.build_manifest(presenter: presenter, curation_concern: CurateGenericWork.find(parent_document[:id])) + end + + def parsed_manifest + JSON.parse(manifest) + end + + def parsed_uri + URI.parse(parsed_manifest['sequences'][0]['canvases'][0]['@id']) end end end