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) + } +}