summaryrefslogtreecommitdiff
path: root/links.go
blob: f7bda7628cea654486fc65b7f8aec66d1e763b0d (plain)
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
package main

import (
	"bufio"
	"html/template"
	"log"
	"os"
	"strings"
)

type Link struct {
	Title string
	URL   template.URL
}

func GetLinks() (links []Link) {
	fh, err := os.Open(os.ExpandEnv("$HOME/.startpage-urls"))
	if err != nil {
		log.Printf("Couldn't read links: %s", err)
		return
	}
	defer fh.Close()

	scanner := bufio.NewScanner(fh)
	for scanner.Scan() {
		parts := strings.SplitN(scanner.Text(), "->", 2)
		links = append(links, Link{
			strings.TrimSpace(parts[0]),
			template.URL(strings.TrimSpace(parts[1])),
		})
	}

	return
}