Moved engine selecting logic into separate function
This commit is contained in:
parent
da67666a6c
commit
f6dc1f953e
@ -4,6 +4,8 @@ import axios from "../types/axios";
|
||||
import { JSDOM } from "jsdom";
|
||||
import { DOMWindow } from "jsdom";
|
||||
|
||||
import micromatch from "micromatch";
|
||||
|
||||
import readability from "./readability";
|
||||
import google, { GoogleDomains } from "./google";
|
||||
import stackoverflow, { StackOverflowDomains } from "./stackoverflow/main";
|
||||
@ -11,8 +13,6 @@ import stackoverflow, { StackOverflowDomains } from "./stackoverflow/main";
|
||||
import { generateProxyUrl } from "../utils/generate";
|
||||
import isLocalResource from "../utils/islocal";
|
||||
|
||||
import micromatch from "micromatch";
|
||||
|
||||
import { LocalResourceError, NotHtmlMimetypeError } from "../errors/main";
|
||||
|
||||
export default async function handlePage(
|
||||
@ -49,20 +49,19 @@ export default async function handlePage(
|
||||
}
|
||||
});
|
||||
|
||||
if (engine) {
|
||||
return engines[engine](window);
|
||||
return getFallbackEngine(urlObj.hostname, engine)(window);
|
||||
}
|
||||
|
||||
function getFallbackEngine(host: string, specified?: string): EngineFunction {
|
||||
if (specified) {
|
||||
return engines[specified];
|
||||
}
|
||||
|
||||
const title = window.document.title;
|
||||
const lang = window.document.documentElement.lang;
|
||||
|
||||
for (const match of fallback) {
|
||||
if (micromatch.isMatch(urlObj.hostname, match.pattern)) {
|
||||
return { title, lang, ...match.engine(window) };
|
||||
for (const engine of fallback) {
|
||||
if (micromatch.isMatch(host, engine.pattern)) {
|
||||
return engine.engine;
|
||||
}
|
||||
}
|
||||
|
||||
return engines.readability(window);
|
||||
return engines.readability;
|
||||
}
|
||||
|
||||
interface Engines {
|
||||
|
Loading…
x
Reference in New Issue
Block a user