full site update
This commit is contained in:
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
|
||||
};
|
||||
|
Reference in New Issue
Block a user