You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rsvp-reader/scripts/metadata/parseMetadata.js

23 lines
613 B
JavaScript

function* parseMetadata(metadata) {
for (const [key, entry] of Object.entries(metadata)) {
entry.textUris = entry.formaturi
.filter(uri => extensionIn(uri, ['.txt', '.utf-8']))
.map(stripPGHost)
entry.pictures = entry.formaturi
.filter(uri => extensionIn(uri, ['.jpg', 'png']))
.map(stripPGHost)
delete entry.formaturi
entry.id = key
yield entry
}
}
function extensionIn(path, endings) {
return endings.some(ending => path.endsWith(ending))
}
function stripPGHost(uri) {
return uri.replace('http://www.gutenberg.org', '')
}
module.exports = { parseMetadata }