Skip to content

Commit

Permalink
add support for multiple manifests + travis
Browse files Browse the repository at this point in the history
  • Loading branch information
Marii committed Jan 8, 2018
1 parent 94bfc17 commit 90aedfc
Show file tree
Hide file tree
Showing 40 changed files with 381 additions and 9,640 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -3,3 +3,4 @@ source 'https://rubygems.org'
gem 'jekyll', '3.7.0'
gem 'minima', '2.1.1'
gem 'rake'
gem 'html-proofer'
29 changes: 29 additions & 0 deletions Gemfile.lock
@@ -1,16 +1,33 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (5.1.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
colorator (1.1.0)
colorize (0.8.1)
concurrent-ruby (1.0.5)
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
ethon (0.11.0)
ffi (>= 1.3.0)
eventmachine (1.2.5)
ffi (1.9.18)
forwardable-extended (2.6.0)
html-proofer (3.8.0)
activesupport (>= 4.2, < 6.0)
addressable (~> 2.3)
colorize (~> 0.8)
mercenary (~> 0.3.2)
nokogiri (~> 1.8.1)
parallel (~> 1.3)
typhoeus (~> 1.3)
yell (~> 2.0)
http_parser.rb (0.6.0)
i18n (0.9.1)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -38,8 +55,13 @@ GEM
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
mercenary (0.3.6)
mini_portile2 (2.3.0)
minima (2.1.1)
jekyll (~> 3.3)
minitest (5.11.1)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
parallel (1.12.1)
pathutil (0.16.1)
forwardable-extended (~> 2.6)
public_suffix (3.0.1)
Expand All @@ -55,11 +77,18 @@ GEM
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
thread_safe (0.3.6)
typhoeus (1.3.0)
ethon (>= 0.9.0)
tzinfo (1.2.4)
thread_safe (~> 0.1)
yell (2.0.7)

PLATFORMS
ruby

DEPENDENCIES
html-proofer
jekyll (= 3.7.0)
minima (= 2.1.1)
rake
Expand Down
87 changes: 48 additions & 39 deletions Rakefile
@@ -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
9 changes: 9 additions & 0 deletions _includes/.travis.yml
@@ -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
11 changes: 7 additions & 4 deletions _includes/iiif_presentation.html
@@ -1,3 +1,9 @@
{% capture data %}
{% for m in page.manifests %}
{ manifestUri: '{{ site.url }}{{ site.baseurl }}/iiif/{{ m }}/manifest.json' }{% unless forloop.last %}, {% endunless %}
{% endfor %}
{% endcapture %}

<iframe title='Mirador' class="iiif_presentation" allowtransparency="true" src='iiif_mirador.html' allowfullscreen='true' webkitallowfullscreen='true' mozallowfullscreen='true' style='width: 100%; height: 600px;' srcdoc="<link rel='stylesheet' type='text/css' href='{{ site.baseurl }}/build/mirador/css/mirador-combined.css'>
<style>
#viewer {
Expand All @@ -12,10 +18,7 @@
$(function() {
myMiradorInstance = Mirador({
id: 'viewer',
data: [
{ manifestUri: '{{ site.url }}{{ site.baseurl }}/iiif/dublin/manifest.json', 'location': 'University of the City of Dublin'},
{ manifestUri: '{{ site.url }}{{ site.baseurl }}/iiif/bnf640/manifest.json', 'location': 'Gallica'}
],
data: [{{ data }}],
windowObjects: [{
loadedManifest: '{{ site.url }}{{ site.baseurl }}/iiif/bnf640/manifest.json',
canvasID: 'http://gallica.bnf.fr/iiif/ark:/12148/btv1b10500001g/canvas/f7',
Expand Down
5 changes: 5 additions & 0 deletions annotations/bnf640/f10/f10.json
@@ -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=\"{&quot;defaultStrokeValue&quot;:1,&quot;editStrokeValue&quot;:5,&quot;currentStrokeValue&quot;:5,&quot;annotation&quot;:null,&quot;editable&quot;: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"}]
@@ -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 }} }
2 changes: 1 addition & 1 deletion annotations/bnf640/f11/f11.json
Expand Up @@ -2,4 +2,4 @@
layout: null
label: f11-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>6</p>"}],"on":[{"@type":"oa:SpecificResource","full":"http://gallica.bnf.fr/iiif/ark:/12148/btv1b10500001g/canvas/f11","selector":{"@type":"oa:Choice","default":{"@type":"oa:FragmentSelector","value":"xywh=1331,537,50,75"},"item":{"@type":"oa:SvgSelector","value":"<svg xmlns='http://www.w3.org/2000/svg'><path xmlns=\"http://www.w3.org/2000/svg\" d=\"M1356.21336,611.96834c0,-16.71379 8.35689,-33.42757 25.07068,-50.14136c0,-13.84615 -11.22453,-25.07068 -25.07068,-25.07068c-13.84615,0 -25.07068,11.22453 -25.07068,25.07068c16.71379,16.71379 25.07068,33.42757 25.07068,50.14136z\" data-paper-data=\"{&quot;defaultStrokeValue&quot;:1,&quot;editStrokeValue&quot;:5,&quot;currentStrokeValue&quot;:1,&quot;fixedSize&quot;:true,&quot;editable&quot;:true,&quot;deleteIcon&quot;:null,&quot;annotation&quot;:null}\" id=\"pin_f06b387d-01ed-446f-8a5b-ae509faed686\" fill-opacity=\"0\" fill=\"#00bfff\" fill-rule=\"nonzero\" stroke=\"#00bfff\" stroke-width=\"5.01414\" 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":"6a988caa-d35d-4482-8cee-3c12454c4d32"},{"@context":"http://iiif.io/api/presentation/2/context.json","@type":"oa:Annotation","motivation":["oa:commenting"],"resource":[{"@type":"dctypes:Text","format":"text/html","chars":"<p>7</p>"}],"on":[{"@type":"oa:SpecificResource","full":"http://gallica.bnf.fr/iiif/ark:/12148/btv1b10500001g/canvas/f11","selector":{"@type":"oa:Choice","default":{"@type":"oa:FragmentSelector","value":"xywh=1440,1810,104,156"},"item":{"@type":"oa:SvgSelector","value":"<svg xmlns='http://www.w3.org/2000/svg'><path xmlns=\"http://www.w3.org/2000/svg\" d=\"M1492.43853,1965.59751c0,-34.65771 17.32885,-69.31542 51.98656,-103.97313c0,-28.71139 -23.27518,-51.98656 -51.98656,-51.98656c-28.71139,0 -51.98656,23.27518 -51.98656,51.98656c34.65771,34.65771 51.98656,69.31542 51.98656,103.97313z\" data-paper-data=\"{&quot;defaultStrokeValue&quot;:1,&quot;editStrokeValue&quot;:5,&quot;currentStrokeValue&quot;:1,&quot;fixedSize&quot;:true,&quot;editable&quot;:true,&quot;deleteIcon&quot;:null,&quot;annotation&quot;:null}\" id=\"pin_26e0e405-617b-4001-88c9-91ce1b725a3d\" fill-opacity=\"0\" fill=\"#00bfff\" fill-rule=\"nonzero\" stroke=\"#00bfff\" stroke-width=\"10.39731\" 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":"a0818a1e-ebed-4215-9438-f06e7d9173f4"},{"@context":"http://iiif.io/api/presentation/2/context.json","@type":"oa:Annotation","motivation":["oa:commenting"],"resource":[{"@type":"dctypes:Text","format":"text/html","chars":"<p>8</p>"}],"on":[{"@type":"oa:SpecificResource","full":"http://gallica.bnf.fr/iiif/ark:/12148/btv1b10500001g/canvas/f11","selector":{"@type":"oa:Choice","default":{"@type":"oa:FragmentSelector","value":"xywh=1451,3463,104,156"},"item":{"@type":"oa:SvgSelector","value":"<svg xmlns='http://www.w3.org/2000/svg'><path xmlns=\"http://www.w3.org/2000/svg\" d=\"M1502.83584,3618.77026c0,-34.65771 17.32885,-69.31542 51.98656,-103.97313c0,-28.71139 -23.27518,-51.98656 -51.98656,-51.98656c-28.71139,0 -51.98656,23.27518 -51.98656,51.98656c34.65771,34.65771 51.98656,69.31542 51.98656,103.97313z\" data-paper-data=\"{&quot;defaultStrokeValue&quot;:1,&quot;editStrokeValue&quot;:5,&quot;currentStrokeValue&quot;:1,&quot;fixedSize&quot;:true,&quot;editable&quot;:true,&quot;deleteIcon&quot;:null,&quot;annotation&quot;:null}\" id=\"pin_15c9cfff-d7d6-464a-b524-95b23949bcbe\" fill-opacity=\"0\" fill=\"#00bfff\" fill-rule=\"nonzero\" stroke=\"#00bfff\" stroke-width=\"10.39731\" 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":"7fba6a72-3520-43e1-a05a-f40f653c1246"}]

0 comments on commit 90aedfc

Please sign in to comment.