Skip to content
Snippets Groups Projects
Commit 40ae0ebd authored by Anthony's avatar Anthony
Browse files

Use new convention for manifest in ID

parent c917880d
No related branches found
No related tags found
2 merge requests!13Manifest side to side,!11Draft: 33 8 open an other manifest side by side from an annotation
...@@ -24,16 +24,28 @@ export class AnnotationManifestsAccordion extends Component { ...@@ -24,16 +24,28 @@ export class AnnotationManifestsAccordion extends Component {
this.handleOpenManifestSideToSide = this.handleOpenManifestSideToSide.bind(this); this.handleOpenManifestSideToSide = this.handleOpenManifestSideToSide.bind(this);
this.handleOpenAccordion = this.handleOpenAccordion.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 searchManifest(text) { function searchManifestInContent(text) {
return text.match( 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; 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) { if (annotation.manifests) {
annotation.manifests = annotation.manifests.map(id => ({ id })); annotation.manifests = annotation.manifests.map(id => ({ id }));
} else { } else {
...@@ -148,8 +160,8 @@ AnnotationManifestsAccordion.propsTypes = { ...@@ -148,8 +160,8 @@ AnnotationManifestsAccordion.propsTypes = {
addWindow: PropTypes.func.isRequired, addWindow: PropTypes.func.isRequired,
annotation: PropTypes.shape( annotation: PropTypes.shape(
{ {
content: PropTypes.string.isRequired, content: PropTypes.string,
id: PropTypes.string.isRequired, id: PropTypes.string,
manifests: PropTypes.arrayOf(PropTypes.string), manifests: PropTypes.arrayOf(PropTypes.string),
}, },
), ),
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment