Add tests

This commit is contained in:
Hongbo Wu
2022-09-29 16:22:51 +08:00
parent 5fdb8b337d
commit 8fb398eae4
15 changed files with 86 additions and 44 deletions

View File

@ -0,0 +1,21 @@
import { ContentHandler, PreHandleResult } from './index'
class MediumHandler extends ContentHandler {
shouldPreHandle(url: string, dom?: Document): boolean {
const u = new URL(url)
return u.hostname.endsWith('medium.com')
}
async preHandle(url: string, document?: Document): Promise<PreHandleResult> {
console.log('prehandling medium url', url)
try {
const res = new URL(url)
res.searchParams.delete('source')
return Promise.resolve({ url: res.toString() })
} catch (error) {
console.error('error prehandling medium url', error)
throw error
}
}
}