From 12160cc9dcb6042f62b64a8be0fd1e0bf722d894 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 10 Mar 2023 15:43:06 +0800 Subject: [PATCH] filter out highlights with no quote --- packages/api/src/services/integrations.ts | 37 +++++++++++++---------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/api/src/services/integrations.ts b/packages/api/src/services/integrations.ts index a0aeac460..7c3a0ddaf 100644 --- a/packages/api/src/services/integrations.ts +++ b/packages/api/src/services/integrations.ts @@ -65,22 +65,27 @@ const validateReadwiseToken = async (token: string): Promise => { const pageToReadwiseHighlight = (page: Page): ReadwiseHighlight[] => { if (!page.highlights) return [] - return page.highlights.map((highlight) => { - return { - text: highlight.quote, - title: page.title, - author: page.author || undefined, - highlight_url: getHighlightUrl(page.slug, highlight.id), - highlighted_at: new Date(highlight.createdAt).toISOString(), - category: 'articles', - image_url: page.image || undefined, - location: highlight.highlightPositionPercent || undefined, - location_type: 'order', - note: highlight.annotation || undefined, - source_type: 'omnivore', - source_url: page.url, - } - }) + return ( + page.highlights + // filter out highlights with no quote + .filter((highlight) => highlight.quote.length === 0) + .map((highlight) => { + return { + text: highlight.quote, + title: page.title, + author: page.author || undefined, + highlight_url: getHighlightUrl(page.slug, highlight.id), + highlighted_at: new Date(highlight.createdAt).toISOString(), + category: 'articles', + image_url: page.image || undefined, + location: highlight.highlightPositionPercent || undefined, + location_type: 'order', + note: highlight.annotation || undefined, + source_type: 'omnivore', + source_url: page.url, + } + }) + ) } export const syncWithIntegration = async (