Skip to content

Commit 94bfc17

Browse files
author
Marii
committed
add second manifest
1 parent eadf600 commit 94bfc17

25 files changed

+9683
-140
lines changed

β€ŽRakefile

+45-48
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,63 @@ require 'fileutils'
22
require 'json'
33

44
task :store_annotations do
5-
data = Dir["annotations/*.json"].sort!
6-
data.each do |new_data|
5+
manifests = []
6+
Dir['annotations/*/'].each { | m | manifests << File.basename(m, ".*") }
77

8-
@name = File.basename(new_data, ".*")
9-
@dir = "annotations/" + @name
8+
manifests.each do | manifest |
9+
unstored_canvases = Dir["annotations/" + manifest + "/*.json"].sort!
10+
unstored_canvases.each do |canvas|
1011

11-
FileUtils::mkdir_p @dir # make dir named after d
12+
@name = File.basename(canvas, ".*")
13+
@dir = "annotations/" + manifest + "/" + @name
14+
@sum_annotations = []
1215

13-
listpath = @dir + "/" + "list.json" # make annotation list if necessary
14-
if !File.exist?(listpath)
15-
puts "creating " + listpath + ".\n"
16-
File.open(listpath, 'w') do |f|
17-
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/' + @name + '/list.json","@type": "sc:AnnotationList","resources": {{ annotations.content }} }')
18-
end
19-
end
16+
listpath = @dir + "/" + "list.json"
17+
annopath = @dir + "/" + @name + ".json"
2018

21-
annopath = @dir + "/" + @name + ".json"
22-
anno_file = File.read(new_data)
23-
annos = JSON.parse(anno_file)
19+
new_annotations = JSON.parse(File.read(canvas))
2420

25-
if !File.exist?(annopath) # if no preexisting annotation file
26-
puts "creating " + annopath + ".\n"
27-
else # if preexisting annotation file
28-
puts "appending new annotations to " + annopath + ".\n"
29-
old_file = File.read(annopath).gsub(/\A---(.|\n)*?---/, "").to_s
30-
annos = annos.concat JSON.parse(old_file)
31-
end
21+
FileUtils::mkdir_p @dir # make dir for canvas annotations
3222

33-
File.open(annopath, 'w') do |f|
34-
f.write("---\nlayout: null\nlabel: " + @name + "-resources\n---\n" + annos.to_json)
35-
end
23+
if !File.exist?(listpath) # make annotation list if necessary
24+
puts "creating " + listpath + ".\n"
25+
File.open(listpath, 'w') do |f|
26+
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 }} }')
27+
end
28+
end
3629

37-
File.delete(new_data) # remove data file
38-
end
39-
end
30+
if !File.exist?(annopath) # if no preexisting annotation file
31+
puts "creating " + annopath + ".\n"
32+
else # if preexisting annotation file
33+
puts "appending new annotations to " + annopath + ".\n"
34+
old_annotations = JSON.parse(File.read(annopath).gsub(/\A---(.|\n)*?---/, ""))
35+
@sum_annotations = new_annotations.concat old_annotations # add annotation JSON to array
36+
puts @sum_annotations
37+
end
4038

41-
task :write_manifest do
42-
canvas_ids = []
43-
Dir['annotations/*/'].each { | c_dir | canvas_ids << File.basename(c_dir, ".*") }
44-
puts "adding annotation references for canvases " + canvas_ids.to_s + " to manifest copy."
39+
File.open(annopath, 'w') { |f| f.write("---\nlayout: null\nlabel: " + @name + "-resources\n---\n" + @sum_annotations.to_json) }
40+
# File.delete(canvas) # remove unstored data file
41+
end
4542

46-
m = File.read('build/clean-manifest.json').gsub(/\A---(.|\n)*?---/, "").to_s
47-
manifest = JSON.parse(m)
43+
stored_canvases = []
44+
Dir['annotations/' + manifest + "/*/"].each { | c | stored_canvases << File.basename(c, ".*") }
45+
puts "adding annotation references for canvases " + stored_canvases.to_s + " to manifest copy."
4846

49-
manifest["sequences"][0]["canvases"].select {|c| canvas_ids.include? c["@id"].split('/')[-1] }.each do | canvas |
50-
this_id = canvas["@id"].split('/')[-1]
51-
anno_hash = Hash.new { |hash, key| hash[key] = {} }
52-
empty_array = Array.new
53-
anno_hash["@id"] = "{{ site.url }}{{ site.baseurl }}/annotations/" + this_id + "/list.json"
54-
anno_hash["@type"] = "sc:AnnotationList"
55-
canvas["otherContent"] = empty_array << anno_hash
56-
end
47+
manifest_json = JSON.parse(File.read("iiif/" + manifest + "/clean-manifest.json").gsub(/\A---(.|\n)*?---/, "").to_s)
5748

58-
# write new manifest to file
59-
File.open("manifest.json", 'w+') { |f| f.write("---\nlayout: null\n---\n"+manifest.to_json) }
49+
manifest_json["sequences"][0]["canvases"].select {|c| stored_canvases.include? c["@id"].split('/')[-1] }.each do | canvas |
50+
empty_array = Array.new
51+
annotation_hash = Hash.new { |hash, key| hash[key] = {} }
52+
this_id = canvas["@id"].split('/')[-1]
53+
annotation_hash["@id"] = "{{ site.url }}{{ site.baseurl }}/annotations/" + manifest + "/" + this_id + "/list.json"
54+
annotation_hash["@type"] = "sc:AnnotationList"
55+
canvas["otherContent"] = empty_array << annotation_hash
56+
end
6057

61-
end
58+
# write new manifest to file
59+
File.open("iiif/" + manifest + "/manifest.json", 'w+') { |f| f.write("---\nlayout: null\n---\n"+manifest_json.to_json) }
6260

63-
task :store_and_reference => :store_annotations do
64-
Rake::Task["write_manifest"].invoke
61+
end
6562
end
6663

67-
task :default => [:store_and_reference]
64+
task :default => [:store_annotations]

β€Ž_config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
title: BnF640
22
description: ""
33
baseurl: "/bnf640" # the subpath of your site, e.g. /blog
4-
url: "" # the base hostname & protocol for your site, e.g. http://example.com
4+
url: "http://marii.info" # the base hostname & protocol for your site, e.g. http://example.com
55

66
# Build settings
77
markdown: kramdown

β€Ž_includes/annotation_to_json.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
99
crossorigin="anonymous"></script>
1010
<script type="text/jscript">
11-
var gallicaUrlRegex = /.+gallica\.bnf\.fr.+canvas\/(.+)/;
11+
var canvas_regex = /.+canvas\/([^.]+)/;
1212

1313
function download(filename, text) {
1414
var element = document.createElement('a');
@@ -40,7 +40,7 @@
4040
$( "#anno_results" ).empty()
4141
for(var i =0; i < localStorage.length; i++){
4242
var key = localStorage.key(i);
43-
var matches = gallicaUrlRegex.exec(key);
43+
var matches = canvas_regex.exec(key);
4444
if(matches != null) {
4545
var canvas = matches[1];
4646
var fileName = canvas + '.json';

β€Ž_includes/iiif_presentation.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
myMiradorInstance = Mirador({
1414
id: 'viewer',
1515
data: [
16-
{ manifestUri: '{{ site.baseurl }}/manifest.json', 'location': 'Gallica'}
16+
{ manifestUri: '{{ site.url }}{{ site.baseurl }}/iiif/dublin/manifest.json', 'location': 'University of the City of Dublin'},
17+
{ manifestUri: '{{ site.url }}{{ site.baseurl }}/iiif/bnf640/manifest.json', 'location': 'Gallica'}
1718
],
1819
windowObjects: [{
19-
loadedManifest: '{{ site.baseurl }}/manifest.json',
20+
loadedManifest: '{{ site.url }}{{ site.baseurl }}/iiif/bnf640/manifest.json',
2021
canvasID: 'http://gallica.bnf.fr/iiif/ark:/12148/btv1b10500001g/canvas/f7',
2122
bottomPanelVisible: true
2223
}],

β€Žannotations/bnf640/f11/f11.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
layout: null
3+
label: f11-resources
4+
---
5+
[]

β€Žannotations/f11/list.json β€Žannotations/bnf640/f11/list.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
layout: null
33
canvas: f11
44
---
5-
{% 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/f11/list.json","@type": "sc:AnnotationList","resources": {{ annotations.content }} }
5+
{% 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/f11/list.json","@type": "sc:AnnotationList","resources": {{ annotations.content }} }

β€Žannotations/bnf640/f12/f12.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
layout: null
3+
label: f12-resources
4+
---
5+
[]

β€Žannotations/f12/list.json β€Žannotations/bnf640/f12/list.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
layout: null
33
canvas: f12
44
---
5-
{% 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/f12/list.json","@type": "sc:AnnotationList","resources": {{ annotations.content }} }
5+
{% 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/f12/list.json","@type": "sc:AnnotationList","resources": {{ annotations.content }} }

β€Žannotations/bnf640/f13/f13.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
layout: null
3+
label: f13-resources
4+
---
5+
[]

β€Žannotations/bnf640/f13/list.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
layout: null
3+
canvas: f13
4+
---
5+
{% 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/f13/list.json","@type": "sc:AnnotationList","resources": {{ annotations.content }} }

β€Žannotations/bnf640/f7/f7.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
layout: null
3+
label: f7-resources
4+
---
5+
[{"@context":"http://iiif.io/api/presentation/2/context.json","@type":"oa:Annotation","motivation":["oa:commenting"],"resource":[{"@type":"dctypes:Text","format":"text/html","chars":"<p>testing</p>"}],"on":[{"@type":"oa:SpecificResource","full":"http://gallica.bnf.fr/iiif/ark:/12148/btv1b10500001g/canvas/f7","selector":{"@type":"oa:Choice","default":{"@type":"oa:FragmentSelector","value":"xywh=1641,2695,857,917"},"item":{"@type":"oa:SvgSelector","value":"<svg xmlns='http://www.w3.org/2000/svg'><path xmlns=\"http://www.w3.org/2000/svg\" d=\"M1766.68161,2829.32263c79.08489,-77.02115 190.64694,-134.37619 302.74962,-134.30766l0,0l0,0c112.10268,0.06852 209.76292,53.72324 302.74962,134.30766c92.9867,80.58442 129.12946,203.37953 125.403,324.24738c-3.72646,120.86785 -47.32213,239.80845 -125.403,324.24738c-78.08087,84.43893 -190.64694,134.37619 -302.74962,134.30766c-112.10268,-0.06852 -223.74196,-50.14283 -302.74962,-134.30766c-79.00766,-84.16483 -125.38369,-202.42019 -125.403,-324.24738c-0.01931,-121.8272 46.31811,-247.22624 125.403,-324.24738z\" data-paper-data=\"{&quot;defaultStrokeValue&quot;:1,&quot;editStrokeValue&quot;:5,&quot;currentStrokeValue&quot;:1,&quot;rotation&quot;:0,&quot;deleteIcon&quot;:null,&quot;rotationIcon&quot;:null,&quot;group&quot;:null,&quot;editable&quot;:true,&quot;annotation&quot;:null}\" id=\"ellipse_2a79b0e4-dcc4-4710-b734-41147ca65472\" fill-opacity=\"0\" fill=\"#00bfff\" fill-rule=\"nonzero\" stroke=\"#00bfff\" stroke-width=\"10.38004\" 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":"f031df2d-6d5e-47a1-bb42-943835839d21"},{"@context":"http://iiif.io/api/presentation/2/context.json","@type":"oa:Annotation","motivation":["oa:commenting"],"resource":[{"@type":"dctypes:Text","format":"text/html","chars":"<p>testing</p>"}],"on":[{"@type":"oa:SpecificResource","full":"http://gallica.bnf.fr/iiif/ark:/12148/btv1b10500001g/canvas/f7","selector":{"@type":"oa:Choice","default":{"@type":"oa:FragmentSelector","value":"xywh=1641,2695,857,917"},"item":{"@type":"oa:SvgSelector","value":"<svg xmlns='http://www.w3.org/2000/svg'><path xmlns=\"http://www.w3.org/2000/svg\" d=\"M1766.68161,2829.32263c79.08489,-77.02115 190.64694,-134.37619 302.74962,-134.30766l0,0l0,0c112.10268,0.06852 209.76292,53.72324 302.74962,134.30766c92.9867,80.58442 129.12946,203.37953 125.403,324.24738c-3.72646,120.86785 -47.32213,239.80845 -125.403,324.24738c-78.08087,84.43893 -190.64694,134.37619 -302.74962,134.30766c-112.10268,-0.06852 -223.74196,-50.14283 -302.74962,-134.30766c-79.00766,-84.16483 -125.38369,-202.42019 -125.403,-324.24738c-0.01931,-121.8272 46.31811,-247.22624 125.403,-324.24738z\" data-paper-data=\"{&quot;defaultStrokeValue&quot;:1,&quot;editStrokeValue&quot;:5,&quot;currentStrokeValue&quot;:1,&quot;rotation&quot;:0,&quot;deleteIcon&quot;:null,&quot;rotationIcon&quot;:null,&quot;group&quot;:null,&quot;editable&quot;:true,&quot;annotation&quot;:null}\" id=\"ellipse_2a79b0e4-dcc4-4710-b734-41147ca65472\" fill-opacity=\"0\" fill=\"#00bfff\" fill-rule=\"nonzero\" stroke=\"#00bfff\" stroke-width=\"10.38004\" 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":"f031df2d-6d5e-47a1-bb42-943835839d21"}]

β€Žannotations/f7/list.json β€Žannotations/bnf640/f7/list.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
layout: null
33
canvas: f7
44
---
5-
{% 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/f7/list.json","@type": "sc:AnnotationList","resources": {{ annotations.content }} }
5+
{% 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/f7/list.json","@type": "sc:AnnotationList","resources": {{ annotations.content }} }

β€Žannotations/bnf640/f9/f9.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
layout: null
3+
label: f9-resources
4+
---
5+
[]
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
layout: null
3-
canvas: f14
3+
canvas: f9
44
---
5-
{% 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/f14/list.json","@type": "sc:AnnotationList","resources": {{ annotations.content }} }
5+
{% 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/f9/list.json","@type": "sc:AnnotationList","resources": {{ annotations.content }} }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
layout: null
3+
canvas: ucdlib_42220
4+
---
5+
{% 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 }} }

β€Žannotations/dublin/ucdlib_42220/ucdlib_42220.json

+5
Large diffs are not rendered by default.

β€Žannotations/f11/f11.json

-5
This file was deleted.

0 commit comments

Comments
Β (0)