Skip to content

Commit

Permalink
Add minimal info to collection, enable file write
Browse files Browse the repository at this point in the history
  • Loading branch information
martimpassos committed Sep 20, 2023
1 parent 3f66563 commit 0d5f442
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 47 deletions.
26 changes: 18 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
51 changes: 18 additions & 33 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand All @@ -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'],
Expand Down Expand Up @@ -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'],
Expand All @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0d5f442

Please sign in to comment.