Home / Function/ getEntryData() — astro Function Reference

getEntryData() — astro Function Reference

Architecture documentation for the getEntryData() function in utils.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  491817d6_81a3_cf47_fbd9_bfd8550b7529["getEntryData()"]
  7a09e708_c090_71c0_8138_7343699b1865["utils.ts"]
  491817d6_81a3_cf47_fbd9_bfd8550b7529 -->|defined in| 7a09e708_c090_71c0_8138_7343699b1865
  a0205099_ee90_216f_374a_b6b4ab0e709c["getYAMLErrorLine()"]
  491817d6_81a3_cf47_fbd9_bfd8550b7529 -->|calls| a0205099_ee90_216f_374a_b6b4ab0e709c
  style 491817d6_81a3_cf47_fbd9_bfd8550b7529 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/content/utils.ts lines 154–245

export async function getEntryData<
	TInputData extends Record<string, unknown> = Record<string, unknown>,
	TOutputData extends TInputData = TInputData,
>(
	entry: {
		id: string;
		collection: string;
		unvalidatedData: TInputData;
		_internal: EntryInternal;
	},
	collectionConfig: CollectionConfig,
	shouldEmitFile: boolean,
	pluginContext?: PluginContext,
): Promise<TOutputData> {
	let data = entry.unvalidatedData as TOutputData;

	let schema = collectionConfig.schema;

	if (typeof schema === 'function') {
		if (pluginContext) {
			schema = schema({
				image: createImage(pluginContext, shouldEmitFile, entry._internal.filePath),
			});
		} else if (collectionConfig.type === CONTENT_LAYER_TYPE) {
			schema = schema({
				image: () =>
					z.string().transform((val) => {
						// Normalize bare filenames to relative paths for consistent resolution
						// This ensures bare filenames like "cover.jpg" work the same way as in markdown frontmatter
						let normalizedPath = val;

						// Skip normalization for URLs, absolute paths, and already-relative paths
						const isUrl = val.includes('://');
						const isAbsolute = val.startsWith('/');
						const isRelative = val.startsWith('.');

						if (val && !isUrl && !isAbsolute && !isRelative) {
							// Check if this is a local file or an alias
							// Resolve relative to the entry's directory
							const entryDir = path.dirname(entry._internal.filePath);
							const resolvedPath = path.resolve(entryDir, val);

							// If the file exists, normalize to relative path
							// Otherwise keep as-is (likely a Vite alias)
							if (fsMod.existsSync(resolvedPath)) {
								normalizedPath = `./${val}`;
							}
						}
						return `${IMAGE_IMPORT_PREFIX}${normalizedPath}`;
					}),
			});
		}
	}

	if (schema) {
		// Use `safeParseAsync` to allow async transforms
		let formattedError;
		const parsed = await (schema as z.ZodSchema).safeParseAsync(data, {
			error(issue) {
				if (issue.code === 'custom' && issue.params?.isHoistedAstroError) {
					formattedError = issue.params?.astroError;
				}
				return errorMap(issue);
			},
		});
		if (parsed.success) {
			data = parsed.data as TOutputData;
		} else {
			if (!formattedError) {
				formattedError = new AstroError({
					...AstroErrorData.InvalidContentEntryDataError,
					message: AstroErrorData.InvalidContentEntryDataError.message(
						entry.collection,
						entry.id,
						parsed.error,
					),
					location: {
						file: entry._internal?.filePath,
						line: getYAMLErrorLine(
							entry._internal?.rawData,
							String(parsed.error.issues[0].path[0]),

Subdomains

Frequently Asked Questions

What does getEntryData() do?
getEntryData() is a function in the astro codebase, defined in packages/astro/src/content/utils.ts.
Where is getEntryData() defined?
getEntryData() is defined in packages/astro/src/content/utils.ts at line 154.
What does getEntryData() call?
getEntryData() calls 1 function(s): getYAMLErrorLine.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free