Add GitHubHandler class

This commit is contained in:
Jackson Harper 2022-10-13 18:38:01 +08:00
parent f39c6923b0
commit ff21770a70

View file

@ -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<Document> {
const body = dom.querySelector('body')
const article = dom.querySelector('article')
if (body && article) {
body?.replaceChildren(article)
}
return Promise.resolve(dom)
}
}