Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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] }
Expand Down