full site update
This commit is contained in:
10
node_modules/astro/dist/i18n/index.d.ts
generated
vendored
10
node_modules/astro/dist/i18n/index.d.ts
generated
vendored
@@ -1,7 +1,8 @@
|
||||
import type { APIContext, AstroConfig, Locales, SSRManifest, ValidRedirectStatus } from '../@types/astro.js';
|
||||
import type { SSRManifest } from '../core/app/types.js';
|
||||
import type { AstroConfig, Locales, ValidRedirectStatus } from '../types/public/config.js';
|
||||
import type { APIContext } from '../types/public/context.js';
|
||||
import type { RoutingStrategies } from './utils.js';
|
||||
export declare function requestHasLocale(locales: Locales): (context: APIContext) => boolean;
|
||||
export declare function requestIs404Or500(request: Request, base?: string): boolean;
|
||||
export declare function pathHasLocale(path: string, locales: Locales): boolean;
|
||||
type GetLocaleRelativeUrl = GetLocaleOptions & {
|
||||
locale: string;
|
||||
@@ -77,6 +78,7 @@ export declare function normalizeTheLocale(locale: string): string;
|
||||
* Returns an array of only locales, by picking the `code`
|
||||
* @param locales
|
||||
*/
|
||||
export declare function getAllCodes(locales: Locales): string[];
|
||||
export declare function toCodes(locales: Locales): string[];
|
||||
/**
|
||||
* It returns the array of paths
|
||||
@@ -95,8 +97,8 @@ export type MiddlewarePayload = {
|
||||
fallbackType: 'redirect' | 'rewrite';
|
||||
};
|
||||
export declare function redirectToDefaultLocale({ trailingSlash, format, base, defaultLocale, }: MiddlewarePayload): (context: APIContext, statusCode?: ValidRedirectStatus) => Response;
|
||||
export declare function notFound({ base, locales }: MiddlewarePayload): (context: APIContext, response?: Response) => Response | undefined;
|
||||
export declare function notFound({ base, locales, fallback }: MiddlewarePayload): (context: APIContext, response?: Response) => Response | undefined;
|
||||
export type RedirectToFallback = (context: APIContext, response: Response) => Promise<Response>;
|
||||
export declare function redirectToFallback({ fallback, locales, defaultLocale, strategy, base, fallbackType, }: MiddlewarePayload): (context: APIContext, response: Response) => Promise<Response>;
|
||||
export declare function createMiddleware(i18nManifest: SSRManifest['i18n'], base: SSRManifest['base'], trailingSlash: SSRManifest['trailingSlash'], format: SSRManifest['buildFormat']): import("../@types/astro.js").MiddlewareHandler;
|
||||
export declare function createMiddleware(i18nManifest: SSRManifest['i18n'], base: SSRManifest['base'], trailingSlash: SSRManifest['trailingSlash'], format: SSRManifest['buildFormat']): import("../types/public/common.js").MiddlewareHandler;
|
||||
export {};
|
||||
|
42
node_modules/astro/dist/i18n/index.js
generated
vendored
42
node_modules/astro/dist/i18n/index.js
generated
vendored
@@ -1,7 +1,7 @@
|
||||
import { appendForwardSlash, joinPaths } from "@astrojs/internal-helpers/path";
|
||||
import { shouldAppendForwardSlash } from "../core/build/util.js";
|
||||
import { REROUTE_DIRECTIVE_HEADER } from "../core/constants.js";
|
||||
import { MissingLocale, i18nNoLocaleFoundInPath } from "../core/errors/errors-data.js";
|
||||
import { i18nNoLocaleFoundInPath, MissingLocale } from "../core/errors/errors-data.js";
|
||||
import { AstroError } from "../core/errors/index.js";
|
||||
import { createI18nMiddleware } from "./middleware.js";
|
||||
function requestHasLocale(locales) {
|
||||
@@ -9,10 +9,6 @@ function requestHasLocale(locales) {
|
||||
return pathHasLocale(context.url.pathname, locales);
|
||||
};
|
||||
}
|
||||
function requestIs404Or500(request, base = "") {
|
||||
const url = new URL(request.url);
|
||||
return url.pathname.startsWith(`${base}/404`) || url.pathname.startsWith(`${base}/500`);
|
||||
}
|
||||
function pathHasLocale(path, locales) {
|
||||
const segments = path.split("/");
|
||||
for (const segment of segments) {
|
||||
@@ -55,11 +51,16 @@ function getLocaleRelativeUrl({
|
||||
pathsToJoin.push(normalizedLocale);
|
||||
}
|
||||
pathsToJoin.push(path);
|
||||
let relativePath;
|
||||
if (shouldAppendForwardSlash(trailingSlash, format)) {
|
||||
return appendForwardSlash(joinPaths(...pathsToJoin));
|
||||
relativePath = appendForwardSlash(joinPaths(...pathsToJoin));
|
||||
} else {
|
||||
return joinPaths(...pathsToJoin);
|
||||
relativePath = joinPaths(...pathsToJoin);
|
||||
}
|
||||
if (relativePath === "") {
|
||||
return "/";
|
||||
}
|
||||
return relativePath;
|
||||
}
|
||||
function getLocaleAbsoluteUrl({ site, isBuild, ...rest }) {
|
||||
const localeUrl = getLocaleRelativeUrl(rest);
|
||||
@@ -69,7 +70,9 @@ function getLocaleAbsoluteUrl({ site, isBuild, ...rest }) {
|
||||
const base = domains[locale];
|
||||
url = joinPaths(base, localeUrl.replace(`/${rest.locale}`, ""));
|
||||
} else {
|
||||
if (site) {
|
||||
if (localeUrl === "/") {
|
||||
url = site || "/";
|
||||
} else if (site) {
|
||||
url = joinPaths(site, localeUrl);
|
||||
} else {
|
||||
url = localeUrl;
|
||||
@@ -129,6 +132,17 @@ function getLocaleByPath(path, locales) {
|
||||
function normalizeTheLocale(locale) {
|
||||
return locale.replaceAll("_", "-").toLowerCase();
|
||||
}
|
||||
function getAllCodes(locales) {
|
||||
const result = [];
|
||||
for (const loopLocale of locales) {
|
||||
if (typeof loopLocale === "string") {
|
||||
result.push(loopLocale);
|
||||
} else {
|
||||
result.push(...loopLocale.codes);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function toCodes(locales) {
|
||||
return locales.map((loopLocale) => {
|
||||
if (typeof loopLocale === "string") {
|
||||
@@ -177,9 +191,11 @@ function redirectToDefaultLocale({
|
||||
}
|
||||
};
|
||||
}
|
||||
function notFound({ base, locales }) {
|
||||
function notFound({ base, locales, fallback }) {
|
||||
return function(context, response) {
|
||||
if (response?.headers.get(REROUTE_DIRECTIVE_HEADER) === "no") return response;
|
||||
if (response?.headers.get(REROUTE_DIRECTIVE_HEADER) === "no" && typeof fallback === "undefined") {
|
||||
return response;
|
||||
}
|
||||
const url = context.url;
|
||||
const isRoot = url.pathname === base + "/" || url.pathname === base;
|
||||
if (!(isRoot || pathHasLocale(url.pathname, locales))) {
|
||||
@@ -239,9 +255,9 @@ function redirectToFallback({
|
||||
newPathname = context.url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`);
|
||||
}
|
||||
if (fallbackType === "rewrite") {
|
||||
return await context.rewrite(newPathname);
|
||||
return await context.rewrite(newPathname + context.url.search);
|
||||
} else {
|
||||
return context.redirect(newPathname);
|
||||
return context.redirect(newPathname + context.url.search);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -253,6 +269,7 @@ function createMiddleware(i18nManifest, base, trailingSlash, format) {
|
||||
}
|
||||
export {
|
||||
createMiddleware,
|
||||
getAllCodes,
|
||||
getLocaleAbsoluteUrl,
|
||||
getLocaleAbsoluteUrlList,
|
||||
getLocaleByPath,
|
||||
@@ -265,7 +282,6 @@ export {
|
||||
redirectToDefaultLocale,
|
||||
redirectToFallback,
|
||||
requestHasLocale,
|
||||
requestIs404Or500,
|
||||
toCodes,
|
||||
toPaths
|
||||
};
|
||||
|
3
node_modules/astro/dist/i18n/middleware.d.ts
generated
vendored
3
node_modules/astro/dist/i18n/middleware.d.ts
generated
vendored
@@ -1,2 +1,3 @@
|
||||
import type { MiddlewareHandler, SSRManifest } from '../@types/astro.js';
|
||||
import type { SSRManifest } from '../core/app/types.js';
|
||||
import type { MiddlewareHandler } from '../types/public/common.js';
|
||||
export declare function createI18nMiddleware(i18n: SSRManifest['i18n'], base: SSRManifest['base'], trailingSlash: SSRManifest['trailingSlash'], format: SSRManifest['buildFormat']): MiddlewareHandler;
|
||||
|
16
node_modules/astro/dist/i18n/middleware.js
generated
vendored
16
node_modules/astro/dist/i18n/middleware.js
generated
vendored
@@ -1,11 +1,11 @@
|
||||
import { REROUTE_DIRECTIVE_HEADER, ROUTE_TYPE_HEADER } from "../core/constants.js";
|
||||
import { isRequestServerIsland, requestIs404Or500 } from "../core/routing/match.js";
|
||||
import {
|
||||
normalizeTheLocale,
|
||||
notFound,
|
||||
redirectToDefaultLocale,
|
||||
redirectToFallback,
|
||||
requestHasLocale,
|
||||
requestIs404Or500
|
||||
requestHasLocale
|
||||
} from "./index.js";
|
||||
function createI18nMiddleware(i18n, base, trailingSlash, format) {
|
||||
if (!i18n) return (_, next) => next();
|
||||
@@ -20,12 +20,12 @@ function createI18nMiddleware(i18n, base, trailingSlash, format) {
|
||||
const _noFoundForNonLocaleRoute = notFound(payload);
|
||||
const _requestHasLocale = requestHasLocale(payload.locales);
|
||||
const _redirectToFallback = redirectToFallback(payload);
|
||||
const prefixAlways = (context) => {
|
||||
const prefixAlways = (context, response) => {
|
||||
const url = context.url;
|
||||
if (url.pathname === base + "/" || url.pathname === base) {
|
||||
return _redirectToDefaultLocale(context);
|
||||
} else if (!_requestHasLocale(context)) {
|
||||
return _noFoundForNonLocaleRoute(context);
|
||||
return _noFoundForNonLocaleRoute(context, response);
|
||||
}
|
||||
return void 0;
|
||||
};
|
||||
@@ -58,8 +58,12 @@ function createI18nMiddleware(i18n, base, trailingSlash, format) {
|
||||
if (requestIs404Or500(context.request, base)) {
|
||||
return response;
|
||||
}
|
||||
if (isRequestServerIsland(context.request, base)) {
|
||||
return response;
|
||||
}
|
||||
const { currentLocale } = context;
|
||||
switch (i18n.strategy) {
|
||||
// NOTE: theoretically, we should never hit this code path
|
||||
case "manual": {
|
||||
return response;
|
||||
}
|
||||
@@ -96,7 +100,7 @@ function createI18nMiddleware(i18n, base, trailingSlash, format) {
|
||||
break;
|
||||
}
|
||||
case "pathname-prefix-always": {
|
||||
const result = prefixAlways(context);
|
||||
const result = prefixAlways(context, response);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
@@ -104,7 +108,7 @@ function createI18nMiddleware(i18n, base, trailingSlash, format) {
|
||||
}
|
||||
case "domains-prefix-always": {
|
||||
if (localeHasntDomain(i18n, currentLocale)) {
|
||||
const result = prefixAlways(context);
|
||||
const result = prefixAlways(context, response);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
4
node_modules/astro/dist/i18n/utils.d.ts
generated
vendored
4
node_modules/astro/dist/i18n/utils.d.ts
generated
vendored
@@ -1,4 +1,5 @@
|
||||
import type { AstroConfig, Locales } from '../@types/astro.js';
|
||||
import type { SSRManifest } from '../core/app/types.js';
|
||||
import type { AstroConfig, Locales } from '../types/public/config.js';
|
||||
type BrowserLocale = {
|
||||
locale: string;
|
||||
qualityValue: number | undefined;
|
||||
@@ -23,5 +24,6 @@ export declare function computePreferredLocaleList(request: Request, locales: Lo
|
||||
export declare function computeCurrentLocale(pathname: string, locales: Locales, defaultLocale: string): string | undefined;
|
||||
export type RoutingStrategies = 'manual' | 'pathname-prefix-always' | 'pathname-prefix-other-locales' | 'pathname-prefix-always-no-redirect' | 'domains-prefix-always' | 'domains-prefix-other-locales' | 'domains-prefix-always-no-redirect';
|
||||
export declare function toRoutingStrategy(routing: NonNullable<AstroConfig['i18n']>['routing'], domains: NonNullable<AstroConfig['i18n']>['domains']): RoutingStrategies;
|
||||
export declare function fromRoutingStrategy(strategy: RoutingStrategies, fallbackType: NonNullable<SSRManifest['i18n']>['fallbackType']): NonNullable<AstroConfig['i18n']>['routing'];
|
||||
export declare function toFallbackType(routing: NonNullable<AstroConfig['i18n']>['routing']): 'redirect' | 'rewrite';
|
||||
export {};
|
||||
|
42
node_modules/astro/dist/i18n/utils.js
generated
vendored
42
node_modules/astro/dist/i18n/utils.js
generated
vendored
@@ -1,4 +1,4 @@
|
||||
import { normalizeTheLocale, toCodes } from "./index.js";
|
||||
import { getAllCodes, normalizeTheLocale } from "./index.js";
|
||||
function parseLocale(header) {
|
||||
if (header === "*") {
|
||||
return [{ locale: header, qualityValue: void 0 }];
|
||||
@@ -35,7 +35,7 @@ function parseLocale(header) {
|
||||
return result;
|
||||
}
|
||||
function sortAndFilterLocales(browserLocaleList, locales) {
|
||||
const normalizedLocales = toCodes(locales).map(normalizeTheLocale);
|
||||
const normalizedLocales = getAllCodes(locales).map(normalizeTheLocale);
|
||||
return browserLocaleList.filter((browserLocale) => {
|
||||
if (browserLocale.locale !== "*") {
|
||||
return normalizedLocales.includes(normalizeTheLocale(browserLocale.locale));
|
||||
@@ -59,11 +59,13 @@ function computePreferredLocale(request, locales) {
|
||||
if (typeof currentLocale === "string") {
|
||||
if (normalizeTheLocale(currentLocale) === normalizeTheLocale(firstResult.locale)) {
|
||||
result = currentLocale;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
for (const currentCode of currentLocale.codes) {
|
||||
if (normalizeTheLocale(currentCode) === normalizeTheLocale(firstResult.locale)) {
|
||||
result = currentLocale.path;
|
||||
result = currentCode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,13 +80,7 @@ function computePreferredLocaleList(request, locales) {
|
||||
if (acceptHeader) {
|
||||
const browserLocaleList = sortAndFilterLocales(parseLocale(acceptHeader), locales);
|
||||
if (browserLocaleList.length === 1 && browserLocaleList.at(0).locale === "*") {
|
||||
return locales.map((locale) => {
|
||||
if (typeof locale === "string") {
|
||||
return locale;
|
||||
} else {
|
||||
return locale.codes.at(0);
|
||||
}
|
||||
});
|
||||
return getAllCodes(locales);
|
||||
} else if (browserLocaleList.length > 0) {
|
||||
for (const browserLocale of browserLocaleList) {
|
||||
for (const loopLocale of locales) {
|
||||
@@ -95,7 +91,7 @@ function computePreferredLocaleList(request, locales) {
|
||||
} else {
|
||||
for (const code of loopLocale.codes) {
|
||||
if (code === browserLocale.locale) {
|
||||
result.push(loopLocale.path);
|
||||
result.push(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,6 +164,29 @@ function toRoutingStrategy(routing, domains) {
|
||||
}
|
||||
return strategy;
|
||||
}
|
||||
const PREFIX_DEFAULT_LOCALE = /* @__PURE__ */ new Set([
|
||||
"pathname-prefix-always",
|
||||
"domains-prefix-always",
|
||||
"pathname-prefix-always-no-redirect",
|
||||
"domains-prefix-always-no-redirect"
|
||||
]);
|
||||
const REDIRECT_TO_DEFAULT_LOCALE = /* @__PURE__ */ new Set([
|
||||
"pathname-prefix-always-no-redirect",
|
||||
"domains-prefix-always-no-redirect"
|
||||
]);
|
||||
function fromRoutingStrategy(strategy, fallbackType) {
|
||||
let routing;
|
||||
if (strategy === "manual") {
|
||||
routing = "manual";
|
||||
} else {
|
||||
routing = {
|
||||
prefixDefaultLocale: PREFIX_DEFAULT_LOCALE.has(strategy),
|
||||
redirectToDefaultLocale: !REDIRECT_TO_DEFAULT_LOCALE.has(strategy),
|
||||
fallbackType
|
||||
};
|
||||
}
|
||||
return routing;
|
||||
}
|
||||
function toFallbackType(routing) {
|
||||
if (routing === "manual") {
|
||||
return "rewrite";
|
||||
@@ -178,6 +197,7 @@ export {
|
||||
computeCurrentLocale,
|
||||
computePreferredLocale,
|
||||
computePreferredLocaleList,
|
||||
fromRoutingStrategy,
|
||||
parseLocale,
|
||||
toFallbackType,
|
||||
toRoutingStrategy
|
||||
|
3
node_modules/astro/dist/i18n/vite-plugin-i18n.d.ts
generated
vendored
3
node_modules/astro/dist/i18n/vite-plugin-i18n.d.ts
generated
vendored
@@ -1,5 +1,6 @@
|
||||
import type * as vite from 'vite';
|
||||
import type { AstroConfig, AstroSettings } from '../@types/astro.js';
|
||||
import type { AstroSettings } from '../types/astro.js';
|
||||
import type { AstroConfig } from '../types/public/config.js';
|
||||
type AstroInternationalization = {
|
||||
settings: AstroSettings;
|
||||
};
|
||||
|
Reference in New Issue
Block a user