Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for multiple manifests + travis
- Loading branch information
Marii
committed
Jan 8, 2018
1 parent
94bfc17
commit 90aedfc
Showing
40 changed files
with
381 additions
and
9,640 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ source 'https://rubygems.org' | |
gem 'jekyll', '3.7.0' | ||
gem 'minima', '2.1.1' | ||
gem 'rake' | ||
gem 'html-proofer' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,73 @@ | ||
require 'fileutils' | ||
require 'json' | ||
|
||
task :default => [:store_annotations] | ||
|
||
task :store_annotations do | ||
manifests = [] | ||
Dir['annotations/*/'].each { | m | manifests << File.basename(m, ".*") } | ||
|
||
manifests.each do | manifest | | ||
unstored_canvases = Dir["annotations/" + manifest + "/*.json"].sort! | ||
unstored_canvases.each do |canvas| | ||
name = File.basename(canvas, ".*") | ||
dir = "annotations/" + manifest + "/" + name | ||
sum_annotations = JSON.parse(File.read(canvas)) | ||
|
||
@name = File.basename(canvas, ".*") | ||
@dir = "annotations/" + manifest + "/" + @name | ||
@sum_annotations = [] | ||
FileUtils::mkdir_p dir # make dir for canvas annotations | ||
|
||
listpath = @dir + "/" + "list.json" | ||
annopath = @dir + "/" + @name + ".json" | ||
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 | ||
|
||
new_annotations = JSON.parse(File.read(canvas)) | ||
File.delete(canvas) # remove unstored data file | ||
end | ||
|
||
FileUtils::mkdir_p @dir # make dir for canvas annotations | ||
unless unstored_canvases.empty? | ||
update_manifest_copy(manifest) | ||
end | ||
end | ||
end | ||
|
||
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 }} }') | ||
end | ||
end | ||
|
||
if !File.exist?(annopath) # if no preexisting annotation file | ||
puts "creating " + annopath + ".\n" | ||
else # if preexisting annotation file | ||
puts "appending new annotations to " + annopath + ".\n" | ||
old_annotations = JSON.parse(File.read(annopath).gsub(/\A---(.|\n)*?---/, "")) | ||
@sum_annotations = new_annotations.concat old_annotations # add annotation JSON to array | ||
puts @sum_annotations | ||
end | ||
|
||
File.open(annopath, 'w') { |f| f.write("---\nlayout: null\nlabel: " + @name + "-resources\n---\n" + @sum_annotations.to_json) } | ||
# File.delete(canvas) # remove unstored data file | ||
def make_anno_list(dir,name,manifest) | ||
listpath = dir + "/" + "list.json" | ||
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 }} }') | ||
end | ||
end | ||
end | ||
|
||
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." | ||
def store_anno_array(dir,name,sum_annotations) | ||
annopath = dir + "/" + name + ".json" | ||
if !File.exist?(annopath) # if no preexisting annotation file | ||
puts "creating " + annopath + ".\n" | ||
else # if preexisting annotation file | ||
puts "appending new annotations to " + annopath + ".\n" | ||
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) } | ||
end | ||
|
||
manifest_json = JSON.parse(File.read("iiif/" + manifest + "/clean-manifest.json").gsub(/\A---(.|\n)*?---/, "").to_s) | ||
def update_manifest_copy(manifest) | ||
stored_canvases = [] | ||
Dir['annotations/' + manifest + "/*/"].each { | c | stored_canvases << File.basename(c, ".*") } | ||
|
||
manifest_json["sequences"][0]["canvases"].select {|c| stored_canvases.include? c["@id"].split('/')[-1] }.each do | canvas | | ||
empty_array = Array.new | ||
annotation_hash = Hash.new { |hash, key| hash[key] = {} } | ||
this_id = canvas["@id"].split('/')[-1] | ||
annotation_hash["@id"] = "{{ site.url }}{{ site.baseurl }}/annotations/" + manifest + "/" + this_id + "/list.json" | ||
annotation_hash["@type"] = "sc:AnnotationList" | ||
canvas["otherContent"] = empty_array << annotation_hash | ||
end | ||
puts "adding annotation references for canvases " + stored_canvases.to_s + " to manifest copy." | ||
|
||
# write new manifest to file | ||
File.open("iiif/" + manifest + "/manifest.json", 'w+') { |f| f.write("---\nlayout: null\n---\n"+manifest_json.to_json) } | ||
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] } | ||
|
||
canvases.each do | canvas | | ||
annotation_hash = Hash.new { |hash, key| hash[key] = {} } | ||
this_id = canvas["@id"].split('/')[-1] | ||
annotation_hash["@id"] = "{{ site.url }}{{ site.baseurl }}/annotations/" + manifest + "/" + this_id + "/list.json" | ||
annotation_hash["@type"] = "sc:AnnotationList" | ||
canvas["otherContent"] = Array.new << annotation_hash | ||
end | ||
end | ||
|
||
task :default => [:store_annotations] | ||
File.open("iiif/" + manifest + "/manifest.json", 'w+') { |f| f.write("---\nlayout: null\n---\n"+manifest_json.to_json) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: ruby | ||
rvm: | ||
- 2.4 | ||
script: | ||
- bundle exec jekyll build -d _site/bnf640 | ||
- bundle exec htmlproofer ./_site --only-4xx --check-html --assume-extension --disable-external '/.*/' | ||
env: | ||
global: | ||
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true # speeds up installation of html-proofer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
layout: null | ||
label: f10-resources | ||
--- | ||
[{"@context":"http://iiif.io/api/presentation/2/context.json","@type":"oa:Annotation","motivation":["oa:commenting"],"resource":[{"@type":"dctypes:Text","format":"text/html","chars":"<p>5</p>"}],"on":[{"@type":"oa:SpecificResource","full":"http://gallica.bnf.fr/iiif/ark:/12148/btv1b10500001g/canvas/f10","selector":{"@type":"oa:Choice","default":{"@type":"oa:FragmentSelector","value":"xywh=1220,698,1243,17"},"item":{"@type":"oa:SvgSelector","value":"<svg xmlns='http://www.w3.org/2000/svg'><path xmlns=\"http://www.w3.org/2000/svg\" d=\"M1219.72996,697.54631l1242.61505,17.41984l0,0\" data-paper-data=\"{"defaultStrokeValue":1,"editStrokeValue":5,"currentStrokeValue":5,"annotation":null,"editable":true}\" id=\"rough_path_6b925223-487d-492a-864d-1c26c345856f\" fill=\"none\" fill-rule=\"nonzero\" stroke=\"#00bfff\" stroke-width=\"19.35537\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-miterlimit=\"10\" stroke-dasharray=\"\" stroke-dashoffset=\"0\" font-family=\"none\" font-weight=\"none\" font-size=\"none\" text-anchor=\"none\" style=\"mix-blend-mode: normal\"/></svg>"}},"within":{"@id":"http://gallica.bnf.fr/iiif/ark:/12148/btv1b10500001g/manifest.json","@type":"sc:Manifest"}}],"@id":"0028ebc0-9097-449e-9daa-50ae7c6e95c9"}] |
4 changes: 2 additions & 2 deletions
4
annotations/dublin/ucdlib_42220/list.json → annotations/bnf640/f10/list.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
layout: null | ||
canvas: ucdlib_42220 | ||
canvas: f10 | ||
--- | ||
{% 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/dublin/ucdlib_42220/list.json","@type": "sc:AnnotationList","resources": {{ annotations.content }} } | ||
{% 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/bnf640/f10/list.json","@type": "sc:AnnotationList","resources": {{ annotations.content }} } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.