index.ts — astro Source File
Architecture documentation for index.ts, a typescript file in the astro codebase. 10 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR e4a1ef92_c598_36b5_dc33_9ab2535360bc["index.ts"] e9dfb380_680c_13fb_c9d4_a88e777254bd["../core/app/common.js"] e4a1ef92_c598_36b5_dc33_9ab2535360bc --> e9dfb380_680c_13fb_c9d4_a88e777254bd a4f2698c_5256_262a_ba7c_f72b51878d10["../core/app/types.js"] e4a1ef92_c598_36b5_dc33_9ab2535360bc --> a4f2698c_5256_262a_ba7c_f72b51878d10 c396bb1c_7eee_221a_d665_5744d13dc23f["../core/build/util.js"] e4a1ef92_c598_36b5_dc33_9ab2535360bc --> c396bb1c_7eee_221a_d665_5744d13dc23f 7216d952_4e4a_2d18_a85b_74b4ace79e2b["../core/constants.js"] e4a1ef92_c598_36b5_dc33_9ab2535360bc --> 7216d952_4e4a_2d18_a85b_74b4ace79e2b 8df634da_0f30_1e1f_1314_2439b0c9baab["../core/errors/errors-data.js"] e4a1ef92_c598_36b5_dc33_9ab2535360bc --> 8df634da_0f30_1e1f_1314_2439b0c9baab ef8a1e3f_e350_75a6_b92d_62a8566d8db9["../core/errors/index.js"] e4a1ef92_c598_36b5_dc33_9ab2535360bc --> ef8a1e3f_e350_75a6_b92d_62a8566d8db9 c32d12e2_d85e_28c0_eea7_9b29629857e0["../types/public/config.js"] e4a1ef92_c598_36b5_dc33_9ab2535360bc --> c32d12e2_d85e_28c0_eea7_9b29629857e0 28857b9f_4720_3f29_4abb_a7eec34dcca5["../types/public/context.js"] e4a1ef92_c598_36b5_dc33_9ab2535360bc --> 28857b9f_4720_3f29_4abb_a7eec34dcca5 db6f0aaa_f5a4_2555_3d84_fea3866e7a67["./middleware.js"] e4a1ef92_c598_36b5_dc33_9ab2535360bc --> db6f0aaa_f5a4_2555_3d84_fea3866e7a67 e4df8f29_fb2f_3d70_a962_fdf6a3670b22["path"] e4a1ef92_c598_36b5_dc33_9ab2535360bc --> e4df8f29_fb2f_3d70_a962_fdf6a3670b22 style e4a1ef92_c598_36b5_dc33_9ab2535360bc fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { appendForwardSlash, joinPaths } from '@astrojs/internal-helpers/path';
import type { RoutingStrategies } from '../core/app/common.js';
import type { SSRManifest } from '../core/app/types.js';
import { shouldAppendForwardSlash } from '../core/build/util.js';
import { REROUTE_DIRECTIVE_HEADER } from '../core/constants.js';
import { i18nNoLocaleFoundInPath, MissingLocale } from '../core/errors/errors-data.js';
import { AstroError } from '../core/errors/index.js';
import type { AstroConfig, Locales, ValidRedirectStatus } from '../types/public/config.js';
import type { APIContext } from '../types/public/context.js';
import { createI18nMiddleware } from './middleware.js';
export function requestHasLocale(locales: Locales) {
return function (context: APIContext): boolean {
return pathHasLocale(context.url.pathname, locales);
};
}
// Checks if the pathname has any locale
export function pathHasLocale(path: string, locales: Locales): boolean {
// pages that use a locale param ([locale].astro or [locale]/index.astro)
// and getStaticPaths make [locale].html the pathname during SSG
// which will not match a configured locale without removing .html
// as we do in normalizeThePath
const segments = path.split('/').map(normalizeThePath);
for (const segment of segments) {
for (const locale of locales) {
if (typeof locale === 'string') {
if (normalizeTheLocale(segment) === normalizeTheLocale(locale)) {
return true;
}
} else if (segment === locale.path) {
return true;
}
}
}
return false;
}
type GetLocaleRelativeUrl = GetLocaleOptions & {
locale: string;
base: string;
locales: Locales;
trailingSlash: AstroConfig['trailingSlash'];
format: NonNullable<AstroConfig['build']['format']>;
strategy?: RoutingStrategies;
defaultLocale: string;
domains: Record<string, string> | undefined;
path?: string;
};
export type GetLocaleOptions = {
/**
* Makes the locale URL-friendly by replacing underscores with dashes, and converting the locale to lower case.
* @default true
*/
normalizeLocale?: boolean;
/**
* An optional path to prepend to `locale`.
*/
// ... (369 more lines)
Domain
Subdomains
Functions
- context()
- createMiddleware()
- getAllCodes()
- getLocaleAbsoluteUrl()
- getLocaleAbsoluteUrlList()
- getLocaleByPath()
- getLocaleRelativeUrl()
- getLocaleRelativeUrlList()
- getPathByLocale()
- normalizeTheLocale()
- normalizeThePath()
- notFound()
- pathHasLocale()
- peekCodePathToUse()
- redirectToDefaultLocale()
- redirectToFallback()
- requestHasLocale()
- toCodes()
- toPaths()
Types
Dependencies
- ../core/app/common.js
- ../core/app/types.js
- ../core/build/util.js
- ../core/constants.js
- ../core/errors/errors-data.js
- ../core/errors/index.js
- ../types/public/config.js
- ../types/public/context.js
- ./middleware.js
- path
Source
Frequently Asked Questions
What does index.ts do?
index.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in index.ts?
index.ts defines 19 function(s): context, createMiddleware, getAllCodes, getLocaleAbsoluteUrl, getLocaleAbsoluteUrlList, getLocaleByPath, getLocaleRelativeUrl, getLocaleRelativeUrlList, getPathByLocale, normalizeTheLocale, and 9 more.
What does index.ts depend on?
index.ts imports 10 module(s): ../core/app/common.js, ../core/app/types.js, ../core/build/util.js, ../core/constants.js, ../core/errors/errors-data.js, ../core/errors/index.js, ../types/public/config.js, ../types/public/context.js, and 2 more.
Where is index.ts in the architecture?
index.ts is located at packages/astro/src/i18n/index.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/i18n).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free