Created
November 23, 2019 21:25
-
-
Save destroytoday/d7d2c2cf17dc3c271fc60c224b727443 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findAnnotations (field:Block | Inline):Array<Block | Inline> { | |
const annotations:Array<Block | Inline> = [] | |
// `field.content` returns Block | Inline | Text | |
// I’d like to ignore Text | |
// `reduce` is showing a TypeScript error "This expression is not callable" because Text isn’t included | |
// but if I add it, `node.content` errors because Text doesn’t have `.content` | |
return field.content.reduce((acc:Array<Block | Inline>, node:Block | Inline) => { | |
if (node.nodeType === INLINES.EMBEDDED_ENTRY && node.data.target.sys.contentType.sys.id === 'annotation') { | |
acc.push(node.data.target) | |
} else if (node.content && node.content.length > 0) { | |
acc.push(...this.findAnnotations(node)) | |
} | |
return acc | |
}, annotations) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment