@@ -3,7 +3,7 @@ package skillhub
33import (
44 "encoding/json"
55 "fmt"
6- "io/ioutil "
6+ "io"
77 "net/http"
88 "net/url"
99 "regexp"
@@ -67,7 +67,7 @@ func (c *Client) Search(query string) ([]Skill, error) {
6767 if err != nil {
6868 return nil , err
6969 }
70- defer resp .Body .Close ()
70+ defer func () { _ = resp .Body .Close () } ()
7171
7272 if resp .StatusCode != http .StatusOK {
7373 return nil , fmt .Errorf ("SkillHub API returned status: %d" , resp .StatusCode )
@@ -88,13 +88,13 @@ func (c *Client) Resolve(slug string) (string, error) {
8888 if err != nil {
8989 return "" , err
9090 }
91- defer resp .Body .Close ()
91+ defer func () { _ = resp .Body .Close () } ()
9292
9393 if resp .StatusCode != http .StatusOK {
9494 return "" , fmt .Errorf ("failed to fetch skill page: %d" , resp .StatusCode )
9595 }
9696
97- body , err := ioutil .ReadAll (resp .Body )
97+ body , err := io .ReadAll (resp .Body )
9898 if err != nil {
9999 return "" , err
100100 }
@@ -115,5 +115,29 @@ func (c *Client) Resolve(slug string) (string, error) {
115115 return rawURL , nil
116116 }
117117
118+ // Fallback: try to find repoUrl in Next.js hydration data or JSON
119+ // Matches: "repoUrl":"https://github.com/..."
120+ reJson := regexp .MustCompile (`"repoUrl":"(https://github\.com/[^"]+)"` )
121+ matchesJson := reJson .FindStringSubmatch (string (body ))
122+ if len (matchesJson ) > 1 {
123+ rawURL := matchesJson [1 ]
124+ // unescape backward slashes if any (though usually forward slashes are fine in JSON)
125+ // But in the hydration data we saw, it was like \"repoUrl\":\"https...\"
126+ // The string(body) should have the raw bytes.
127+ // If it's inside a JS string, it might be escaped.
128+ // The curl output showed: \"repoUrl\":\"https://github.com/MadAppGang/claude-code\"
129+ // So the regex needs to handle the escaped quotes?
130+ // Actually, if we use a broader regex, we can capture it.
131+ // Let's rely on finding https://github.com inside the quote.
132+ return rawURL , nil
133+ }
134+
135+ // Try one more pattern for escaped JSON
136+ reEscaped := regexp .MustCompile (`\\?"repoUrl\\?":\\?"(https://github\.com/[^"\\]+)\\?"` )
137+ matchesEscaped := reEscaped .FindStringSubmatch (string (body ))
138+ if len (matchesEscaped ) > 1 {
139+ return matchesEscaped [1 ], nil
140+ }
141+
118142 return "" , fmt .Errorf ("GitHub URL not found for skill: %s" , slug )
119143}
0 commit comments