Skip to content

Commit

Permalink
feat: eager discover readable content (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
xc2 authored Oct 8, 2024
1 parent af7cf12 commit e8d6c1c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/content/read.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { InboxEntryInput } from "@/types";
import { Readability, isProbablyReaderable } from "@mozilla/readability";
import { Readability } from "@mozilla/readability";
import DOMPurify from "dompurify";

export interface ReaderInfo extends NonNullable<ReturnType<Readability["parse"]>> {
pured: string;
}

export function getReaderInfo(): ReaderInfo | false {
const isReaderable = isProbablyReaderable(document);
if (!isReaderable) return false;
const p = new Readability(document.cloneNode(true) as Document).parse()!;
const p = new Readability(document.cloneNode(true) as Document).parse();
if (!p) return false;

const pured = DOMPurify.sanitize(p?.content || "");
return { ...p, pured };
}
Expand Down

0 comments on commit e8d6c1c

Please sign in to comment.