@fluenti/nuxt 0.4.0-rc.1 → 0.4.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/detectors-BBAX-ZGA.cjs +2 -0
- package/dist/detectors-BBAX-ZGA.cjs.map +1 -0
- package/dist/{detectors-CBe19LCy.js → detectors-Ds481Wx6.js} +20 -34
- package/dist/detectors-Ds481Wx6.js.map +1 -0
- package/dist/{locale-head-CV660rxz.js → locale-head-Ezrd93Ax.js} +8 -8
- package/dist/locale-head-Ezrd93Ax.js.map +1 -0
- package/dist/locale-head-jGmp0Xnb.cjs +2 -0
- package/dist/locale-head-jGmp0Xnb.cjs.map +1 -0
- package/dist/module.cjs +1 -1
- package/dist/module.cjs.map +1 -1
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +4 -4
- package/dist/module.js.map +1 -1
- package/dist/{page-extend-BrPO2RhM.js → page-extend-Bnxtcvnr.js} +4 -2
- package/dist/{page-extend-BrPO2RhM.js.map → page-extend-Bnxtcvnr.js.map} +1 -1
- package/dist/{page-extend-tRXsujtK.cjs → page-extend-DqTELmU6.cjs} +2 -2
- package/dist/{page-extend-tRXsujtK.cjs.map → page-extend-DqTELmU6.cjs.map} +1 -1
- package/dist/page-meta-transform.d.ts.map +1 -1
- package/dist/parse-accept-language-BJacT1Mq.js +24 -0
- package/dist/parse-accept-language-BJacT1Mq.js.map +1 -0
- package/dist/parse-accept-language-ZKitIm3n.cjs +2 -0
- package/dist/parse-accept-language-ZKitIm3n.cjs.map +1 -0
- package/dist/runtime/client.cjs +1 -1
- package/dist/runtime/client.js +2 -2
- package/dist/runtime/composables.cjs +1 -1
- package/dist/runtime/composables.js +1 -1
- package/dist/runtime/detectors/header.d.ts.map +1 -1
- package/dist/runtime/index.cjs +1 -1
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/locale-head.d.ts.map +1 -1
- package/dist/runtime/middleware/locale-redirect.cjs +1 -1
- package/dist/runtime/middleware/locale-redirect.js +1 -1
- package/dist/runtime/plugin.cjs +1 -1
- package/dist/runtime/plugin.js +1 -1
- package/dist/runtime/server/locale-redirect.cjs +1 -1
- package/dist/runtime/server/locale-redirect.cjs.map +1 -1
- package/dist/runtime/server/locale-redirect.d.ts.map +1 -1
- package/dist/runtime/server/locale-redirect.js +20 -34
- package/dist/runtime/server/locale-redirect.js.map +1 -1
- package/dist/runtime/standalone-composables.cjs +1 -1
- package/dist/runtime/standalone-composables.js +1 -1
- package/dist/runtime/utils/parse-accept-language.d.ts +6 -0
- package/dist/runtime/utils/parse-accept-language.d.ts.map +1 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/detectors-CBe19LCy.js.map +0 -1
- package/dist/detectors-CxhqsYjl.cjs +0 -2
- package/dist/detectors-CxhqsYjl.cjs.map +0 -1
- package/dist/locale-head-CV660rxz.js.map +0 -1
- package/dist/locale-head-CwFSeJqY.cjs +0 -2
- package/dist/locale-head-CwFSeJqY.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locale-redirect.js","names":[],"sources":["../../../src/runtime/server/locale-redirect.ts"],"sourcesContent":["import { defineEventHandler, sendRedirect, getHeader, getCookie, getQuery } from 'h3'\n\n/**\n * Nitro server middleware for locale-based redirects.\n *\n * Runs at the Nitro layer (before Vue Router), which is earlier in the\n * request lifecycle. This prevents any flash of wrong-locale content\n * during SSR, as the redirect happens before page rendering starts.\n *\n * Only active when strategy is 'prefix' or 'prefix_and_default'.\n */\nexport default defineEventHandler((event) => {\n const url = event.path ?? '/'\n\n // Skip non-page requests (assets, API routes, etc.)\n if (url.startsWith('/_nuxt/') || url.startsWith('/api/') || url.startsWith('/__nuxt')) {\n return\n }\n\n // Skip if URL already has a file extension (static assets)\n if (/\\.\\w{2,5}$/.test(url)) {\n return\n }\n\n // Read config from runtime config\n const config = (event.context['__fluenti_config'] ??\n useRuntimeConfigFromEvent(event)) as {\n locales: string[]\n defaultLocale: string\n strategy: string\n detectOrder?: string[]\n queryParamKey?: string\n detectBrowserLanguage?: { useCookie?: boolean; cookieKey?: string; fallbackLocale?: string }\n } | undefined\n\n if (!config) return\n\n // Only handle prefix/prefix_and_default strategies\n if (config.strategy !== 'prefix' && config.strategy !== 'prefix_and_default') {\n return\n }\n\n // Check if the URL already has a locale prefix\n const pathSegments = url.split('/').filter(Boolean)\n const firstSegment = pathSegments[0]\n\n if (firstSegment && config.locales.includes(firstSegment)) {\n // URL already has a valid locale prefix\n return\n }\n\n // For prefix_and_default, unprefixed URLs are allowed for the default locale\n // (they will be served without redirect)\n // For prefix strategy, we must redirect\n\n // Detect locale from various sources\n let detectedLocale = config.defaultLocale\n\n //
|
|
1
|
+
{"version":3,"file":"locale-redirect.js","names":[],"sources":["../../../src/runtime/server/locale-redirect.ts"],"sourcesContent":["import { defineEventHandler, sendRedirect, getHeader, getCookie, getQuery } from 'h3'\nimport { parseAcceptLanguage } from '../utils/parse-accept-language'\n\n/**\n * Nitro server middleware for locale-based redirects.\n *\n * Runs at the Nitro layer (before Vue Router), which is earlier in the\n * request lifecycle. This prevents any flash of wrong-locale content\n * during SSR, as the redirect happens before page rendering starts.\n *\n * Only active when strategy is 'prefix' or 'prefix_and_default'.\n */\nexport default defineEventHandler((event) => {\n const url = event.path ?? '/'\n\n // Skip non-page requests (assets, API routes, etc.)\n if (url.startsWith('/_nuxt/') || url.startsWith('/api/') || url.startsWith('/__nuxt')) {\n return\n }\n\n // Skip if URL already has a file extension (static assets)\n if (/\\.\\w{2,5}$/.test(url)) {\n return\n }\n\n // Read config from runtime config\n const config = (event.context['__fluenti_config'] ??\n useRuntimeConfigFromEvent(event)) as {\n locales: string[]\n defaultLocale: string\n strategy: string\n detectOrder?: string[]\n queryParamKey?: string\n detectBrowserLanguage?: { useCookie?: boolean; cookieKey?: string; fallbackLocale?: string }\n } | undefined\n\n if (!config) return\n\n // Only handle prefix/prefix_and_default strategies\n if (config.strategy !== 'prefix' && config.strategy !== 'prefix_and_default') {\n return\n }\n\n // Check if the URL already has a locale prefix\n const pathSegments = url.split('/').filter(Boolean)\n const firstSegment = pathSegments[0]\n\n if (firstSegment && config.locales.includes(firstSegment)) {\n // URL already has a valid locale prefix\n return\n }\n\n // For prefix_and_default, unprefixed URLs are allowed for the default locale\n // (they will be served without redirect)\n // For prefix strategy, we must redirect\n\n // Detect locale from various sources\n let detectedLocale = config.defaultLocale\n\n // Detection chain: query → cookie → Accept-Language → default\n const queryKey = config.queryParamKey ?? 'locale'\n const queryLocale = getQuery(event)[queryKey]\n\n if (typeof queryLocale === 'string' && config.locales.includes(queryLocale)) {\n detectedLocale = queryLocale\n } else {\n const cookieKey = config.detectBrowserLanguage?.cookieKey ?? 'fluenti_locale'\n const cookieLocale = getCookie(event, cookieKey)\n if (cookieLocale && config.locales.includes(cookieLocale)) {\n detectedLocale = cookieLocale\n } else {\n const acceptLang = getHeader(event, 'accept-language')\n if (acceptLang) {\n const preferred = parseAcceptLanguage(acceptLang, config.locales)\n if (preferred) detectedLocale = preferred\n }\n }\n }\n\n // Redirect to locale-prefixed URL\n const cleanUrl = url === '/' ? '' : url\n const redirectUrl = `/${detectedLocale}${cleanUrl}`\n\n return sendRedirect(event, redirectUrl, 302)\n})\n\n/**\n * Read Fluenti runtime config from the event context.\n */\nfunction useRuntimeConfigFromEvent(event: { context: Record<string, unknown> }) {\n try {\n const nitroConfig = (event.context['nitro'] ?? event.context['__nitro']) as Record<string, unknown> | undefined\n const runtimeConfig = (nitroConfig?.['runtimeConfig'] ?? {}) as Record<string, unknown>\n const publicConfig = (runtimeConfig['public'] ?? {}) as Record<string, unknown>\n const fluentiConfig = publicConfig['fluenti']\n if (fluentiConfig) {\n event.context['__fluenti_config'] = fluentiConfig\n }\n return fluentiConfig\n } catch {\n return undefined\n }\n}\n"],"mappings":";;;AAYA,IAAA,IAAe,GAAoB,MAAU;CAC3C,IAAM,IAAM,EAAM,QAAQ;AAQ1B,KALI,EAAI,WAAW,UAAU,IAAI,EAAI,WAAW,QAAQ,IAAI,EAAI,WAAW,UAAU,IAKjF,aAAa,KAAK,EAAI,CACxB;CAIF,IAAM,IAAU,EAAM,QAAQ,oBAC5B,EAA0B,EAAM;AAYlC,KAHI,CAAC,KAGD,EAAO,aAAa,YAAY,EAAO,aAAa,qBACtD;CAKF,IAAM,IADe,EAAI,MAAM,IAAI,CAAC,OAAO,QAAQ,CACjB;AAElC,KAAI,KAAgB,EAAO,QAAQ,SAAS,EAAa,CAEvD;CAQF,IAAI,IAAiB,EAAO,eAGtB,IAAW,EAAO,iBAAiB,UACnC,IAAc,EAAS,EAAM,CAAC;AAEpC,KAAI,OAAO,KAAgB,YAAY,EAAO,QAAQ,SAAS,EAAY,CACzE,KAAiB;MACZ;EAEL,IAAM,IAAe,EAAU,GADb,EAAO,uBAAuB,aAAa,iBACb;AAChD,MAAI,KAAgB,EAAO,QAAQ,SAAS,EAAa,CACvD,KAAiB;OACZ;GACL,IAAM,IAAa,EAAU,GAAO,kBAAkB;AACtD,OAAI,GAAY;IACd,IAAM,IAAY,EAAoB,GAAY,EAAO,QAAQ;AACjE,IAAI,MAAW,IAAiB;;;;AAStC,QAAO,EAAa,GAFA,IAAI,IADP,MAAQ,MAAM,KAAK,KAGI,IAAI;EAC5C;AAKF,SAAS,EAA0B,GAA6C;AAC9E,KAAI;EAIF,IAAM,OAHe,EAAM,QAAQ,SAAY,EAAM,QAAQ,UACxB,iBAAoB,EAAE,EACvB,UAAa,EAAE,EAChB;AAInC,SAHI,MACF,EAAM,QAAQ,mBAAsB,IAE/B;SACD;AACN"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../path-utils-BQIsp_or.cjs`),t=require(`../locale-head-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../path-utils-BQIsp_or.cjs`),t=require(`../locale-head-jGmp0Xnb.cjs`);require(`../module.cjs`);let n=require(`vue`);function r(t,n){return(r,i)=>e.n(r,i??t.value,n.defaultLocale,n.strategy)}function i(t,n){return r=>e.r(t.value,r,n.locales,n.defaultLocale,n.strategy)}function a(t,n,r){return(i,a)=>{let o=a??t.value;if(typeof i==`string`){let t=e.n(i,o,r.defaultLocale,r.strategy);return n.resolve(t)}if(`path`in i&&i.path){let t=e.n(i.path,o,r.defaultLocale,r.strategy);return n.resolve({...i,path:t})}return n.resolve(i)}}function o(e,r,i,a){return(0,n.computed)(()=>t.t(e.value,r.value,i,a))}exports.useLocaleHead=o,exports.useLocalePath=r,exports.useLocaleRoute=a,exports.useSwitchLocalePath=i;
|
|
2
2
|
//# sourceMappingURL=standalone-composables.cjs.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as e, r as t } from "../path-utils-BcvXLCGi.js";
|
|
2
|
-
import { t as n } from "../locale-head-
|
|
2
|
+
import { t as n } from "../locale-head-Ezrd93Ax.js";
|
|
3
3
|
import { computed as r } from "vue";
|
|
4
4
|
//#region src/runtime/standalone-composables.ts
|
|
5
5
|
function i(t, n) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse Accept-Language header and find the best matching locale.
|
|
3
|
+
* Shared between server handler and client-side header detector.
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseAcceptLanguage(header: string, locales: string[]): string | null;
|
|
6
|
+
//# sourceMappingURL=parse-accept-language.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-accept-language.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils/parse-accept-language.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CA2BpF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -196,6 +196,15 @@ export interface FluentNuxtOptions {
|
|
|
196
196
|
* @default true
|
|
197
197
|
*/
|
|
198
198
|
globalMiddleware?: boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Whether to register the page meta transform plugin.
|
|
201
|
+
*
|
|
202
|
+
* When enabled (default), `defineI18nRoute()` and `definePageMeta({ i18n: ... })`
|
|
203
|
+
* are automatically transformed. Set to `false` to disable the Vite transform.
|
|
204
|
+
*
|
|
205
|
+
* @default true
|
|
206
|
+
*/
|
|
207
|
+
pageMetaTransform?: boolean;
|
|
199
208
|
/**
|
|
200
209
|
* Whether to register the `NuxtLinkLocale` component globally.
|
|
201
210
|
*
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAE3D,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,CAAA;AAG7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEnE,gDAAgD;AAChD,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,uBAAuB,GAAG,oBAAoB,GAAG,WAAW,GAAG,SAAS,CAAA;AAE1G,yCAAyC;AACzC,MAAM,WAAW,4BAA4B;IAC3C,kDAAkD;IAClD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,8BAA8B;AAC9B,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAA;AAE/E;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,0CA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;IACpD,2CAA2C;IAC3C,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAC1B,gDAAgD;IAChD,aAAa,EAAE,MAAM,CAAA;IACrB,0DAA0D;IAC1D,sBAAsB,EAAE,OAAO,CAAA;IAC/B,6DAA6D;IAC7D,OAAO,CAAC,EAAE,YAAY,EAAE,CAAA;IACxB,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;CAChD;AAID,4DAA4D;AAC5D,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAUjG;AAED,0EAA0E;AAC1E,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,gBAAgB,EAAE,EAC3B,QAAQ,CAAC,EAAE,YAAY,EAAE,GACxB,YAAY,EAAE,CAShB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluenti/nuxt",
|
|
3
|
-
"version": "0.4.0-rc.
|
|
3
|
+
"version": "0.4.0-rc.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Nuxt module for Fluenti — locale-prefixed routes, SEO helpers, auto locale detection",
|
|
6
6
|
"homepage": "https://fluenti.dev",
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"@nuxt/kit": "^4.4.2",
|
|
72
72
|
"@nuxt/schema": "^4.4.2",
|
|
73
|
-
"@fluenti/
|
|
74
|
-
"@fluenti/
|
|
73
|
+
"@fluenti/vue": "0.4.0-rc.2",
|
|
74
|
+
"@fluenti/core": "0.4.0-rc.2"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"typescript": "^5.9",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"detectors-CBe19LCy.js","names":[],"sources":["../src/runtime/detectors/path.ts","../src/runtime/detectors/cookie.ts","../src/runtime/detectors/header.ts","../src/runtime/detectors/query.ts","../src/runtime/detectors/index.ts"],"sourcesContent":["import type { LocaleDetectContext } from '../../types'\nimport { extractLocaleFromPath } from '../path-utils'\n\n/** Detect locale from URL path prefix (e.g. /ja/about → 'ja') */\nexport default function detectPath(ctx: LocaleDetectContext): void {\n if (ctx.strategy === 'no_prefix') return\n const { locale } = extractLocaleFromPath(ctx.path, ctx.locales)\n if (locale) {\n ctx.setLocale(locale)\n }\n}\n","import { useCookie } from '#imports'\nimport type { LocaleDetectContext } from '../../types'\n\n/** Detect locale from cookie value */\nexport default function detectCookie(ctx: LocaleDetectContext): void {\n if (!ctx.detectBrowserLanguage?.useCookie) return\n\n // Prefer pre-read cookie value from plugin (hoisted before await)\n if (ctx.cookieValue !== undefined) {\n if (ctx.cookieValue && ctx.locales.includes(ctx.cookieValue)) {\n ctx.setLocale(ctx.cookieValue)\n }\n return\n }\n\n // Fallback: read cookie directly (works when called synchronously in plugin context)\n const cookieKey = ctx.detectBrowserLanguage.cookieKey ?? 'fluenti_locale'\n try {\n const cookie = useCookie(cookieKey)\n if (cookie.value && ctx.locales.includes(cookie.value)) {\n ctx.setLocale(cookie.value)\n }\n } catch {\n // useCookie may fail outside Nuxt context\n }\n}\n","import { useRequestHeaders } from '#imports'\nimport type { LocaleDetectContext } from '../../types'\n\n/** Detect locale from Accept-Language header (SSR only) */\nexport default function detectHeader(ctx: LocaleDetectContext): void {\n if (!ctx.isServer) return\n\n // Prefer pre-read header from plugin (hoisted before await)\n const acceptLang = ctx.acceptLanguage ?? readAcceptLanguage()\n if (acceptLang) {\n const matched = negotiateLocale(acceptLang, ctx.locales)\n if (matched) {\n ctx.setLocale(matched)\n }\n }\n}\n\nfunction readAcceptLanguage(): string | undefined {\n try {\n const headers = useRequestHeaders(['accept-language'])\n return headers['accept-language']\n } catch {\n return undefined\n }\n}\n\nfunction negotiateLocale(acceptLanguage: string, locales: string[]): string | null {\n const preferred = acceptLanguage\n .split(',')\n .map((part) => {\n const [lang, q] = part.trim().split(';q=')\n const parsed = q ? parseFloat(q) : 1\n return { lang: lang!.trim().toLowerCase(), q: Number.isFinite(parsed) ? parsed : 0 }\n })\n .sort((a, b) => b.q - a.q)\n\n for (const { lang } of preferred) {\n if (locales.includes(lang)) return lang\n const prefix = lang.split('-')[0]!\n if (locales.includes(prefix)) return prefix\n }\n\n return null\n}\n","import { useRoute, useRuntimeConfig } from '#imports'\nimport type { LocaleDetectContext } from '../../types'\nimport type { FluentNuxtRuntimeConfig } from '../../types'\n\n/** Detect locale from query parameter (e.g. ?locale=ja) */\nexport default function detectQuery(ctx: LocaleDetectContext): void {\n try {\n const route = useRoute()\n const config = useRuntimeConfig().public['fluenti'] as FluentNuxtRuntimeConfig\n const paramKey = config.queryParamKey ?? 'locale'\n const queryLocale = route.query[paramKey] as string | undefined\n if (queryLocale && ctx.locales.includes(queryLocale)) {\n ctx.setLocale(queryLocale)\n }\n } catch {\n // May fail outside Nuxt context\n }\n}\n","import type { LocaleDetectContext, LocaleDetectorFn, FluentNuxtRuntimeConfig } from '../../types'\nimport detectPath from './path'\nimport detectCookie from './cookie'\nimport detectHeader from './header'\nimport detectQuery from './query'\nimport detectDomain from './domain'\n\n/** Map of built-in detector names to their implementations */\nconst builtinDetectors: Record<string, LocaleDetectorFn> = {\n path: detectPath,\n cookie: detectCookie,\n header: detectHeader,\n query: detectQuery,\n domain: detectDomain,\n}\n\n/**\n * Run the detection chain: iterate through detectOrder, then fire the hook.\n *\n * Returns the detected locale or the defaultLocale as fallback.\n */\nexport async function runDetectors(\n path: string,\n config: FluentNuxtRuntimeConfig,\n customDetectors?: Map<string, LocaleDetectorFn>,\n hookFn?: (ctx: LocaleDetectContext) => void | Promise<void>,\n host?: string,\n cookieValue?: string | null,\n acceptLanguage?: string,\n): Promise<string> {\n let resolved: string | null = null\n let stopped = false\n\n const ctx: LocaleDetectContext = {\n path,\n locales: config.locales,\n defaultLocale: config.defaultLocale,\n strategy: config.strategy,\n ...(config.detectBrowserLanguage ? { detectBrowserLanguage: config.detectBrowserLanguage } : {}),\n detectedLocale: null,\n setLocale(locale: string) {\n if (config.locales.includes(locale)) {\n resolved = locale\n ctx.detectedLocale = locale\n stopped = true\n }\n },\n isServer: import.meta.server ?? false,\n ...(host ? { host } : {}),\n ...(cookieValue != null ? { cookieValue } : {}),\n ...(acceptLanguage ? { acceptLanguage } : {}),\n }\n\n // Attach domains to context for domain detector\n if (config.domains) {\n Object.assign(ctx, { domains: config.domains })\n }\n\n // 1. Run detectors in order\n for (const name of config.detectOrder) {\n if (stopped) break\n\n const detector = builtinDetectors[name] ?? customDetectors?.get(name)\n if (detector) {\n await detector(ctx)\n }\n }\n\n // 2. Fire the hook — allows overriding or supplementing the detection chain\n if (hookFn && !stopped) {\n await hookFn(ctx)\n }\n\n // 3. Fallback\n return resolved ?? config.detectBrowserLanguage?.fallbackLocale ?? config.defaultLocale\n}\n\nexport { builtinDetectors }\nexport type { LocaleDetectContext, LocaleDetectorFn }\n"],"mappings":";;;;AAIA,SAAwB,EAAW,GAAgC;AACjE,KAAI,EAAI,aAAa,YAAa;CAClC,IAAM,EAAE,cAAW,EAAsB,EAAI,MAAM,EAAI,QAAQ;AAC/D,CAAI,KACF,EAAI,UAAU,EAAO;;;;ACJzB,SAAwB,EAAa,GAAgC;AACnE,KAAI,CAAC,EAAI,uBAAuB,UAAW;AAG3C,KAAI,EAAI,gBAAgB,KAAA,GAAW;AACjC,EAAI,EAAI,eAAe,EAAI,QAAQ,SAAS,EAAI,YAAY,IAC1D,EAAI,UAAU,EAAI,YAAY;AAEhC;;CAIF,IAAM,IAAY,EAAI,sBAAsB,aAAa;AACzD,KAAI;EACF,IAAM,IAAS,EAAU,EAAU;AACnC,EAAI,EAAO,SAAS,EAAI,QAAQ,SAAS,EAAO,MAAM,IACpD,EAAI,UAAU,EAAO,MAAM;SAEvB;;;;AClBV,SAAwB,EAAa,GAAgC;AACnE,KAAI,CAAC,EAAI,SAAU;CAGnB,IAAM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AO,uBAAuB,GAAG,EAAE;EAC/F,gBAAgB;EAChB,UAAU,GAAgB;AACxB,GAAI,EAAO,QAAQ,SAAS,EAAO,KACjC,IAAW,GACX,EAAI,iBAAiB,GACrB,IAAU;;EAGd,UAAU,OAAO,KAAK,UAAU;EAChC,GAAI,IAAO,EAAE,SAAM,GAAG,EAAE;EACxB,GAAI,KAAe,OAAyB,EAAE,GAApB,EAAE,gBAAa;EACzC,GAAI,IAAiB,EAAE,mBAAgB,GAAG,EAAE;EAC7C;AAGD,CAAI,EAAO,WACT,OAAO,OAAO,GAAK,EAAE,SAAS,EAAO,SAAS,CAAC;AAIjD,MAAK,IAAM,KAAQ,EAAO,aAAa;AACrC,MAAI,EAAS;EAEb,IAAM,IAAW,EAAiB,MAAS,GAAiB,IAAI,EAAK;AACrE,EAAI,KACF,MAAM,EAAS,EAAI;;AAUvB,QALI,KAAU,CAAC,KACb,MAAM,EAAO,EAAI,EAIZ,KAAY,EAAO,uBAAuB,kBAAkB,EAAO"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require(`./path-utils-BQIsp_or.cjs`);require(`./module.cjs`);const t=require(`./runtime/detectors/domain.cjs`);let n=require(`#imports`);function r(t){if(t.strategy===`no_prefix`)return;let{locale:n}=e.t(t.path,t.locales);n&&t.setLocale(n)}function i(e){if(!e.detectBrowserLanguage?.useCookie)return;if(e.cookieValue!==void 0){e.cookieValue&&e.locales.includes(e.cookieValue)&&e.setLocale(e.cookieValue);return}let t=e.detectBrowserLanguage.cookieKey??`fluenti_locale`;try{let r=(0,n.useCookie)(t);r.value&&e.locales.includes(r.value)&&e.setLocale(r.value)}catch{}}function a(e){if(!e.isServer)return;let t=e.acceptLanguage??o();if(t){let n=s(t,e.locales);n&&e.setLocale(n)}}function o(){try{return(0,n.useRequestHeaders)([`accept-language`])[`accept-language`]}catch{return}}function s(e,t){let n=e.split(`,`).map(e=>{let[t,n]=e.trim().split(`;q=`),r=n?parseFloat(n):1;return{lang:t.trim().toLowerCase(),q:Number.isFinite(r)?r:0}}).sort((e,t)=>t.q-e.q);for(let{lang:e}of n){if(t.includes(e))return e;let n=e.split(`-`)[0];if(t.includes(n))return n}return null}function c(e){try{let t=(0,n.useRoute)(),r=(0,n.useRuntimeConfig)().public.fluenti.queryParamKey??`locale`,i=t.query[r];i&&e.locales.includes(i)&&e.setLocale(i)}catch{}}var l={path:r,cookie:i,header:a,query:c,domain:t};async function u(e,t,n,r,i,a,o){let s=null,c=!1,u={path:e,locales:t.locales,defaultLocale:t.defaultLocale,strategy:t.strategy,...t.detectBrowserLanguage?{detectBrowserLanguage:t.detectBrowserLanguage}:{},detectedLocale:null,setLocale(e){t.locales.includes(e)&&(s=e,u.detectedLocale=e,c=!0)},isServer:{}.server??!1,...i?{host:i}:{},...a==null?{}:{cookieValue:a},...o?{acceptLanguage:o}:{}};t.domains&&Object.assign(u,{domains:t.domains});for(let e of t.detectOrder){if(c)break;let t=l[e]??n?.get(e);t&&await t(u)}return r&&!c&&await r(u),s??t.detectBrowserLanguage?.fallbackLocale??t.defaultLocale}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return u}});
|
|
2
|
-
//# sourceMappingURL=detectors-CxhqsYjl.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"detectors-CxhqsYjl.cjs","names":[],"sources":["../src/runtime/detectors/path.ts","../src/runtime/detectors/cookie.ts","../src/runtime/detectors/header.ts","../src/runtime/detectors/query.ts","../src/runtime/detectors/index.ts"],"sourcesContent":["import type { LocaleDetectContext } from '../../types'\nimport { extractLocaleFromPath } from '../path-utils'\n\n/** Detect locale from URL path prefix (e.g. /ja/about → 'ja') */\nexport default function detectPath(ctx: LocaleDetectContext): void {\n if (ctx.strategy === 'no_prefix') return\n const { locale } = extractLocaleFromPath(ctx.path, ctx.locales)\n if (locale) {\n ctx.setLocale(locale)\n }\n}\n","import { useCookie } from '#imports'\nimport type { LocaleDetectContext } from '../../types'\n\n/** Detect locale from cookie value */\nexport default function detectCookie(ctx: LocaleDetectContext): void {\n if (!ctx.detectBrowserLanguage?.useCookie) return\n\n // Prefer pre-read cookie value from plugin (hoisted before await)\n if (ctx.cookieValue !== undefined) {\n if (ctx.cookieValue && ctx.locales.includes(ctx.cookieValue)) {\n ctx.setLocale(ctx.cookieValue)\n }\n return\n }\n\n // Fallback: read cookie directly (works when called synchronously in plugin context)\n const cookieKey = ctx.detectBrowserLanguage.cookieKey ?? 'fluenti_locale'\n try {\n const cookie = useCookie(cookieKey)\n if (cookie.value && ctx.locales.includes(cookie.value)) {\n ctx.setLocale(cookie.value)\n }\n } catch {\n // useCookie may fail outside Nuxt context\n }\n}\n","import { useRequestHeaders } from '#imports'\nimport type { LocaleDetectContext } from '../../types'\n\n/** Detect locale from Accept-Language header (SSR only) */\nexport default function detectHeader(ctx: LocaleDetectContext): void {\n if (!ctx.isServer) return\n\n // Prefer pre-read header from plugin (hoisted before await)\n const acceptLang = ctx.acceptLanguage ?? readAcceptLanguage()\n if (acceptLang) {\n const matched = negotiateLocale(acceptLang, ctx.locales)\n if (matched) {\n ctx.setLocale(matched)\n }\n }\n}\n\nfunction readAcceptLanguage(): string | undefined {\n try {\n const headers = useRequestHeaders(['accept-language'])\n return headers['accept-language']\n } catch {\n return undefined\n }\n}\n\nfunction negotiateLocale(acceptLanguage: string, locales: string[]): string | null {\n const preferred = acceptLanguage\n .split(',')\n .map((part) => {\n const [lang, q] = part.trim().split(';q=')\n const parsed = q ? parseFloat(q) : 1\n return { lang: lang!.trim().toLowerCase(), q: Number.isFinite(parsed) ? parsed : 0 }\n })\n .sort((a, b) => b.q - a.q)\n\n for (const { lang } of preferred) {\n if (locales.includes(lang)) return lang\n const prefix = lang.split('-')[0]!\n if (locales.includes(prefix)) return prefix\n }\n\n return null\n}\n","import { useRoute, useRuntimeConfig } from '#imports'\nimport type { LocaleDetectContext } from '../../types'\nimport type { FluentNuxtRuntimeConfig } from '../../types'\n\n/** Detect locale from query parameter (e.g. ?locale=ja) */\nexport default function detectQuery(ctx: LocaleDetectContext): void {\n try {\n const route = useRoute()\n const config = useRuntimeConfig().public['fluenti'] as FluentNuxtRuntimeConfig\n const paramKey = config.queryParamKey ?? 'locale'\n const queryLocale = route.query[paramKey] as string | undefined\n if (queryLocale && ctx.locales.includes(queryLocale)) {\n ctx.setLocale(queryLocale)\n }\n } catch {\n // May fail outside Nuxt context\n }\n}\n","import type { LocaleDetectContext, LocaleDetectorFn, FluentNuxtRuntimeConfig } from '../../types'\nimport detectPath from './path'\nimport detectCookie from './cookie'\nimport detectHeader from './header'\nimport detectQuery from './query'\nimport detectDomain from './domain'\n\n/** Map of built-in detector names to their implementations */\nconst builtinDetectors: Record<string, LocaleDetectorFn> = {\n path: detectPath,\n cookie: detectCookie,\n header: detectHeader,\n query: detectQuery,\n domain: detectDomain,\n}\n\n/**\n * Run the detection chain: iterate through detectOrder, then fire the hook.\n *\n * Returns the detected locale or the defaultLocale as fallback.\n */\nexport async function runDetectors(\n path: string,\n config: FluentNuxtRuntimeConfig,\n customDetectors?: Map<string, LocaleDetectorFn>,\n hookFn?: (ctx: LocaleDetectContext) => void | Promise<void>,\n host?: string,\n cookieValue?: string | null,\n acceptLanguage?: string,\n): Promise<string> {\n let resolved: string | null = null\n let stopped = false\n\n const ctx: LocaleDetectContext = {\n path,\n locales: config.locales,\n defaultLocale: config.defaultLocale,\n strategy: config.strategy,\n ...(config.detectBrowserLanguage ? { detectBrowserLanguage: config.detectBrowserLanguage } : {}),\n detectedLocale: null,\n setLocale(locale: string) {\n if (config.locales.includes(locale)) {\n resolved = locale\n ctx.detectedLocale = locale\n stopped = true\n }\n },\n isServer: import.meta.server ?? false,\n ...(host ? { host } : {}),\n ...(cookieValue != null ? { cookieValue } : {}),\n ...(acceptLanguage ? { acceptLanguage } : {}),\n }\n\n // Attach domains to context for domain detector\n if (config.domains) {\n Object.assign(ctx, { domains: config.domains })\n }\n\n // 1. Run detectors in order\n for (const name of config.detectOrder) {\n if (stopped) break\n\n const detector = builtinDetectors[name] ?? customDetectors?.get(name)\n if (detector) {\n await detector(ctx)\n }\n }\n\n // 2. Fire the hook — allows overriding or supplementing the detection chain\n if (hookFn && !stopped) {\n await hookFn(ctx)\n }\n\n // 3. Fallback\n return resolved ?? config.detectBrowserLanguage?.fallbackLocale ?? config.defaultLocale\n}\n\nexport { builtinDetectors }\nexport type { LocaleDetectContext, LocaleDetectorFn }\n"],"mappings":"iJAIA,SAAwB,EAAW,EAAgC,CACjE,GAAI,EAAI,WAAa,YAAa,OAClC,GAAM,CAAE,UAAW,EAAA,EAAsB,EAAI,KAAM,EAAI,QAAQ,CAC3D,GACF,EAAI,UAAU,EAAO,CCJzB,SAAwB,EAAa,EAAgC,CACnE,GAAI,CAAC,EAAI,uBAAuB,UAAW,OAG3C,GAAI,EAAI,cAAgB,IAAA,GAAW,CAC7B,EAAI,aAAe,EAAI,QAAQ,SAAS,EAAI,YAAY,EAC1D,EAAI,UAAU,EAAI,YAAY,CAEhC,OAIF,IAAM,EAAY,EAAI,sBAAsB,WAAa,iBACzD,GAAI,CACF,IAAM,GAAA,EAAA,EAAA,WAAmB,EAAU,CAC/B,EAAO,OAAS,EAAI,QAAQ,SAAS,EAAO,MAAM,EACpD,EAAI,UAAU,EAAO,MAAM,MAEvB,GClBV,SAAwB,EAAa,EAAgC,CACnE,GAAI,CAAC,EAAI,SAAU,OAGnB,IAAM,EAAa,EAAI,gBAAkB,GAAoB,CAC7D,GAAI,EAAY,CACd,IAAM,EAAU,EAAgB,EAAY,EAAI,QAAQ,CACpD,GACF,EAAI,UAAU,EAAQ,EAK5B,SAAS,GAAyC,CAChD,GAAI,CAEF,OAAA,EAAA,EAAA,mBADkC,CAAC,kBAAkB,CAAC,CACvC,wBACT,CACN,QAIJ,SAAS,EAAgB,EAAwB,EAAkC,CACjF,IAAM,EAAY,EACf,MAAM,IAAI,CACV,IAAK,GAAS,CACb,GAAM,CAAC,EAAM,GAAK,EAAK,MAAM,CAAC,MAAM,MAAM,CACpC,EAAS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,CAAC,CAIjD,IAAK,IAAM,KAAQ,EAAO,YAAa,CACrC,GAAI,EAAS,MAEb,IAAM,EAAW,EAAiB,IAAS,GAAiB,IAAI,EAAK,CACjE,GACF,MAAM,EAAS,EAAI,CAUvB,OALI,GAAU,CAAC,GACb,MAAM,EAAO,EAAI,CAIZ,GAAY,EAAO,uBAAuB,gBAAkB,EAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"locale-head-CV660rxz.js","names":[],"sources":["../src/runtime/locale-head.ts"],"sourcesContent":["import { switchLocalePath } from './path-utils'\nimport type { FluentNuxtRuntimeConfig } from '../types'\n\n/**\n * Safely construct an href from a base URL and path.\n * Guards against protocol injection and malformed URLs.\n */\nfunction buildSafeHref(baseUrl: string, path: string): string {\n if (!baseUrl) return path\n try {\n const url = new URL(path, baseUrl)\n if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n return path\n }\n return url.href\n } catch {\n return path\n }\n}\n\n/** Head metadata for locale SEO */\nexport interface LocaleHeadMeta {\n htmlAttrs: { lang: string; dir?: string }\n link: Array<{ rel: string; hreflang: string; href: string }>\n meta: Array<{ property: string; content: string }>\n}\n\nexport interface LocaleHeadOptions {\n /** Add hreflang and og:locale SEO attributes */\n addSeoAttributes?: boolean\n /** Base URL for absolute hreflang links (e.g. 'https://example.com') */\n baseUrl?: string\n /** Add a canonical link tag for the current page (default: true when addSeoAttributes is true) */\n addCanonical?: boolean\n}\n\n/**\n * Pure function that builds locale-aware HTML head metadata.\n *\n * This is the framework-agnostic core logic. For the Nuxt composable,\n * use `useLocaleHead()` from `composables.ts` instead.\n */\nexport function buildLocaleHead(\n locale: string,\n currentPath: string,\n config: FluentNuxtRuntimeConfig,\n options?: LocaleHeadOptions,\n): LocaleHeadMeta {\n const props = config.localeProperties?.[locale]\n const isoTag = props?.iso ?? locale\n\n const head: LocaleHeadMeta = {\n htmlAttrs: {\n lang: isoTag,\n ...(props?.dir ? { dir: props.dir } : {}),\n },\n link: [],\n meta: [],\n }\n\n if (options?.addSeoAttributes) {\n const baseUrl = options.baseUrl ?? ''\n\n // hreflang alternate links for each locale\n for (const loc of config.locales) {\n const locProps = config.localeProperties?.[loc]\n const locIso = locProps?.iso ?? loc\n\n if (config.strategy === 'domains' && config.domains?.length) {\n // For domain strategy, build absolute URLs using domain configs\n const domainEntry = config.domains.find((d) => d.locale === loc)\n if (domainEntry) {\n const protocol = baseUrl.startsWith('https') ? 'https' : 'http'\n head.link.push({\n rel: 'alternate',\n hreflang: locIso,\n href: buildSafeHref(`${protocol}://${domainEntry.domain}`, currentPath),\n })\n }\n } else {\n const path = switchLocalePath(\n currentPath,\n loc,\n config.locales,\n config.defaultLocale,\n config.strategy,\n )\n head.link.push({\n rel: 'alternate',\n hreflang: locIso,\n href: buildSafeHref(baseUrl, path),\n })\n }\n }\n\n // x-default hreflang\n if (config.strategy === 'domains' && config.domains?.length) {\n const defaultDomain = config.domains.find((d) => d.locale === config.defaultLocale)\n if (defaultDomain) {\n const protocol = baseUrl.startsWith('https') ? 'https' : 'http'\n head.link.push({\n rel: 'alternate',\n hreflang: 'x-default',\n href: buildSafeHref(`${protocol}://${defaultDomain.domain}`, currentPath),\n })\n }\n } else {\n const defaultPath = switchLocalePath(\n currentPath,\n config.defaultLocale,\n config.locales,\n config.defaultLocale,\n config.strategy,\n )\n head.link.push({\n rel: 'alternate',\n hreflang: 'x-default',\n href: buildSafeHref(baseUrl, defaultPath),\n })\n }\n\n // Canonical link tag (defaults to true when addSeoAttributes is enabled)\n if (options.addCanonical !== false) {\n if (config.strategy === 'domains' && config.domains?.length) {\n const domainEntry = config.domains.find((d) => d.locale === locale)\n if (domainEntry) {\n const protocol = baseUrl.startsWith('https') ? 'https' : 'http'\n head.link.push({\n rel: 'canonical',\n hreflang: '',\n href: buildSafeHref(`${protocol}://${domainEntry.domain}`, currentPath),\n })\n }\n } else {\n const canonicalPath = switchLocalePath(\n currentPath,\n locale,\n config.locales,\n config.defaultLocale,\n config.strategy,\n )\n head.link.push({\n rel: 'canonical',\n hreflang: '',\n href: buildSafeHref(baseUrl, canonicalPath),\n })\n }\n }\n\n // og:locale (use ISO tag if available)\n head.meta.push({ property: 'og:locale', content: isoTag })\n\n // og:locale:alternate for other locales\n for (const loc of config.locales) {\n if (loc !== locale) {\n const locProps = config.localeProperties?.[loc]\n head.meta.push({\n property: 'og:locale:alternate',\n content: locProps?.iso ?? loc,\n })\n }\n }\n }\n\n return head\n}\n"],"mappings":";;AAOA,SAAS,EAAc,GAAiB,GAAsB;AAC5D,KAAI,CAAC,EAAS,QAAO;AACrB,KAAI;EACF,IAAM,IAAM,IAAI,IAAI,GAAM,EAAQ;AAIlC,SAHI,EAAI,aAAa,WAAW,EAAI,aAAa,WACxC,IAEF,EAAI;SACL;AACN,SAAO;;;AA0BX,SAAgB,EACd,GACA,GACA,GACA,GACgB;CAChB,IAAM,IAAQ,EAAO,mBAAmB,IAClC,IAAS,GAAO,OAAO,GAEvB,IAAuB;EAC3B,WAAW;GACT,MAAM;GACN,GAAI,GAAO,MAAM,EAAE,KAAK,EAAM,KAAK,GAAG,EAAE;GACzC;EACD,MAAM,EAAE;EACR,MAAM,EAAE;EACT;AAED,KAAI,GAAS,kBAAkB;EAC7B,IAAM,IAAU,EAAQ,WAAW;AAGnC,OAAK,IAAM,KAAO,EAAO,SAAS;GAEhC,IAAM,IADW,EAAO,mBAAmB,IAClB,OAAO;AAEhC,OAAI,EAAO,aAAa,aAAa,EAAO,SAAS,QAAQ;IAE3D,IAAM,IAAc,EAAO,QAAQ,MAAM,MAAM,EAAE,WAAW,EAAI;AAChE,QAAI,GAAa;KACf,IAAM,IAAW,EAAQ,WAAW,QAAQ,GAAG,UAAU;AACzD,OAAK,KAAK,KAAK;MACb,KAAK;MACL,UAAU;MACV,MAAM,EAAc,GAAG,EAAS,KAAK,EAAY,UAAU,EAAY;MACxE,CAAC;;UAEC;IACL,IAAM,IAAO,EACX,GACA,GACA,EAAO,SACP,EAAO,eACP,EAAO,SACR;AACD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AU,OAAO;IAC3B,CAAC;;;AAKR,QAAO"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require(`./path-utils-BQIsp_or.cjs`);function t(e,t){if(!e)return t;try{let n=new URL(t,e);return n.protocol!==`http:`&&n.protocol!==`https:`?t:n.href}catch{return t}}function n(n,r,i,a){let o=i.localeProperties?.[n],s=o?.iso??n,c={htmlAttrs:{lang:s,...o?.dir?{dir:o.dir}:{}},link:[],meta:[]};if(a?.addSeoAttributes){let o=a.baseUrl??``;for(let n of i.locales){let a=i.localeProperties?.[n]?.iso??n;if(i.strategy===`domains`&&i.domains?.length){let e=i.domains.find(e=>e.locale===n);if(e){let n=o.startsWith(`https`)?`https`:`http`;c.link.push({rel:`alternate`,hreflang:a,href:t(`${n}://${e.domain}`,r)})}}else{let s=e.r(r,n,i.locales,i.defaultLocale,i.strategy);c.link.push({rel:`alternate`,hreflang:a,href:t(o,s)})}}if(i.strategy===`domains`&&i.domains?.length){let e=i.domains.find(e=>e.locale===i.defaultLocale);if(e){let n=o.startsWith(`https`)?`https`:`http`;c.link.push({rel:`alternate`,hreflang:`x-default`,href:t(`${n}://${e.domain}`,r)})}}else{let n=e.r(r,i.defaultLocale,i.locales,i.defaultLocale,i.strategy);c.link.push({rel:`alternate`,hreflang:`x-default`,href:t(o,n)})}if(a.addCanonical!==!1)if(i.strategy===`domains`&&i.domains?.length){let e=i.domains.find(e=>e.locale===n);if(e){let n=o.startsWith(`https`)?`https`:`http`;c.link.push({rel:`canonical`,hreflang:``,href:t(`${n}://${e.domain}`,r)})}}else{let a=e.r(r,n,i.locales,i.defaultLocale,i.strategy);c.link.push({rel:`canonical`,hreflang:``,href:t(o,a)})}c.meta.push({property:`og:locale`,content:s});for(let e of i.locales)if(e!==n){let t=i.localeProperties?.[e];c.meta.push({property:`og:locale:alternate`,content:t?.iso??e})}}return c}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return n}});
|
|
2
|
-
//# sourceMappingURL=locale-head-CwFSeJqY.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"locale-head-CwFSeJqY.cjs","names":[],"sources":["../src/runtime/locale-head.ts"],"sourcesContent":["import { switchLocalePath } from './path-utils'\nimport type { FluentNuxtRuntimeConfig } from '../types'\n\n/**\n * Safely construct an href from a base URL and path.\n * Guards against protocol injection and malformed URLs.\n */\nfunction buildSafeHref(baseUrl: string, path: string): string {\n if (!baseUrl) return path\n try {\n const url = new URL(path, baseUrl)\n if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n return path\n }\n return url.href\n } catch {\n return path\n }\n}\n\n/** Head metadata for locale SEO */\nexport interface LocaleHeadMeta {\n htmlAttrs: { lang: string; dir?: string }\n link: Array<{ rel: string; hreflang: string; href: string }>\n meta: Array<{ property: string; content: string }>\n}\n\nexport interface LocaleHeadOptions {\n /** Add hreflang and og:locale SEO attributes */\n addSeoAttributes?: boolean\n /** Base URL for absolute hreflang links (e.g. 'https://example.com') */\n baseUrl?: string\n /** Add a canonical link tag for the current page (default: true when addSeoAttributes is true) */\n addCanonical?: boolean\n}\n\n/**\n * Pure function that builds locale-aware HTML head metadata.\n *\n * This is the framework-agnostic core logic. For the Nuxt composable,\n * use `useLocaleHead()` from `composables.ts` instead.\n */\nexport function buildLocaleHead(\n locale: string,\n currentPath: string,\n config: FluentNuxtRuntimeConfig,\n options?: LocaleHeadOptions,\n): LocaleHeadMeta {\n const props = config.localeProperties?.[locale]\n const isoTag = props?.iso ?? locale\n\n const head: LocaleHeadMeta = {\n htmlAttrs: {\n lang: isoTag,\n ...(props?.dir ? { dir: props.dir } : {}),\n },\n link: [],\n meta: [],\n }\n\n if (options?.addSeoAttributes) {\n const baseUrl = options.baseUrl ?? ''\n\n // hreflang alternate links for each locale\n for (const loc of config.locales) {\n const locProps = config.localeProperties?.[loc]\n const locIso = locProps?.iso ?? loc\n\n if (config.strategy === 'domains' && config.domains?.length) {\n // For domain strategy, build absolute URLs using domain configs\n const domainEntry = config.domains.find((d) => d.locale === loc)\n if (domainEntry) {\n const protocol = baseUrl.startsWith('https') ? 'https' : 'http'\n head.link.push({\n rel: 'alternate',\n hreflang: locIso,\n href: buildSafeHref(`${protocol}://${domainEntry.domain}`, currentPath),\n })\n }\n } else {\n const path = switchLocalePath(\n currentPath,\n loc,\n config.locales,\n config.defaultLocale,\n config.strategy,\n )\n head.link.push({\n rel: 'alternate',\n hreflang: locIso,\n href: buildSafeHref(baseUrl, path),\n })\n }\n }\n\n // x-default hreflang\n if (config.strategy === 'domains' && config.domains?.length) {\n const defaultDomain = config.domains.find((d) => d.locale === config.defaultLocale)\n if (defaultDomain) {\n const protocol = baseUrl.startsWith('https') ? 'https' : 'http'\n head.link.push({\n rel: 'alternate',\n hreflang: 'x-default',\n href: buildSafeHref(`${protocol}://${defaultDomain.domain}`, currentPath),\n })\n }\n } else {\n const defaultPath = switchLocalePath(\n currentPath,\n config.defaultLocale,\n config.locales,\n config.defaultLocale,\n config.strategy,\n )\n head.link.push({\n rel: 'alternate',\n hreflang: 'x-default',\n href: buildSafeHref(baseUrl, defaultPath),\n })\n }\n\n // Canonical link tag (defaults to true when addSeoAttributes is enabled)\n if (options.addCanonical !== false) {\n if (config.strategy === 'domains' && config.domains?.length) {\n const domainEntry = config.domains.find((d) => d.locale === locale)\n if (domainEntry) {\n const protocol = baseUrl.startsWith('https') ? 'https' : 'http'\n head.link.push({\n rel: 'canonical',\n hreflang: '',\n href: buildSafeHref(`${protocol}://${domainEntry.domain}`, currentPath),\n })\n }\n } else {\n const canonicalPath = switchLocalePath(\n currentPath,\n locale,\n config.locales,\n config.defaultLocale,\n config.strategy,\n )\n head.link.push({\n rel: 'canonical',\n hreflang: '',\n href: buildSafeHref(baseUrl, canonicalPath),\n })\n }\n }\n\n // og:locale (use ISO tag if available)\n head.meta.push({ property: 'og:locale', content: isoTag })\n\n // og:locale:alternate for other locales\n for (const loc of config.locales) {\n if (loc !== locale) {\n const locProps = config.localeProperties?.[loc]\n head.meta.push({\n property: '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