From ec328a33355caae6ce3459f9c29cdfc6b38a1c2a Mon Sep 17 00:00:00 2001 From: Anthony Geourjon <anthony.geourjon@tetras-libre.fr> Date: Wed, 1 Mar 2023 15:23:07 +0100 Subject: [PATCH] Revert "Disable searching manifest in annotation content" This reverts commit 33e158c3d5bd5601008e950321e56972f284e397. --- src/components/AnnotationManifestsAccordion.js | 16 +++++++++++++++- src/helper/utils.js | 6 ++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/components/AnnotationManifestsAccordion.js b/src/components/AnnotationManifestsAccordion.js index 95cb2f11e..5287697ca 100644 --- a/src/components/AnnotationManifestsAccordion.js +++ b/src/components/AnnotationManifestsAccordion.js @@ -24,6 +24,16 @@ export class AnnotationManifestsAccordion extends Component { this.handleOpenManifestSideToSide = this.handleOpenManifestSideToSide.bind(this); this.handleOpenAccordion = this.handleOpenAccordion.bind(this); + /** Search manifest directly in content. We consider all the links with #manifest at the end are manifest */ + function searchManifestInContent(text) { + if (text == null) { + return null; + } + return text.match( + /((http|https)\:\/\/[a-z0-9\/:%_+.,#?!@&=-]+)#manifest/gi, + ); + } + /** Search if the annotation is a manifest. URL must be resolvable for the annotation. So the manifest url is added at the end of the id */ function searchManifestInID(id) { const match = id.match( @@ -35,13 +45,17 @@ export class AnnotationManifestsAccordion extends Component { const { annotation } = this.props; - annotation.manifests = searchManifestInID(annotation.id); + /** Merge array even if some are null) */ + const concat = (...arrays) => [].concat(...arrays.filter(Array.isArray)); + + annotation.manifests = concat(searchManifestInContent(annotation.content), searchManifestInID(annotation.id)); if (annotation.manifests) { annotation.manifests = annotation.manifests.map(id => ({ id })); } else { annotation.manifests = []; } + annotation.manifests = removeDuplicates(annotation.manifests); this.state = { annotation }; } diff --git a/src/helper/utils.js b/src/helper/utils.js index a39f2b31a..c0b88adc3 100644 --- a/src/helper/utils.js +++ b/src/helper/utils.js @@ -1,3 +1,9 @@ +/** + * Remove duplicate elements in array + * + * */ +export const removeDuplicates = (arr) => [...new Map(arr.map(v => [v.id, v])).values()]; + /** * Filter annotation with a query string. Search in ID and value * */ -- GitLab