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

Method extractFrontmatter

src/extraction/astro-extractor.ts:135–163  ·  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

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

Callers 1

extractMethod · 0.95

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected