@studiocms/ui
Version:
The UI library for StudioCMS. Includes the layouts & components we use to build StudioCMS.
86 lines (85 loc) • 3.79 kB
TypeScript
import type { AstroGlobal } from 'astro';
import { z } from 'astro/zod';
export declare const HeadConfigSchema: () => z.ZodDefault<z.ZodArray<z.ZodObject<{
tag: z.ZodEnum<{
base: "base";
link: "link";
meta: "meta";
noscript: "noscript";
script: "script";
style: "style";
template: "template";
title: "title";
}>;
attrs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodUndefined]>>>;
content: z.ZodDefault<z.ZodString>;
}, z.core.$strip>>>;
/**
* Default Head Tags for use with createHead() helper
*
* @param title
* @param description
* @param lang
* @param Astro
* @param favicon
* @param ogImage
* @param canonical
* @returns
*/
export declare const headDefaults: (title: string, description: string, Astro: AstroGlobal, ogImage: string | undefined, canonical: URL | undefined) => {
tag: "base" | "link" | "meta" | "noscript" | "script" | "style" | "template" | "title";
attrs?: Record<string, string | boolean | undefined> | undefined;
content?: string | undefined;
}[];
export declare const HeadSchema: z.ZodDefault<z.ZodArray<z.ZodObject<{
tag: z.ZodEnum<{
base: "base";
link: "link";
meta: "meta";
noscript: "noscript";
script: "script";
style: "style";
template: "template";
title: "title";
}>;
attrs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodUndefined]>>>;
content: z.ZodDefault<z.ZodString>;
}, z.core.$strip>>>;
export type HeadUserConfig = z.input<ReturnType<typeof HeadConfigSchema>>;
export type HeadConfig = z.output<ReturnType<typeof HeadConfigSchema>>;
/**
* Test if a head config object contains a matching `<title>` or `<meta>` tag.
*
* For example, will return true if `head` already contains
* `<meta name="description" content="A">` and the passed `tag`
* is `<meta name="description" content="B">`. Tests against `name`,
* `property`, and `http-equiv` attributes for `<meta>` tags.
*/
export declare function hasTag(head: HeadConfig, entry: HeadConfig[number]): boolean;
/**
* Test if a head config object contains a tag of the same type
* as `entry` and a matching attribute for one of the passed `keys`.
*/
export declare function hasOneOf(head: HeadConfig, entry: HeadConfig[number], keys: string[]): boolean;
/** Find the first matching key–value pair in a head entry’s attributes. */
export declare function getAttr(keys: string[], entry: HeadConfig[number]): [key: string, value: string | boolean] | undefined;
/** Merge two heads, overwriting entries in the first head that exist in the second. */
export declare function mergeHead(oldHead: HeadConfig, newHead: HeadConfig): {
tag: "base" | "link" | "meta" | "noscript" | "script" | "style" | "template" | "title";
attrs: Record<string, string | boolean | undefined>;
content: string;
}[];
/** Sort head tags to place important tags first and relegate “SEO” meta tags. */
export declare function sortHead(head: HeadConfig): {
tag: "base" | "link" | "meta" | "noscript" | "script" | "style" | "template" | "title";
attrs: Record<string, string | boolean | undefined>;
content: string;
}[];
/** Get the relative importance of a specific head tag. */
export declare function getImportance(entry: HeadConfig[number]): 80 | 0 | 100 | 90 | 70;
/** Create a fully parsed, merged, and sorted head entry array from multiple sources. */
export declare function createHead(defaultHeaders: HeadUserConfig, ...heads: HeadConfig[]): {
tag: "base" | "link" | "meta" | "noscript" | "script" | "style" | "template" | "title";
attrs: Record<string, string | boolean | undefined>;
content: string;
}[];