mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 12:23:22 +00:00
Single-binary web UI for visual skill management — React 19 + Vite frontend embedded via go:embed, Go net/http REST API backend (30+ endpoints). Includes dashboard, skills browser, targets, sync, collect, search, install, config editor, backup/restore, and git sync pages. Also adds Bitbucket/GitLab URL parsing for install, git operations library, skill version checking, CI frontend build steps, Docker sandbox support, and website docs for the ui command.
86 lines
1.7 KiB
Go
86 lines
1.7 KiB
Go
package utils
|
|
|
|
import (
|
|
"bufio"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// ParseSkillName reads the SKILL.md and extracts the "name" from frontmatter.
|
|
func ParseSkillName(skillPath string) (string, error) {
|
|
skillFile := filepath.Join(skillPath, "SKILL.md")
|
|
file, err := os.Open(skillFile)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer file.Close()
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
inFrontmatter := false
|
|
|
|
for scanner.Scan() {
|
|
line := strings.TrimSpace(scanner.Text())
|
|
|
|
// Detect frontmatter delimiters
|
|
if line == "---" {
|
|
if inFrontmatter {
|
|
break // End of frontmatter
|
|
}
|
|
inFrontmatter = true
|
|
continue
|
|
}
|
|
|
|
if inFrontmatter {
|
|
if strings.HasPrefix(line, "name:") {
|
|
// Extract value: "name: my-skill" -> "my-skill"
|
|
parts := strings.SplitN(line, ":", 2)
|
|
if len(parts) == 2 {
|
|
name := strings.TrimSpace(parts[1])
|
|
// Remove quotes if present
|
|
name = strings.Trim(name, `"'`)
|
|
return name, nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return "", nil // Name not found
|
|
}
|
|
|
|
// ParseFrontmatterField reads a SKILL.md file and extracts the value of a given frontmatter field.
|
|
func ParseFrontmatterField(filePath, field string) string {
|
|
file, err := os.Open(filePath)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
defer file.Close()
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
inFrontmatter := false
|
|
prefix := field + ":"
|
|
|
|
for scanner.Scan() {
|
|
line := strings.TrimSpace(scanner.Text())
|
|
|
|
if line == "---" {
|
|
if inFrontmatter {
|
|
break
|
|
}
|
|
inFrontmatter = true
|
|
continue
|
|
}
|
|
|
|
if inFrontmatter && strings.HasPrefix(line, prefix) {
|
|
parts := strings.SplitN(line, ":", 2)
|
|
if len(parts) == 2 {
|
|
val := strings.TrimSpace(parts[1])
|
|
val = strings.Trim(val, `"'`)
|
|
return val
|
|
}
|
|
}
|
|
}
|
|
|
|
return ""
|
|
}
|