From e11e4735908c06ba03410c0184f3dcacae3a31d4 Mon Sep 17 00:00:00 2001 From: ryanscottaudio Date: Wed, 22 Mar 2017 14:26:37 -0400 Subject: [PATCH 1/2] Pass showCaptionInArticleView prop down --- lib/block-list.js | 13 +++++++------ lib/embed.js | 4 ++++ lib/header.js | 3 ++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/block-list.js b/lib/block-list.js index 869e30b..b523b5a 100644 --- a/lib/block-list.js +++ b/lib/block-list.js @@ -13,13 +13,14 @@ const types = { header4: ({children}) => renderHeading(4, children), header5: ({children}) => renderHeading(5, children), header6: ({children}) => renderHeading(6, children), - embed: item => renderEmbed(item, { + embed: (item, opts) => renderEmbed(item, { layout: 'embedLayout', style: 'embedStyle', mediaLayout: 'embedMediaLayout', mediaStyle: 'embedMediaStyle', captionLayout: 'embedCaptionLayout', - captionTextStyle: 'embedCaptionTextStyle' + captionTextStyle: 'embedCaptionTextStyle', + showCaptionInArticleView: opts.showCaptionInArticleView }) }; @@ -29,7 +30,7 @@ const hasContent = ({children}) => children.some(child => child.type !== 'linebreak' && (child.content && child.content.trim())); -function renderItem (item) { +function renderItem (item, opts) { const {type} = item; if (!types[type]) { return null; @@ -39,11 +40,11 @@ function renderItem (item) { return null; } - return types[type](item); + return types[type](item, opts); } -export default function ({body}) { +export default function ({body}, opts) { return body - .map(renderItem) + .map(renderItem, opts) .filter(Boolean); } diff --git a/lib/embed.js b/lib/embed.js index de3c959..b40642c 100644 --- a/lib/embed.js +++ b/lib/embed.js @@ -83,6 +83,10 @@ const render = (item, opts) => { } embed.caption = renderTextItems(null, item.caption, captionOpts); + + if (opts.showCaptionInArticleView) { + + } } return result; diff --git a/lib/header.js b/lib/header.js index b292814..baca491 100644 --- a/lib/header.js +++ b/lib/header.js @@ -54,7 +54,8 @@ const componentsWithEmbed = (article, opts) => mediaLayout: 'headerEmbedMediaLayout', mediaStyle: 'headerEmbedMediaStyle', captionLayout: 'headerCaptionLayout', - captionTextStyle: 'headerCaptionTextStyle' + captionTextStyle: 'headerCaptionTextStyle', + showCaptionInArticleView: opts.showCaptionInArticleView })] .concat(componentsWithoutEmbed(article, opts)); From 65a67d203a23c5ddb55f334b9f08009622f40e75 Mon Sep 17 00:00:00 2001 From: ryanscottaudio Date: Wed, 22 Mar 2017 15:36:47 -0400 Subject: [PATCH 2/2] Append captions and attributions correctly --- lib/block-list.js | 6 +++--- lib/embed.js | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/block-list.js b/lib/block-list.js index b523b5a..60cf4f1 100644 --- a/lib/block-list.js +++ b/lib/block-list.js @@ -30,7 +30,7 @@ const hasContent = ({children}) => children.some(child => child.type !== 'linebreak' && (child.content && child.content.trim())); -function renderItem (item, opts) { +const renderItem = opts => item => { const {type} = item; if (!types[type]) { return null; @@ -41,10 +41,10 @@ function renderItem (item, opts) { } return types[type](item, opts); -} +}; export default function ({body}, opts) { return body - .map(renderItem, opts) + .map(renderItem(opts)) .filter(Boolean); } diff --git a/lib/embed.js b/lib/embed.js index b40642c..10b3d73 100644 --- a/lib/embed.js +++ b/lib/embed.js @@ -43,6 +43,14 @@ const embeds = { }) }; +const renderCaption = (item, opts) => { + const captionToRender = item.attribution + ? item.caption.concat([{ type: 'text', content: ' ' }], item.attribution) + : item.caption; + + return renderTextItems(null, captionToRender, opts); +}; + const render = (item, opts) => { opts = opts || {}; const embed = embeds[item.embedType](item); @@ -82,10 +90,12 @@ const render = (item, opts) => { captionOpts.textStyle = opts.captionTextStyle; } - embed.caption = renderTextItems(null, item.caption, captionOpts); + const captionComponent = renderCaption(item, captionOpts); + captionComponent.role = 'caption'; + embed.caption = captionComponent; if (opts.showCaptionInArticleView) { - + result.components.push(captionComponent); } }