Merge pull request #3064 from omnivore-app/fix/highlighted-markdown

fix: highlights not added to the content if searching for highlighted content
This commit is contained in:
Hongbo Wu 2023-11-03 11:59:47 +08:00 committed by GitHub
commit 90d0827b36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 43 deletions

View file

@ -46,7 +46,6 @@ import {
TypeaheadSearchSuccess,
UpdateReason,
UpdatesSinceError,
UpdatesSinceErrorCode,
UpdatesSinceSuccess,
} from '../../generated/graphql'
import { getColumns } from '../../repository'
@ -54,6 +53,7 @@ import { getInternalLabelWithColor } from '../../repository/label'
import { libraryItemRepository } from '../../repository/library_item'
import { userRepository } from '../../repository/user'
import { createPageSaveRequest } from '../../services/create_page_save_request'
import { findHighlightsByLibraryItemId } from '../../services/highlights'
import {
addLabelsToLibraryItem,
findLabelsByIds,
@ -661,28 +661,40 @@ export const searchResolver = authorized<
libraryItems.pop()
}
const edges = libraryItems.map((libraryItem) => {
if (params.includeContent && libraryItem.readableContent) {
// convert html to the requested format
const format = params.format || ArticleFormat.Html
try {
const converter = contentConverter(format)
if (converter) {
libraryItem.readableContent = converter(
libraryItem.readableContent,
libraryItem.highlights
)
}
} catch (error) {
log.error('Error converting content', error)
const edges = await Promise.all(
libraryItems.map(async (libraryItem) => {
if (
libraryItem.highlightAnnotations &&
libraryItem.highlightAnnotations.length > 0
) {
libraryItem.highlights = await findHighlightsByLibraryItemId(
libraryItem.id,
uid
)
}
}
return {
node: libraryItemToSearchItem(libraryItem),
cursor: endCursor,
}
})
if (params.includeContent && libraryItem.readableContent) {
// convert html to the requested format
const format = params.format || ArticleFormat.Html
try {
const converter = contentConverter(format)
if (converter) {
libraryItem.readableContent = converter(
libraryItem.readableContent,
libraryItem.highlights
)
}
} catch (error) {
log.error('Error converting content', error)
}
}
return {
node: libraryItemToSearchItem(libraryItem),
cursor: endCursor,
}
})
)
return {
edges,

View file

@ -3,23 +3,21 @@
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { createHmac } from 'crypto'
import { Subscription } from '../entity/subscription'
import { env } from '../env'
import {
Article,
Highlight,
Label,
PageType,
Recommendation,
SearchItem,
User,
} from '../generated/graphql'
import { findHighlightsByLibraryItemId } from '../services/highlights'
import { findLabelsByLibraryItemId } from '../services/labels'
import { findRecommendationsByLibraryItemId } from '../services/recommendation'
import { findUploadFileById } from '../services/upload_file'
import {
highlightDataToHighlight,
isBase64Image,
recommandationDataToRecommendation,
validatedDate,
@ -128,7 +126,6 @@ import { markEmailAsItemResolver, recentEmailsResolver } from './recent_emails'
import { recentSearchesResolver } from './recent_searches'
import { WithDataSourcesContext } from './types'
import { updateEmailResolver } from './user'
import { createHmac } from 'crypto'
/* eslint-disable @typescript-eslint/naming-convention */
type ResultResolveType = {
@ -378,24 +375,6 @@ export const functionResolvers = {
return item.siteIcon
},
async highlights(
item: {
id: string
highlights?: Highlight[]
highlightAnnotations?: string[] | null
},
_: unknown,
ctx: WithDataSourcesContext
) {
if (item.highlights) return item.highlights
if (item.highlightAnnotations && item.highlightAnnotations.length > 0) {
const highlights = await findHighlightsByLibraryItemId(item.id, ctx.uid)
return highlights.map(highlightDataToHighlight)
}
return []
},
async labels(
item: { id: string; labels?: Label[]; labelNames?: string[] | null },
_: unknown,