summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJesse Vincent <jesse@fsck.com>2025-11-22 12:41:58 -0800
committerJesse Vincent <jesse@fsck.com>2025-11-22 12:41:58 -0800
commit4eab16380b65cd4aef0e586556e7a41999b7284a (patch)
tree8a0ae37fac7b276ff83d07bd270925d0a4040718 /lib
parent7ffff619650a83b4994f64fd452cd69636fc85c0 (diff)
refactor: extract frontmatter stripping to shared helper function
Diffstat (limited to 'lib')
-rw-r--r--lib/skills-core.js33
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
};