Skip to content

Commit

Permalink
fix: failed to fetch highlight when quote is null
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed Jun 22, 2023
1 parent 03a747b commit 2dc2fcc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export enum HighlightType {

export interface Highlight {
id: string;
quote: string;
annotation: string;
patch: string;
quote: string | null;
annotation: string | null;
patch: string | null;
updatedAt: string;
labels?: Label[];
type: HighlightType;
Expand Down
4 changes: 2 additions & 2 deletions src/settings/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export const renderArticleContnet = async (
highlightUrl: `https://omnivore.app/me/${article.slug}#${highlight.id}`,
highlightID: highlight.id.slice(0, 8),
dateHighlighted: formatDate(highlight.updatedAt, dateHighlightedFormat),
note: highlight.annotation,
note: highlight.annotation ?? undefined,
labels: renderLabels(highlight.labels),
};
});
Expand Down Expand Up @@ -228,7 +228,7 @@ export const renderArticleContnet = async (
datePublished,
fileAttachment,
description: article.description,
note: articleNote?.annotation,
note: articleNote?.annotation ?? undefined,
type: article.pageType,
dateRead,
wordsCount,
Expand Down
15 changes: 12 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ export interface HighlightPoint {
top: number;
}

export const getHighlightLocation = (patch: string): number => {
export const getHighlightLocation = (patch: string | null): number => {
if (!patch) {
return 0;
}
const dmp = new diff_match_patch();
const patches = dmp.patch_fromText(patch);
return patches[0].start1 || 0;
};

export const getHighlightPoint = (patch: string): HighlightPoint => {
export const getHighlightPoint = (patch: string | null): HighlightPoint => {
if (!patch) {
return { left: 0, top: 0 };
}
const { bbox } = JSON.parse(patch) as { bbox: number[] };
if (!bbox || bbox.length !== 4) {
return { left: 0, top: 0 };
Expand Down Expand Up @@ -129,9 +135,12 @@ export const siteNameFromUrl = (originalArticleUrl: string): string => {
};

export const formatHighlightQuote = (
quote: string,
quote: string | null,
template: string
): string => {
if (!quote) {
return "";
}
// if the template has highlights, we need to preserve paragraphs
const regex = /{{#highlights}}(\n)*>/gm;
if (regex.test(template)) {
Expand Down

0 comments on commit 2dc2fcc

Please sign in to comment.