Merge pull request #1308 from omnivore-app/fix/github-handler

Create a content handler for GitHub pages
This commit is contained in:
Hongbo Wu 2022-10-14 11:59:10 +08:00 committed by GitHub
commit ef745cce3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View file

@ -9,6 +9,7 @@ import { TDotCoHandler } from './websites/t-dot-co-handler'
import { TwitterHandler } from './websites/twitter-handler'
import { YoutubeHandler } from './websites/youtube-handler'
import { WikipediaHandler } from './websites/wikipedia-handler'
import { GitHubHandler } from './websites/github-handler'
import {
ContentHandler,
NewsletterInput,
@ -52,6 +53,7 @@ const contentHandlers: ContentHandler[] = [
new TwitterHandler(),
new YoutubeHandler(),
new WikipediaHandler(),
new GitHubHandler(),
new AxiosHandler(),
new GolangHandler(),
new MorningBrewHandler(),

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