-
Notifications
You must be signed in to change notification settings - Fork 1
/
wf.go
48 lines (39 loc) · 853 Bytes
/
wf.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
package wf
import (
"fmt"
"io"
"wf/opml"
)
type Item struct {
Title string `json:"title"`
Note *string `json:"note,omitempty"`
Children []Item `json:"items,omitempty"`
}
func Note(s string) *string {
return &s
}
func PrintItem(w io.Writer, wfi Item) {
printItemIndent(w, wfi, "")
}
func printItemIndent(w io.Writer, wfi Item, indent string) {
fmt.Fprintf(w, "%s- %s\n", indent, wfi.Title)
for _, child := range wfi.Children {
printItemIndent(w, child, indent+"\t")
}
}
func ToOPML(item *Item) opml.Root {
return opml.New([]opml.Outline{
toOutline(item),
})
}
func toOutline(item *Item) opml.Outline {
outlines := []opml.Outline{}
for _, child := range item.Children {
outlines = append(outlines, toOutline(&child))
}
return opml.Outline{
Text: item.Title,
Note: item.Note,
Children: outlines,
}
}