22 lines
613 B
TypeScript
22 lines
613 B
TypeScript
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
|
|
}
|
|
}
|
|
}
|