Home / Function/ resolvePartials() — astro Function Reference

resolvePartials() — astro Function Reference

Architecture documentation for the resolvePartials() function in content-entry-type.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  5b158f1a_da81_b230_bb87_31167f3836a8["resolvePartials()"]
  b46411b3_6535_0116_92ac_cd60b744df11["content-entry-type.ts"]
  5b158f1a_da81_b230_bb87_31167f3836a8 -->|defined in| b46411b3_6535_0116_92ac_cd60b744df11
  8da81c7c_4056_9a1c_b1a1_0ac3cbab6581["getContentEntryType()"]
  8da81c7c_4056_9a1c_b1a1_0ac3cbab6581 -->|calls| 5b158f1a_da81_b230_bb87_31167f3836a8
  style 5b158f1a_da81_b230_bb87_31167f3836a8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/integrations/markdoc/src/content-entry-type.ts lines 153–230

async function resolvePartials({
	ast,
	fileUrl,
	root,
	tokenizer,
	allowHTML,
	markdocConfig,
	pluginContext,
	raisePartialValidationErrors,
}: {
	ast: Node;
	fileUrl: URL;
	root: URL;
	tokenizer: any;
	allowHTML?: boolean;
	markdocConfig: MarkdocConfig;
	pluginContext: Rollup.PluginContext;
	raisePartialValidationErrors: (ast: Node, filePath: string) => void;
}) {
	const relativePartialPath = path.relative(fileURLToPath(root), fileURLToPath(fileUrl));
	for (const node of ast.walk()) {
		if (node.type === 'tag' && node.tag === 'partial') {
			const { file } = node.attributes;
			if (!file) {
				throw new MarkdocError({
					// Should be caught by Markdoc validation step.
					message: `(Uncaught error) Partial tag requires a 'file' attribute`,
				});
			}

			if (markdocConfig.partials?.[file]) continue;

			let partialPath: string;
			let partialContents: string;
			try {
				const resolved = await pluginContext.resolve(file, fileURLToPath(fileUrl));
				let partialId = resolved?.id;
				if (!partialId) {
					const attemptResolveAsRelative = await pluginContext.resolve(
						'./' + file,
						fileURLToPath(fileUrl),
					);
					if (!attemptResolveAsRelative?.id) throw new Error();
					partialId = attemptResolveAsRelative.id;
				}

				partialPath = fileURLToPath(new URL(prependForwardSlash(partialId), 'file://'));
				partialContents = await fs.promises.readFile(partialPath, 'utf-8');
			} catch {
				throw new MarkdocError({
					message: [
						`**${String(relativePartialPath)}** contains invalid content:`,
						`Could not read partial file \`${file}\`. Does the file exist?`,
					].join('\n'),
				});
			}
			if (pluginContext.meta.watchMode) pluginContext.addWatchFile(partialPath);
			let partialTokens = tokenizer.tokenize(partialContents);
			if (allowHTML) {
				partialTokens = htmlTokenTransform(tokenizer, partialTokens);
			}
			const partialAst = Markdoc.parse(partialTokens);
			raisePartialValidationErrors(partialAst, partialPath);
			await resolvePartials({
				ast: partialAst,
				root,
				fileUrl: pathToFileURL(partialPath),
				tokenizer,
				allowHTML,
				markdocConfig,
				pluginContext,
				raisePartialValidationErrors,
			});

			Object.assign(node, partialAst);
		}
	}
}

Domain

Subdomains

Frequently Asked Questions

What does resolvePartials() do?
resolvePartials() is a function in the astro codebase, defined in packages/integrations/markdoc/src/content-entry-type.ts.
Where is resolvePartials() defined?
resolvePartials() is defined in packages/integrations/markdoc/src/content-entry-type.ts at line 153.
What calls resolvePartials()?
resolvePartials() is called by 1 function(s): getContentEntryType.

Analyze Your Own Codebase

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

Try Supermodel Free