astro-ghostcms/.pnpm-store/v3/files/b6/79e54901a6ba17966f141b9f32a...

53 lines
2.1 KiB
Plaintext
Raw Normal View History

2024-02-14 14:10:47 +00:00
import type { ComponentInstance, Locales, Params, Props, RouteData, SSRElement, SSRResult } from '../../@types/astro.js';
import type { Environment } from './environment.js';
import type { RoutingStrategies } from '../config/schema.js';
/**
* The RenderContext represents the parts of rendering that are specific to one request.
*/
export interface RenderContext {
request: Request;
pathname: string;
scripts?: Set<SSRElement>;
links?: Set<SSRElement>;
styles?: Set<SSRElement>;
componentMetadata?: SSRResult['componentMetadata'];
route: RouteData;
status?: number;
params: Params;
props: Props;
locals?: object;
locales: Locales | undefined;
defaultLocale: string | undefined;
routing: RoutingStrategies | undefined;
}
export type CreateRenderContextArgs = Partial<Omit<RenderContext, 'params' | 'props' | 'locals'>> & {
route: RouteData;
request: RenderContext['request'];
mod: ComponentInstance | undefined;
env: Environment;
};
export declare function createRenderContext(options: CreateRenderContextArgs): Promise<RenderContext>;
type BrowserLocale = {
locale: string;
qualityValue: number | undefined;
};
/**
* Parses the value of the `Accept-Header` language:
*
* More info: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language
*
* Complex example: `fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5`
*
*/
export declare function parseLocale(header: string): BrowserLocale[];
/**
* Set the current locale by parsing the value passed from the `Accept-Header`.
*
* If multiple locales are present in the header, they are sorted by their quality value and the highest is selected as current locale.
*
*/
export declare function computePreferredLocale(request: Request, locales: Locales): string | undefined;
export declare function computePreferredLocaleList(request: Request, locales: Locales): string[];
export declare function computeCurrentLocale(request: Request, locales: Locales, routingStrategy: RoutingStrategies | undefined, defaultLocale: string | undefined): undefined | string;
export {};