Add metadata to manifest - WIP
This commit is contained in:
parent
d707457cb8
commit
1d84db0d58
@ -14,12 +14,21 @@ export default async function generateManifest(manifestId) {
|
||||
let manifest = new Manifest(IIIF_API_VERSION, BASE_URL);
|
||||
manifest.generateID(manifestId);
|
||||
manifest.generateLabel();
|
||||
|
||||
const images = await Common.getImageList(manifestId);
|
||||
|
||||
manifest = await Common.populateCanvases(
|
||||
manifest,
|
||||
await Common.getImageList(manifestId),
|
||||
images,
|
||||
manifestId
|
||||
);
|
||||
|
||||
manifest.setMetadata(
|
||||
Common.createMetadata(
|
||||
manifest,
|
||||
images[0],
|
||||
)
|
||||
);
|
||||
|
||||
return manifest.toObject();
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
import IIIFResource from './IIIFResource.js';
|
||||
|
||||
/**
|
||||
* @todo Move to common.js?!
|
||||
*/
|
||||
const splitter = {
|
||||
NIR: splitNIR,
|
||||
DN: splitDNO,
|
||||
@ -60,7 +63,6 @@ class Image {
|
||||
/**
|
||||
* Generate IIIF id pointing to image
|
||||
* server endpoint for this image
|
||||
* @todo Warning! Only works for NIR filenames...
|
||||
* @param {string} serviceURL The image server base URL
|
||||
* @param {string} filename The image's complete filename
|
||||
*/
|
||||
|
@ -1,9 +1,7 @@
|
||||
import IIIFResource from './IIIFResource.js';
|
||||
import Sequence from "./Sequence.js";
|
||||
import ManifestMetadata from './Metadata.js';
|
||||
|
||||
const TECH = {
|
||||
nir: "Technical Photography, Near Infrared Imaging 1000nm",
|
||||
}
|
||||
/**
|
||||
* @implements IIIFResource
|
||||
*/
|
||||
@ -12,6 +10,7 @@ class Manifest {
|
||||
#type = 'sc:Manifest';
|
||||
#label = '';
|
||||
resourceId = '';
|
||||
#metadata = {};
|
||||
#technique = '';
|
||||
/**
|
||||
* @var {Sequence[]}
|
||||
@ -46,6 +45,13 @@ class Manifest {
|
||||
generateLabel() {
|
||||
this.#label = `P.Herc. ${this.resourceId.split('-')[1]}`;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {ManifestMetadata} metadata
|
||||
*/
|
||||
setMetadata(metadata) {
|
||||
this.#metadata = metadata.toObject();
|
||||
}
|
||||
/**
|
||||
* Object representation of this
|
||||
* manifest
|
||||
@ -57,6 +63,7 @@ class Manifest {
|
||||
"@id" : this.id,
|
||||
"@type" : this.#type,
|
||||
label : this.#label,
|
||||
metadata: this.#metadata,
|
||||
sequences: this.sequences,
|
||||
}
|
||||
}
|
||||
|
61
src/Metadata.js
Normal file
61
src/Metadata.js
Normal file
@ -0,0 +1,61 @@
|
||||
|
||||
class ManifestMetadata {
|
||||
papyrus = '';
|
||||
author = '';
|
||||
title = '';
|
||||
edition = '';
|
||||
technique = '';
|
||||
date = '';
|
||||
imageAuthor = '';
|
||||
license = 'CC BY-NC-ND 4.0';
|
||||
copyright = 'BNN/CNR-ISPC';
|
||||
|
||||
/**
|
||||
* @todo Maybe this doesn't make any sense??
|
||||
* @param {
|
||||
* {papyrus,
|
||||
* author,
|
||||
* title,
|
||||
* edition,
|
||||
* technique,
|
||||
* date,
|
||||
* imageAuthor,
|
||||
* license,
|
||||
* copyright}
|
||||
* } metadata
|
||||
*/
|
||||
constructor(metadata) {
|
||||
this.papyrus = metadata.papyrus ?? this.papyrus;
|
||||
this.author = metadata.author ?? this.author;
|
||||
this.title = metadata.title ?? this.title;
|
||||
this.edition = metadata.edition ?? this.edition;
|
||||
// There should always be a technique value
|
||||
// in the metadata param
|
||||
this.technique = metadata.technique;
|
||||
this.date = metadata.date ?? this.date;
|
||||
this.imageAuthor = metadata.imageAuthor ?? this.imageAuthor
|
||||
this.license = metadata.license ?? this.license;
|
||||
this.copyright = metadata.copyright ?? this.copyright;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of `label, value`
|
||||
* pairs for all metadata
|
||||
* @returns {Array<{label, value}>}
|
||||
*/
|
||||
toObject() {
|
||||
return [
|
||||
{label: "Papyrus", value: this.papyrus},
|
||||
{label:"Author", value: this.author},
|
||||
{label:"Title", value: this.title},
|
||||
{label:"Reference edition", value: this.edition},
|
||||
{label:"Technique", value: this.technique},
|
||||
{label:"Date (Year)", value: this.date},
|
||||
{label:"Image Author", value: this.imageAuthor},
|
||||
{label:"License", value: this.license},
|
||||
{label:"Copyright", value: this.copyright},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
export default ManifestMetadata;
|
@ -6,7 +6,7 @@ import Manifest from './Manifest.js';
|
||||
import Sequence from './Sequence.js';
|
||||
import Canvas from './Canvas.js';
|
||||
import Image from './Image.js';
|
||||
//import ManifestMetadata from './Metadata.js';
|
||||
import ManifestMetadata from './Metadata.js';
|
||||
const Common = {};
|
||||
|
||||
const TECH_NAMES = {
|
||||
@ -80,11 +80,13 @@ Common.createCanvas = async function (manifest, filename) {
|
||||
process.env.IIIF_API_VERSION,
|
||||
process.env.BASE_URL
|
||||
);
|
||||
|
||||
const namePos = {
|
||||
nir: 1,
|
||||
do: 3,
|
||||
dn: 3
|
||||
};
|
||||
|
||||
const canvasName = filename.split('_')[namePos[manifest.technique]]
|
||||
.replace(/\.\w{1,3}$/, '');
|
||||
canvas.generateID(manifest.resourceId, canvasName);
|
||||
@ -140,13 +142,30 @@ Common.populateCanvases = async function (manifest, images) {
|
||||
}
|
||||
/**
|
||||
* @todo Implement...
|
||||
* @param {string} imageName The image filename
|
||||
* @param {Manifest} manifest The Manifest object
|
||||
* @param {string} imgFilename
|
||||
* @returns {ManifestMetadata}
|
||||
*/
|
||||
Common.createMetadata = function (imageName) {
|
||||
let metadata = {};
|
||||
Common.createMetadata = function (manifest, imgFilename) {
|
||||
let metadata = this.getMetadataFromImgName(imgFilename);
|
||||
metadata.technique = TECH_NAMES[manifest.technique];
|
||||
|
||||
return new ManifestMetadata(metadata);
|
||||
}
|
||||
/**
|
||||
* @todo Only works with NIR!!
|
||||
* @param {string} imgFilename
|
||||
*/
|
||||
Common.getMetadataFromImgName = function (imgFilename) {
|
||||
const authors = {
|
||||
DAN: 'Danilo P. Pavone'
|
||||
};
|
||||
|
||||
return {
|
||||
papyrus: imgFilename.split('_')[0].split('-')[2],
|
||||
imageAuthor: authors[imgFilename.split('-')[0].replace(/\d{4}/,'')],
|
||||
date: imgFilename.split('-')[0].match(/\d{4}/)[0],
|
||||
}
|
||||
}
|
||||
|
||||
export default Common;
|
Loading…
Reference in New Issue
Block a user