Skip to content

Commit

Permalink
fix: warn about first i18n usage
Browse files Browse the repository at this point in the history
Fixes #215
  • Loading branch information
harlan-zw committed Sep 29, 2024
1 parent 0a70312 commit 4e0e75d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/core/src/puppeteer/tasks/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export function processSeoMeta($: CheerioAPI): HTMLExtractPayload {
}

export const inspectHtmlTask: PuppeteerTask = async (props) => {
const { resolvedConfig, hooks, runtimeSettings } = useUnlighthouse()
const unlighthouse = useUnlighthouse()
const { resolvedConfig, hooks, runtimeSettings } = unlighthouse
const { page, data: routeReport } = props
const logger = useLogger()
let html: string
Expand Down Expand Up @@ -140,9 +141,14 @@ export const inspectHtmlTask: PuppeteerTask = async (props) => {
routeReport.seo = processSeoMeta($)
if (resolvedConfig.scanner.ignoreI18nPages && routeReport.seo.alternativeLangDefault && withoutTrailingSlash(routeReport.route.url) !== withoutTrailingSlash(routeReport.seo.alternativeLangDefault)) {
routeReport.tasks.inspectHtmlTask = 'ignore'
logger.debug(`Page has an alternative lang, ignoring \`${routeReport.route.path}\`: ${routeReport.seo.alternativeLangDefault}`)
if (!unlighthouse._i18nWarn) {
unlighthouse._i18nWarn = true
logger.warn(`Page has an alternative lang, ignoring \`${routeReport.route.path}\`: ${routeReport.seo.alternativeLangDefault}. You can disable this behavior with the \`scanner.ignoreI18nPages = true\` option. Future warnings will be suppressed.`)
}
else {
logger.debug(`Page has an alternative lang, ignoring \`${routeReport.route.path}\`: ${routeReport.seo.alternativeLangDefault}`)
}
// make sure we queue the default, this fixes issues with if the home page has a default lang that is alternative
const unlighthouse = useUnlighthouse()
unlighthouse.worker.queueRoute(normaliseRoute(routeReport.seo.alternativeLangDefault))
return routeReport
}
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,4 +881,8 @@ export interface UnlighthouseContext {
* @internal
*/
_axios?: AxiosInstance
/**
* @internal
*/
_i18nWarn?: boolean
}

0 comments on commit 4e0e75d

Please sign in to comment.