diff --git a/src/components/AnnotationManifestsAccordion.js b/src/components/AnnotationManifestsAccordion.js index 7c46dadaf56e4d2d84a7e6f75fb56563b35dcc41..9ea6b71038d10f3820ac7cba6c1f65b585841ccc 100644 --- a/src/components/AnnotationManifestsAccordion.js +++ b/src/components/AnnotationManifestsAccordion.js @@ -24,16 +24,28 @@ export class AnnotationManifestsAccordion extends Component { this.handleOpenManifestSideToSide = this.handleOpenManifestSideToSide.bind(this); this.handleOpenAccordion = this.handleOpenAccordion.bind(this); - /** */ - function searchManifest(text) { + /** Search manifest directly in content. We consider all the links with #manifest at the end are manifest */ + function searchManifestInContent(text) { return text.match( - /((http|https)\:\/\/[a-z0-9\/:%_+.,#?!@&=-]+)#manifest/g, + /((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( + /((http|https)\:\/\/[a-z0-9\/:%_+.,#?!@&=-]+)#((http|https)\:\/\/[a-z0-9\/:%_+.,#?!@&=-]+)/gi, ); + + return match ? match[0].split('#').slice(-1) : null; } const { annotation } = this.props; - annotation.manifests = searchManifest(annotation.content.concat(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 { @@ -148,8 +160,8 @@ AnnotationManifestsAccordion.propsTypes = { addWindow: PropTypes.func.isRequired, annotation: PropTypes.shape( { - content: PropTypes.string.isRequired, - id: PropTypes.string.isRequired, + content: PropTypes.string, + id: PropTypes.string, manifests: PropTypes.arrayOf(PropTypes.string), }, ),