import { useRuntimeConfig } from '#imports'; import { withTrailingSlash } from 'ufo'; import type { LocaleObject } from '@nuxtjs/i18n/dist/runtime/composables'; export default defineNitroPlugin((nitroApp) => { nitroApp.hooks.hook('render:html', (html, { event }) => { if (event.path.includes("_nuxt") || event.path.match(/\d{3}\.html/) || event.path.match(/^\/ns/)) { return; } const runtimeConfig = useRuntimeConfig(); const locales = runtimeConfig.public.locales as LocaleObject[]; if (!event.path.match(new RegExp(`^/(${locales.map((l) => l.code).join('|')})/`))) { const links = locales.map((l) => { const url = withTrailingSlash(`/${l.code}${event.path.replace(/\.html$/g, '/')}`); return `${l.name}`; }); html.htmlAttrs = []; const remainingList: string[] = []; html.head.forEach((v) => { remainingList.push(...(v.match(/)/gm) ?? [])); remainingList.push(...(v.match(/]+>/gm) ?? [])); remainingList.push(...(v.match(/]+>/gm) ?? [])); remainingList.push(...(v.match(/\n'); html.body = [ '\n\n', `\n`, ]; html.bodyAppend = []; html.bodyPrepend = []; } }); });