Merge pull request #652 from omnivore-app/fix/parse-partial-documents

If parsing fails, attempt adding <html> wrappers to a document
This commit is contained in:
Jackson Harper 2022-05-18 13:15:38 -07:00 committed by GitHub
commit ac6df4d139
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -205,7 +205,8 @@ const applyHandlers = async (
export const parsePreparedContent = async (
url: string,
preparedDocument: PreparedDocumentInput,
isNewsletter?: boolean
isNewsletter?: boolean,
allowRetry = true
): Promise<ParsedContentPuppeteer> => {
const logRecord: ArticleParseLogRecord = {
url: url,
@ -236,6 +237,13 @@ export const parsePreparedContent = async (
try {
article = getReadabilityResult(url, document, dom, isNewsletter)
if (!article?.textContent && allowRetry) {
const newDocument = {
...preparedDocument,
document: '<html>' + preparedDocument.document + '</html>',
}
return parsePreparedContent(url, newDocument, isNewsletter, false)
}
// Format code blocks
// TODO: we probably want to move this type of thing