MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extractFrontmatter

Method extractFrontmatter

src/extraction/astro-extractor.ts:126–154  ·  view source on GitHub ↗

* Extract the frontmatter block: the content between the opening `---` * fence (first non-blank line of the file) and the closing `---` fence. * An unclosed fence is treated as "no frontmatter" rather than swallowing * the whole template as TypeScript. * * Returns the content plus its

()

Source from the content-addressed store, hash-verified

124 * Returns the content plus its 0-indexed start line, or null.
125 */
126 private extractFrontmatter(): { content: string; startLine: number; endLine: number } | null {
127 const lines = this.source.split('\n');
128
129 // Opening fence must be the first non-blank line
130 let openIdx = -1;
131 for (let i = 0; i < lines.length; i++) {
132 const trimmed = lines[i]!.trim();
133 if (trimmed === '') continue;
134 if (trimmed === '---') openIdx = i;
135 break;
136 }
137 if (openIdx === -1) return null;
138
139 // Closing fence
140 let closeIdx = -1;
141 for (let i = openIdx + 1; i < lines.length; i++) {
142 if (lines[i]!.trim() === '---') {
143 closeIdx = i;
144 break;
145 }
146 }
147 if (closeIdx === -1) return null;
148
149 return {
150 content: lines.slice(openIdx + 1, closeIdx).join('\n'),
151 startLine: openIdx + 1, // 0-indexed line where content starts
152 endLine: closeIdx, // 0-indexed line of the closing fence
153 };
154 }
155
156 /**
157 * Extract <script> blocks from the template portion

Callers 1

extractMethod · 0.95

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected