Upgraded topola library version to 2.5.1

This commit is contained in:
Przemek Wiech
2020-01-15 20:11:25 +01:00
parent f0b8f1929d
commit 904e4e5a24
3 changed files with 25 additions and 23 deletions

6
package-lock.json generated
View File

@@ -14558,9 +14558,9 @@
"dev": true "dev": true
}, },
"topola": { "topola": {
"version": "2.4.0", "version": "2.5.1",
"resolved": "https://registry.npmjs.org/topola/-/topola-2.4.0.tgz", "resolved": "https://registry.npmjs.org/topola/-/topola-2.5.1.tgz",
"integrity": "sha512-ncLg4eDFeF1UNXEcpJvrm8iMnNCtTVsDg8hWHJr83UMSfiV8EwcvklyhoKjB1uRsp/E+eSKOMJb44Acgn5BM1w==", "integrity": "sha512-g1hDeT0X4HHg/p1/Wr/fgUceN9JlP6LC1rIJkfP7lPwWVZcplzfdCDzuyIKPfkrUsE5OZAhw3LoPu6xKv1u/dg==",
"requires": { "requires": {
"array-flat-polyfill": "^1.0.1", "array-flat-polyfill": "^1.0.1",
"d3": "^5.4.0", "d3": "^5.4.0",

View File

@@ -23,7 +23,7 @@
"react-router-dom": "^4.3.1", "react-router-dom": "^4.3.1",
"semantic-ui-css": "^2.4.1", "semantic-ui-css": "^2.4.1",
"semantic-ui-react": "^0.84.0", "semantic-ui-react": "^0.84.0",
"topola": "^2.4.0" "topola": "^2.5.1"
}, },
"devDependencies": { "devDependencies": {
"@types/array.prototype.flatmap": "^1.2.0", "@types/array.prototype.flatmap": "^1.2.0",

View File

@@ -1,4 +1,10 @@
import {JsonFam, JsonGedcomData, JsonIndi, gedcomEntriesToJson} from 'topola'; import {
JsonFam,
JsonGedcomData,
JsonIndi,
gedcomEntriesToJson,
JsonImage,
} from 'topola';
import {GedcomEntry, parse as parseGedcom} from 'parse-gedcom'; import {GedcomEntry, parse as parseGedcom} from 'parse-gedcom';
export interface GedcomData { export interface GedcomData {
@@ -122,28 +128,24 @@ function isImageFile(fileName: string): boolean {
} }
/** /**
* Removes imageUrl fields that are not HTTP links or do not have known image * Removes images that are not HTTP links or do not have known image extensions.
* extensions. Does not modify the input object. * Does not modify the input object.
*/ */
function filterImage(indi: JsonIndi, images: Map<string, string>): JsonIndi { function filterImage(indi: JsonIndi, images: Map<string, string>): JsonIndi {
if (indi.imageUrl) { if (!indi.images || indi.images.length === 0) {
const fileName = indi.imageUrl.match(/[^/\\]*$/)![0];
// If the image file has been loaded into memory, use it.
if (images.has(fileName)) {
const newIndi = Object.assign({}, indi);
newIndi.imageUrl = images.get(fileName);
return newIndi;
}
}
if (
!indi.imageUrl ||
(indi.imageUrl.startsWith('http') && isImageFile(indi.imageUrl))
) {
return indi; return indi;
} }
const newIndi = Object.assign({}, indi); const newImages: JsonImage[] = [];
delete newIndi.imageUrl; indi.images.forEach((image) => {
return newIndi; const fileName = image.url.match(/[^/\\]*$/)![0];
// If the image file has been loaded into memory, use it.
if (images.has(fileName)) {
newImages.push({url: images.get(fileName)!, title: image.title});
} else if (image.url.startsWith('http') && isImageFile(image.url)) {
newImages.push(image);
}
});
return Object.assign({}, indi, {images: newImages});
} }
/** /**