2017-10-20 10:51:56 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-11-09 20:27:03 +00:00
|
|
|
"regexp"
|
2017-10-20 10:51:56 +00:00
|
|
|
)
|
|
|
|
|
2017-11-09 20:27:03 +00:00
|
|
|
const (
|
|
|
|
RE_TAGS = `\B#\w+`
|
|
|
|
)
|
2017-10-20 10:51:56 +00:00
|
|
|
|
2017-11-26 20:17:30 +00:00
|
|
|
type NodeType uint8
|
|
|
|
|
|
|
|
type Node struct {
|
|
|
|
Type string
|
|
|
|
Name string
|
|
|
|
URL string
|
2017-11-27 08:46:50 +00:00
|
|
|
Parent *Node
|
2017-11-26 20:17:30 +00:00
|
|
|
Children []*Node
|
|
|
|
}
|
|
|
|
|
2017-11-20 15:05:44 +00:00
|
|
|
type ParserStats struct {
|
2017-11-17 18:06:34 +00:00
|
|
|
lastNodeCount int
|
2017-11-20 15:05:44 +00:00
|
|
|
lastURLCount int
|
2017-11-17 18:06:34 +00:00
|
|
|
currentNodeCount int
|
|
|
|
currentUrlCount int
|
|
|
|
}
|
2017-10-20 10:51:56 +00:00
|
|
|
|
2017-11-20 18:07:15 +00:00
|
|
|
type ParseHook func(bk *Bookmark)
|
|
|
|
|
2017-11-26 20:17:30 +00:00
|
|
|
func WalkNode(node *Node) {
|
|
|
|
log.Debugf("Node --> %s | %s", node.Name, node.Type)
|
|
|
|
|
|
|
|
if len(node.Children) > 0 {
|
|
|
|
for _, node := range node.Children {
|
|
|
|
go WalkNode(node)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-20 18:07:15 +00:00
|
|
|
func ParseTags(bk *Bookmark) {
|
|
|
|
|
|
|
|
var regex = regexp.MustCompile(RE_TAGS)
|
|
|
|
|
2017-11-23 01:51:23 +00:00
|
|
|
bk.Tags = regex.FindAllString(bk.Metadata, -1)
|
|
|
|
|
|
|
|
if len(bk.Tags) > 0 {
|
|
|
|
log.Debugf("[Title] found following tags: %s", bk.Tags)
|
2017-11-20 18:07:15 +00:00
|
|
|
}
|
2017-11-23 01:51:23 +00:00
|
|
|
|
|
|
|
//bk.tags = regex.FindAllString(bk.url, -1)
|
|
|
|
//if len(tags) > 0 {
|
|
|
|
//log.Debugf("[URL] found following tags: %s", tags)
|
|
|
|
//}
|
2017-11-20 18:07:15 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 20:27:03 +00:00
|
|
|
func _s(value interface{}) string {
|
|
|
|
return string(value.([]byte))
|
|
|
|
}
|
2017-10-20 10:51:56 +00:00
|
|
|
|
2017-11-09 20:27:03 +00:00
|
|
|
func findTagsInTitle(title []byte) {
|
|
|
|
var regex = regexp.MustCompile(RE_TAGS)
|
|
|
|
tags := regex.FindAll(title, -1)
|
|
|
|
debugPrint("%s ---> found following tags: %s", title, tags)
|
|
|
|
}
|