Home / Function/ getFrontmatterLanguagePlugin() — astro Function Reference

getFrontmatterLanguagePlugin() — astro Function Reference

Architecture documentation for the getFrontmatterLanguagePlugin() function in frontmatter.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  53e0489f_e9f0_ae9d_f78e_76a17d617bb1["getFrontmatterLanguagePlugin()"]
  ea4d1e16_3d0b_5a14_84c7_af64d3dde1b2["frontmatter.ts"]
  53e0489f_e9f0_ae9d_f78e_76a17d617bb1 -->|defined in| ea4d1e16_3d0b_5a14_84c7_af64d3dde1b2
  d3244c07_27fb_9495_9c79_ebc5653dbf66["getCollectionName()"]
  53e0489f_e9f0_ae9d_f78e_76a17d617bb1 -->|calls| d3244c07_27fb_9495_9c79_ebc5653dbf66
  style 53e0489f_e9f0_ae9d_f78e_76a17d617bb1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/language-tools/ts-plugin/src/frontmatter.ts lines 36–84

export function getFrontmatterLanguagePlugin(
	collectionConfig: CollectionConfig[],
): LanguagePlugin<string, FrontmatterHolder> {
	return {
		getLanguageId(scriptId) {
			const fileType = SUPPORTED_FRONTMATTER_EXTENSIONS_KEYS.find((ext) =>
				scriptId.endsWith(`.${ext}`),
			);

			if (fileType) {
				return SUPPORTED_FRONTMATTER_EXTENSIONS[
					fileType as keyof typeof SUPPORTED_FRONTMATTER_EXTENSIONS
				];
			}
		},
		createVirtualCode(scriptId, languageId, snapshot) {
			if (SUPPORTED_FRONTMATTER_EXTENSIONS_VALUES.includes(languageId)) {
				const fileName = scriptId.replace(/\\/g, '/');
				return new FrontmatterHolder(
					fileName,
					languageId,
					snapshot,
					// In TypeScript plugins, unlike in the language server, the scriptId is just a string file path
					// so we'll have to convert it to a URL to match the collection config entries
					getCollectionName(collectionConfig, pathToFileURL(fileName).toString().toLowerCase()),
				);
			}
		},
		typescript: {
			extraFileExtensions: SUPPORTED_FRONTMATTER_EXTENSIONS_KEYS.map((ext) => ({
				extension: ext,
				isMixedContent: true,
				scriptKind: 7 satisfies ts.ScriptKind.Deferred,
			})),
			getServiceScript(astroCode) {
				for (const code of forEachEmbeddedCode(astroCode)) {
					if (code.id === VIRTUAL_CODE_ID) {
						return {
							code,
							extension: '.ts',
							scriptKind: 3 satisfies ts.ScriptKind.TS,
						};
					}
				}
				return undefined;
			},
		},
	};
}

Domain

Subdomains

Frequently Asked Questions

What does getFrontmatterLanguagePlugin() do?
getFrontmatterLanguagePlugin() is a function in the astro codebase, defined in packages/language-tools/ts-plugin/src/frontmatter.ts.
Where is getFrontmatterLanguagePlugin() defined?
getFrontmatterLanguagePlugin() is defined in packages/language-tools/ts-plugin/src/frontmatter.ts at line 36.
What does getFrontmatterLanguagePlugin() call?
getFrontmatterLanguagePlugin() calls 1 function(s): getCollectionName.

Analyze Your Own Codebase

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

Try Supermodel Free