run readability on the preview content

This commit is contained in:
Hongbo Wu 2023-12-18 19:08:45 +08:00
parent b1aca117f4
commit 22778af285
2 changed files with 24 additions and 2 deletions

View file

@ -13,6 +13,7 @@ import { libraryItemRepository } from '../repository/library_item'
import { SaveFollowingItemRequest } from '../routers/svc/following'
import { generateSlug, wordsCount } from '../utils/helpers'
import { createThumbnailUrl } from '../utils/imageproxy'
import { parsePreparedContent } from '../utils/parser'
import { parseSearchQuery } from '../utils/search'
enum ReadFilter {
@ -847,11 +848,30 @@ export const createLibraryItem = async (
return newLibraryItem
}
export const saveFeedItemInFollowing = (
export const saveFeedItemInFollowing = async (
input: SaveFollowingItemRequest,
userId: string
) => {
const thumbnail = input.thumbnail && createThumbnailUrl(input.thumbnail)
let content: string | undefined
if (input.previewContent) {
const parsedResult = await parsePreparedContent(input.url, {
document: input.previewContent,
pageInfo: {
title: input.title,
author: input.author,
canonicalUrl: input.url,
contentType: input.previewContentType,
description: input.description,
previewImage: thumbnail,
},
})
if (parsedResult.parsedContent) {
content = parsedResult.parsedContent.content
}
}
return authTrx(
async (tx) => {
@ -863,6 +883,8 @@ export const saveFeedItemInFollowing = (
folder: InFilter.FOLLOWING,
slug: generateSlug(input.title),
thumbnail,
readableContent: content,
state: LibraryItemState.ContentNotFetched,
}
return tx

View file

@ -180,7 +180,7 @@ const getPurifiedContent = (html: string): Document => {
const getReadabilityResult = async (
url: string,
html: string,
document: Document,
document?: Document,
isNewsletter?: boolean
): Promise<Readability.ParseResult | null> => {
// First attempt to read the article as is.