refactor: optional lang and title for engines response

This commit is contained in:
Artemy Egorov 2023-09-07 13:19:43 +03:00
parent 7d0d5f1888
commit 945d237fd6
3 changed files with 7 additions and 6 deletions

View File

@ -76,8 +76,6 @@ export default async function google(
return {
content: `${searchForm}${content.join("")}${navigation}`,
textContent: textContent.join("\n"),
title: window.document.title,
lang: window.document.documentElement.lang,
};
}

View File

@ -1,8 +1,8 @@
export interface IHandlerOutput {
content: string;
textContent: string;
title: string;
lang: string;
title?: string;
lang?: string;
}
export const handlerSchema = {

View File

@ -53,9 +53,12 @@ export default async function handlePage(
return engines[engine](window);
}
for (let match of fallback) {
const title = window.document.title;
const lang = window.document.documentElement.lang;
for (const match of fallback) {
if (micromatch.isMatch(urlObj.hostname, match.pattern)) {
return match.engine(window);
return { title, lang, ...match.engine(window) };
}
}