Skip to content

Instantly share code, notes, and snippets.

@adamflott
Created July 28, 2015 12:42
Show Gist options
  • Save adamflott/502544846aa6c57cf361 to your computer and use it in GitHub Desktop.
Save adamflott/502544846aa6c57cf361 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
"time"
)
type ChromeBookmarks struct {
Name string `json:"name"`
Type string `json:"type"`
Url string `json:"url"`
Children []*ChromeBookmarks `json:"children"`
}
type AllChromeBookmarks struct {
Name string `json:"name"`
B []*ChromeBookmarks `json:"children"`
}
func Print(idx int, b []*ChromeBookmarks) {
for _, v := range b {
if v.Type == "folder" {
fmt.Printf("%s %s\n", strings.Repeat("#", idx), v.Name)
Print(idx+1, v.Children)
} else {
fmt.Printf("%s [%s](%s)\n", "*", v.Name, v.Url)
}
}
}
func main() {
cb, cberr := ioutil.ReadFile("./data/bookmarks.json")
if cberr != nil {
os.Exit(1)
}
var b []AllChromeBookmarks
err := json.Unmarshal(cb, &b)
if err != nil {
fmt.Println("error:", err)
}
fmt.Println("---")
fmt.Printf("title: Bookmarks\n")
fmt.Printf("date: %s\n", time.Now().Format("2006-01-02"))
fmt.Println("---")
fmt.Printf("An auto-generated list of my Chromium bookmarks.\n\n")
/*
fmt.Println("{{< highlight shell >}}")
fmt.Printf("$ cat ~/.config/chromium/Profile\\ 2/Bookmarks | jq '.roots.bookmark_bar.children' > data/bookmarks.json\n")
fmt.Printf("$ go run bin/chrome2mdlinks.go > content/posts/bookmarks.md\n")
fmt.Println("{{< /highlight >}}")
fmt.Printf("\n\n")
*/
skip := []string{"Misc.", "Projects", "Read Next", "Work"}
for _, v := range b {
plz_skip := false
for _, n := range skip {
if n == v.Name {
plz_skip = true
}
}
if plz_skip == false {
fmt.Printf("# %s\n", v.Name)
Print(2, v.B)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment