-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
curated-lists.go
60 lines (47 loc) · 1.26 KB
/
curated-lists.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"bufio"
"io/ioutil"
"log"
"net/http"
"regexp"
"strings"
)
// downloadCuratedLists downloads curated lists from GitHub.
func downloadCuratedLists() {
resp, err := http.Get("https://raw.githubusercontent.com/learn-anything/curated-lists/master/readme.md")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
// body, err := ioutil.ReadAll(resp.Body)
// TODO: add it to cache
// ioutil.WriteFile("lists.md", body, 0600)
}
// doSearchLists searches curated lists.
func doSearchLists() error {
showUpdateStatus()
log.Printf("query=%s", query)
// TODO: where is cache placed?
parseList("lists.md")
if query != "" {
wf.Filter(query)
}
wf.WarnEmpty("No matching items", "Try a different query?")
wf.SendFeedback()
return nil
}
// parseList parses a markdown list for links.
func parseList(file string) {
bytes, _ := ioutil.ReadFile(file)
// Regex to extract markdown links
re := regexp.MustCompile(`\[([^\]]*)\]\(([^)]*)\)`)
// Read string line by line and apply regex
scanner := bufio.NewScanner(strings.NewReader(string(bytes)))
for scanner.Scan() {
matches := re.FindAllStringSubmatch(scanner.Text(), -1)
wf.NewItem(matches[0][1]).Arg(matches[0][2]).Valid(true).UID(matches[0][1])
}
}
func readList(listName string) {
}