From dc5e46a7c651dcbcb11f50fc361aecc3a1cc302d Mon Sep 17 00:00:00 2001 From: Peter Binkley Date: Wed, 18 Sep 2019 21:10:49 -0600 Subject: [PATCH] Use manifest/name as canvas label, to ensure uniqueness --- Rakefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index 1b85138f2..886eac60b 100644 --- a/Rakefile +++ b/Rakefile @@ -17,7 +17,7 @@ task :store_annotations do FileUtils::mkdir_p dir # make dir for canvas annotations make_anno_list(dir,name,manifest) # write canvas annotation list to file - store_anno_array(dir,name,sum_annotations) # write array of canvas annotations to file + store_anno_array(dir,name,manifest,sum_annotations) # write array of canvas annotations to file File.delete(canvas) # remove unstored data file end @@ -35,12 +35,13 @@ def make_anno_list(dir,name,manifest) if !File.exist?(listpath) # make annotation list if necessary puts "creating " + listpath + ".\n" File.open(listpath, 'w') do |f| - f.write("---\nlayout: null\ncanvas: '" + name + "'\n---\n" + '{% assign anno_name = page.canvas | append: "-resources" %}{% assign annotations = site.pages | where: "label", anno_name | first %}{"@context": "http://iiif.io/api/presentation/2/context.json","@id": "{{ site.url }}{{ site.baseurl }}/annotations/' + manifest + '/' + name + '/list.json","@type": "sc:AnnotationList","resources": {{ annotations.content }} }') + # use manifest + '/' + name as canvas label, to ensure uniqueness across all manifests + f.write("---\nlayout: null\ncanvas: '" + manifest + '/' + name + "'\n---\n" + '{% assign anno_name = page.canvas | append: "-resources" %}{% assign annotations = site.pages | where: "label", anno_name | first %}{"@context": "http://iiif.io/api/presentation/2/context.json","@id": "{{ site.url }}{{ site.baseurl }}/annotations/' + manifest + '/' + name + '/list.json","@type": "sc:AnnotationList","resources": {{ annotations.content }} }') end end end -def store_anno_array(dir,name,sum_annotations) +def store_anno_array(dir,name,manifest,sum_annotations) annopath = dir + "/" + name + ".json" if !File.exist?(annopath) # if no preexisting annotation file puts "creating " + annopath + ".\n" @@ -49,14 +50,14 @@ def store_anno_array(dir,name,sum_annotations) old_annotations = JSON.parse(File.read(annopath).gsub(/\A---(.|\n)*?---/, "")) sum_annotations = sum_annotations.concat old_annotations # add annotation JSON to array end - File.open(annopath, 'w') { |f| f.write("---\nlayout: null\nlabel: " + name + "-resources\n---\n" + sum_annotations.to_json) } + File.open(annopath, 'w') { |f| f.write("---\nlayout: null\nlabel: " + manifest + '/' + name + "-resources\n---\n" + sum_annotations.to_json) } end def update_manifest_copy(manifest) stored_canvases = [] Dir['annotations/' + manifest + "/*/"].each { | c | stored_canvases << File.basename(c, ".*") } - puts "adding annotation references for canvases " + stored_canvases.to_s + " to manifest copy." + puts "adding annotation references for canvases " + manifest + '/' + stored_canvases.to_s + " to manifest copy." manifest_json = JSON.parse(File.read("iiif/" + manifest + "/clean-manifest.json").gsub(/\A---(.|\n)*?---/, "").to_s) canvases = manifest_json["sequences"][0]["canvases"].select {|c| stored_canvases.include? c["@id"].split('/')[-1] }