diff --git a/src/components/AnnotationManifestsAccordion.js b/src/components/AnnotationManifestsAccordion.js index 95cb2f11e3b6d0068c055259380a269b1b21f48f..5287697ca3fccc3b0f913aba26ffcd31693de0e3 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 a39f2b31a29cbd5399f4a018b3375263c2fa1a84..c0b88adc3de9679525e9f2f172cd85fd33be4f28 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 * */