diff options
| author | Jesse Vincent <jesse@fsck.com> | 2025-11-22 12:41:58 -0800 |
|---|---|---|
| committer | Jesse Vincent <jesse@fsck.com> | 2025-11-22 12:41:58 -0800 |
| commit | 4eab16380b65cd4aef0e586556e7a41999b7284a (patch) | |
| tree | 8a0ae37fac7b276ff83d07bd270925d0a4040718 /lib | |
| parent | 7ffff619650a83b4994f64fd452cd69636fc85c0 (diff) | |
refactor: extract frontmatter stripping to shared helper function
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/skills-core.js | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/skills-core.js b/lib/skills-core.js index ce9c0ef..c77c26f 100644 --- a/lib/skills-core.js +++ b/lib/skills-core.js @@ -169,9 +169,40 @@ function checkForUpdates(repoDir) { } } +/** + * Strip YAML frontmatter from skill content, returning just the content. + * + * @param {string} content - Full content including frontmatter + * @returns {string} - Content without frontmatter + */ +function stripFrontmatter(content) { + const lines = content.split('\n'); + let inFrontmatter = false; + let frontmatterEnded = false; + const contentLines = []; + + for (const line of lines) { + if (line.trim() === '---') { + if (inFrontmatter) { + frontmatterEnded = true; + continue; + } + inFrontmatter = true; + continue; + } + + if (frontmatterEnded || !inFrontmatter) { + contentLines.push(line); + } + } + + return contentLines.join('\n').trim(); +} + module.exports = { extractFrontmatter, findSkillsInDir, resolveSkillPath, - checkForUpdates + checkForUpdates, + stripFrontmatter }; |
