From ff21770a7089d4ce04b1b80b92378d402e67e544 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 13 Oct 2022 18:38:01 +0800 Subject: [PATCH] Add GitHubHandler class --- .../src/websites/github-handler.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 packages/content-handler/src/websites/github-handler.ts diff --git a/packages/content-handler/src/websites/github-handler.ts b/packages/content-handler/src/websites/github-handler.ts new file mode 100644 index 000000000..c31fe2224 --- /dev/null +++ b/packages/content-handler/src/websites/github-handler.ts @@ -0,0 +1,23 @@ +import { ContentHandler } from '../content-handler' + +export class GitHubHandler extends ContentHandler { + constructor() { + super() + this.name = 'github' + } + + shouldPreParse(url: string, dom: Document): boolean { + return new URL(url).hostname.endsWith('github.com') + } + + async preParse(url: string, dom: Document): Promise { + const body = dom.querySelector('body') + const article = dom.querySelector('article') + + if (body && article) { + body?.replaceChildren(article) + } + + return Promise.resolve(dom) + } +}