mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
SKILL.md frontmatter may contain "version: v0.15.0" (with v prefix), but callers already prepend "v" when formatting. Normalize at the source by trimming the prefix in both ReadLocalSkillVersion and FetchRemoteSkillVersion.
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package version
|
|
|
|
import (
|
|
"bufio"
|
|
"net/http"
|
|
"path/filepath"
|
|
"strings"
|
|
"time"
|
|
|
|
"skillshare/internal/utils"
|
|
)
|
|
|
|
// SkillSourceURL is the raw URL to the official skillshare skill's SKILL.md.
|
|
const SkillSourceURL = "https://raw.githubusercontent.com/runkids/skillshare/main/skills/skillshare/SKILL.md"
|
|
|
|
// ReadLocalSkillVersion reads the "version" field from source/skillshare/SKILL.md.
|
|
// The returned value never has a "v" prefix.
|
|
func ReadLocalSkillVersion(sourceDir string) string {
|
|
skillFile := filepath.Join(sourceDir, "skillshare", "SKILL.md")
|
|
return strings.TrimPrefix(utils.ParseFrontmatterField(skillFile, "version"), "v")
|
|
}
|
|
|
|
// FetchRemoteSkillVersion fetches the latest skill version from GitHub (3s timeout).
|
|
func FetchRemoteSkillVersion() string {
|
|
client := &http.Client{Timeout: 3 * time.Second}
|
|
resp, err := client.Get(SkillSourceURL)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
return ""
|
|
}
|
|
|
|
scanner := bufio.NewScanner(resp.Body)
|
|
inFrontmatter := false
|
|
|
|
for scanner.Scan() {
|
|
line := scanner.Text()
|
|
|
|
if line == "---" {
|
|
if !inFrontmatter {
|
|
inFrontmatter = true
|
|
continue
|
|
}
|
|
break
|
|
}
|
|
|
|
if inFrontmatter && strings.HasPrefix(line, "version:") {
|
|
parts := strings.SplitN(line, ":", 2)
|
|
if len(parts) == 2 {
|
|
return strings.TrimPrefix(strings.TrimSpace(parts[1]), "v")
|
|
}
|
|
}
|
|
}
|
|
|
|
return ""
|
|
}
|