MCPcopy Create free account
hub / github.com/github/awesome-copilot / parseFrontmatter

Function parseFrontmatter

eng/yaml-parser.mjs:23–57  ·  view source on GitHub ↗

* Parse frontmatter from a markdown file using vfile-matter * Works with any markdown file that has YAML frontmatter (agents, prompts, instructions) * @param {string} filePath - Path to the markdown file * @returns {object|null} Parsed frontmatter object or null on error

(filePath)

Source from the content-addressed store, hash-verified

21 * @returns {object|null} Parsed frontmatter object or null on error
22 */
23function parseFrontmatter(filePath) {
24 return safeFileOperation(
25 () => {
26 const content = fs.readFileSync(filePath, "utf8");
27 const file = new VFile({ path: filePath, value: content });
28
29 // Parse the frontmatter using vfile-matter
30 matter(file);
31
32 // The frontmatter is now available in file.data.matter
33 const frontmatter = file.data.matter;
34
35 // Normalize string fields that can accumulate trailing newlines/spaces
36 if (frontmatter) {
37 if (typeof frontmatter.name === "string") {
38 frontmatter.name = frontmatter.name.replace(/[\r\n]+$/g, "").trim();
39 }
40 if (typeof frontmatter.title === "string") {
41 frontmatter.title = frontmatter.title.replace(/[\r\n]+$/g, "").trim();
42 }
43 if (typeof frontmatter.description === "string") {
44 // Remove only trailing whitespace/newlines; preserve internal formatting
45 frontmatter.description = frontmatter.description.replace(
46 /[\s\r\n]+$/g,
47 ""
48 );
49 }
50 }
51
52 return frontmatter;
53 },
54 filePath,
55 null
56 );
57}
58
59/**
60 * Extract agent metadata including MCP server information

Callers 8

generateAgentsDataFunction · 0.90
generateInstructionsDataFunction · 0.90
extractTitleFunction · 0.90
extractDescriptionFunction · 0.90
extractAgentMetadataFunction · 0.85
parseSkillMetadataFunction · 0.85
parseHookMetadataFunction · 0.85
parseWorkflowMetadataFunction · 0.85

Calls 1

safeFileOperationFunction · 0.70

Tested by

no test coverage detected