Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
fix: Get the correct image source url
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer committed Jul 3, 2019
1 parent 771b2ea commit 6b46808
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
26 changes: 12 additions & 14 deletions src/notion-blocks-to-rich-text-nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,9 @@ export function toText(text = []) {
export function toHeading(level) {
return block => {
const content = get(block, 'value.properties.title', []);

if (isEmpty(content)) {
return null;
}

return {
nodeType: `heading-${level}`,
content: content.map(toText)
Expand All @@ -104,11 +102,9 @@ export function toHeading(level) {

export function toParagraph(block) {
const content = get(block, 'value.properties.title', []);

if (isEmpty(content)) {
return null;
}

return {
nodeType: BLOCKS.PARAGRAPH,
content: content.map(toText)
Expand All @@ -117,27 +113,31 @@ export function toParagraph(block) {

export function toQuote(block) {
const content = get(block, 'value.properties.title', []);

if (isEmpty(content)) {
return null;
}

return {
nodeType: BLOCKS.QUOTE,
content: content.map(toText)
};
}

export function toListItem(listType) {
return block => ({
listType,
nodeType: BLOCKS.LIST_ITEM,
content: [toParagraph(block)]
});
return block => {
const content = toParagraph(block);
if (isEmpty(content)) {
return null;
}
return {
listType,
nodeType: BLOCKS.LIST_ITEM,
content: [toParagraph(block)]
};
};
}

export function toImage(block) {
const url = get(block, 'value.format.display_source');
const url = get(block, 'value.properties.source[0][0]');
const src = getImageSrc(url);
const caption = get(block, 'value.properties.caption[0]', []);
return {
Expand All @@ -162,11 +162,9 @@ export function toCallout(block) {
const content = get(block, 'value.properties.title', []);
const icon = getIcon(block);
const color = get(block, 'value.format.block_color');

if (isEmpty(content)) {
return null;
}

return {
nodeType: BLOCKS.CALLOUT,
data: { icon, color },
Expand Down
2 changes: 1 addition & 1 deletion src/utils/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function stringToSegments(path) {
// Split to an array from dot notation
return path.split('.').reduce((allSegments, item) => {
// Split to an array from bracket notation
item.split(/\[([^}]+)\]/g).forEach(key => {
item.split(/\[([^}\]]+)\]/g).forEach(key => {
// Push to the new array
if (key.length > 0) {
allSegments.push(key);
Expand Down
8 changes: 7 additions & 1 deletion src/utils/get.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ describe('get', () => {
baz: [
{
fizz: 'buzz'
}
},
['que']
]
}
};
Expand Down Expand Up @@ -46,4 +47,9 @@ describe('get', () => {
const actual = get(obj, 'fizz.buzz', 'default');
expect(actual).toBe('default');
});

it('should handle nested arrays', () => {
const actual = get(obj, 'foo.baz[1][0]');
expect(actual).toBe('que');
});
});

0 comments on commit 6b46808

Please sign in to comment.