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.
23 lines
613 B
JavaScript
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 }
|