diff --git a/package-lock.json b/package-lock.json index 8a6941b..80778b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,11 +9,11 @@ "version": "0.1.0", "license": "AGPL-3.0", "dependencies": { - "@rollup/plugin-json": "^6.0.0", "iiif-builder": "^1.0.6" }, "devDependencies": { "@rollup/plugin-commonjs": "^22.0.2", + "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^13.3.0", "electron": "^18.2.2", "electron-mocha": "^11.0.2", @@ -161,6 +161,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-6.0.0.tgz", "integrity": "sha512-i/4C5Jrdr1XUarRhVu27EEwjt4GObltD7c+MkCIpO2QIbojw8MUs+CCTqOphQi3Qtg1FLmYt+l+6YeoIf51J7w==", + "dev": true, "dependencies": { "@rollup/pluginutils": "^5.0.1" }, @@ -180,6 +181,7 @@ "version": "5.0.4", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.4.tgz", "integrity": "sha512-0KJnIoRI8A+a1dqOYLxH8vBf8bphDmty5QvIm2hqm7oFCFYKCAZWWd2hXgMibaPsNDhI0AtpYfQZJG47pt/k4g==", + "dev": true, "dependencies": { "@types/estree": "^1.0.0", "estree-walker": "^2.0.2", @@ -200,7 +202,8 @@ "node_modules/@rollup/plugin-json/node_modules/@types/estree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.1.tgz", - "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==" + "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==", + "dev": true }, "node_modules/@rollup/plugin-node-resolve": { "version": "13.3.0", @@ -1115,7 +1118,8 @@ "node_modules/estree-walker": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", - "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==" + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true }, "node_modules/esutils": { "version": "2.0.3", @@ -2355,6 +2359,7 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, "engines": { "node": ">=8.6" }, @@ -2573,7 +2578,7 @@ "version": "2.74.1", "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.74.1.tgz", "integrity": "sha512-K2zW7kV8Voua5eGkbnBtWYfMIhYhT9Pel2uhBk2WO5eMee161nPze/XRfvEQPFYz7KgrCCnmh2Wy0AMFLGGmMA==", - "devOptional": true, + "dev": true, "bin": { "rollup": "dist/bin/rollup" }, @@ -3269,6 +3274,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-6.0.0.tgz", "integrity": "sha512-i/4C5Jrdr1XUarRhVu27EEwjt4GObltD7c+MkCIpO2QIbojw8MUs+CCTqOphQi3Qtg1FLmYt+l+6YeoIf51J7w==", + "dev": true, "requires": { "@rollup/pluginutils": "^5.0.1" }, @@ -3277,6 +3283,7 @@ "version": "5.0.4", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.4.tgz", "integrity": "sha512-0KJnIoRI8A+a1dqOYLxH8vBf8bphDmty5QvIm2hqm7oFCFYKCAZWWd2hXgMibaPsNDhI0AtpYfQZJG47pt/k4g==", + "dev": true, "requires": { "@types/estree": "^1.0.0", "estree-walker": "^2.0.2", @@ -3286,7 +3293,8 @@ "@types/estree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.1.tgz", - "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==" + "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==", + "dev": true } } }, @@ -3992,7 +4000,8 @@ "estree-walker": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", - "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==" + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true }, "esutils": { "version": "2.0.3", @@ -4930,7 +4939,8 @@ "picomatch": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", - "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==" + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true }, "pify": { "version": "3.0.0", @@ -5098,7 +5108,7 @@ "version": "2.74.1", "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.74.1.tgz", "integrity": "sha512-K2zW7kV8Voua5eGkbnBtWYfMIhYhT9Pel2uhBk2WO5eMee161nPze/XRfvEQPFYz7KgrCCnmh2Wy0AMFLGGmMA==", - "devOptional": true, + "dev": true, "requires": { "fsevents": "~2.3.2" } diff --git a/package.json b/package.json index 1f9dc33..dc0396d 100644 --- a/package.json +++ b/package.json @@ -45,24 +45,31 @@ "hint": "The URL prefix to use in the exported manifests and collections. This should be a publicly accessible web location" }, { - "field": "requiredStatement", - "label": "Required Statement", + "field": "requiredStatementLabel", + "label": "Required Statement Label", "default": "Attribution", "hint": "The label to use for the manifests Required Statement section" }, + { + "field": "requiredStatementText", + "label": "Required Statement Text", + "default": "Provided by", + "placeholder": "Provided by", + "hint": "Text to prepend to the 'source' property value" + }, { "field": "itemTemplate", "label": "Item template", - "placeholder": "Select Template (Optional)", + "placeholder": "Select Template", "type": "template", - "hint": "The template determines how to export the IIIF manifest metadata section" + "hint": "The template determines how to export the IIIF manifest" }, { "field": "photoTemplate", "label": "Photo template", - "placeholder": "Select Template (Optional)", + "placeholder": "Select Template", "type": "template", - "hint": "The template determines how to export the IIIF manifest metadata section" + "hint": "The template determines how to export the IIIF manifest" } ], "devDependencies": { diff --git a/src/plugin.js b/src/plugin.js index 8e2b019..ef1a7f0 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -40,7 +40,7 @@ class ExamplePlugin { // Here we write directly to Tropy's log file (via the context object) this.context.logger.trace('Called export hook from example plugin') - //const destination = await this.prompt() + const destination = await this.prompt() // This logs the data supplied to the export hook. The data includes // the currently selected Tropy items (or all items, if none are currently @@ -50,26 +50,28 @@ class ExamplePlugin { let manifests = [] //const zip = new JSZip(); - // for (let item of expanded[0]['@graph']) { - // try { - // const manifest = this.createManifest(item) - // //console.log('Manifest:', await manifest) - // const jsonData = JSON.stringify(manifest, null, 4) - // //writeFile(path.join(destination[0,'manifest.json'), jsonData) + for (let item of expanded[0]['@graph']) { + try { + const manifest = this.createManifest(item) + //console.log('Manifest:', await manifest) + const manifestJson = JSON.stringify(await manifest, null, 4) + writeFile(path.join(destination[0],'manifest.json'), manifestJson) // manifests.push(manifest) // //zip.file(`${manifest.id}.json`, manifest) - // } catch (e) { - // console.log(e.stack) + } catch (e) { + console.log(e.stack) // // this.context.logger.warn( // // { // // stack: e.stack // // }, // // `failed to export IIIF manifest ${item}` // // ) - // } - // } + } + } const collection = this.createCollection(expanded[0]['@graph']) //manifests + const collectionJson = JSON.stringify(await collection, null, 4) + writeFile(path.join(destination[0],'collection.json'), collectionJson) console.log('Collection:', await collection) //zip.file(`${this.options.collectionName}`, collection) } @@ -78,7 +80,7 @@ class ExamplePlugin { let itemTemplate = this.loadTemplate(this.options.itemTemplate) let photoTemplate = this.loadTemplate(this.options.photoTemplate) - const props = { + const props = { //Should be in a class to reuse in createCollection identifier: item['http://purl.org/dc/terms/identifier']?.[0]['@value'], title: item['http://purl.org/dc/terms/title']?.[0]['@value'], description: item['http://purl.org/dc/terms/description']?.[0]['@value'], @@ -111,12 +113,12 @@ class ExamplePlugin { async createCollection(manifests) { const collection = builder.createCollection( - this.options.baseId + '/collection/' + this.options.collectionName.toLowerCase().replace(' ', '_'), + this.options.baseId + 'collection/' + this.options.collectionName.toLowerCase().replace(' ', '_'), async collection => { collection.addLabel(this.options.collectionName) for (let item of manifests) { - // Emprestado de createManifest + // Should be in a class const props = { identifier: item['http://purl.org/dc/terms/identifier']?.[0]['@value'], title: item['http://purl.org/dc/terms/title']?.[0]['@value'], @@ -130,27 +132,9 @@ class ExamplePlugin { // collection.createManifest(id, (manifest) => { - //manifest.addLabel(manifest.label['none'][0]) manifest.addLabel(props.title); - props.description && manifest.addSummary(props.description) - props.rights && manifest.setRights(props.rights); - props.source && manifest.setRequiredStatement({ - label: this.options.requiredStatementLabel, - value: this.options.requiredStatementText + ` ${props.source}` - }) - //props.latitude && props.longitude && manifest.addNavPlace(latitude, longitude) - //provider? - let itemTemplate = this.loadTemplate(this.options.itemTemplate) - this.fillMetadata(itemTemplate, item, manifest) - }) } - // manifests.map(manifest => { - // console.log(manifest) - // collection.createManifest(manifest.id, (manifest) => { - // manifest.addLabel(manifest.label) - // }) - // }) }) return collection } @@ -223,11 +207,12 @@ class ExamplePlugin { } ExamplePlugin.defaults = { - itemTemplate: '', + itemTemplate: 'Export IIIF', photoTemplate: '', collectionName: 'My IIIF Collection', requiredStatementLabel: 'Attribution', requiredStatementText: 'Provided by', + baseId: 'http://localhost:8887/', } // The plugin must be the module's default export.