Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc3bbfce4d | ||
|
|
546a05f94b | ||
|
|
76a516f2a3 | ||
|
|
c79426ef98 | ||
|
|
d23fd33d0d | ||
|
|
1a5ca78da5 | ||
|
|
5147d5f6cd | ||
|
|
1971468038 |
No files matched your search
@@ -11,7 +11,7 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v4
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: 'go.mod'
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ jobs:
|
||||
submodules: recursive
|
||||
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v4
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: 'go.mod'
|
||||
|
||||
@@ -62,7 +62,7 @@ jobs:
|
||||
submodules: recursive
|
||||
|
||||
- name: Install Go
|
||||
uses: actions/setup-go@v4
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: 'go.mod'
|
||||
|
||||
|
||||
@@ -19,6 +19,6 @@ jobs:
|
||||
|
||||
- name: Bump version and push tag
|
||||
id: tag_version
|
||||
uses: mathieudutour/github-tag-action@v6.1
|
||||
uses: mathieudutour/github-tag-action@v6.2
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -2,4 +2,4 @@ module github.com/iand/microdata
|
||||
|
||||
go 1.21.4
|
||||
|
||||
require golang.org/x/net v0.20.0
|
||||
require golang.org/x/net v0.25.0
|
||||
@@ -1,2 +1,2 @@
|
||||
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
|
||||
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
+28
-12
@@ -31,7 +31,7 @@ type Item struct {
|
||||
// NewItem creates a new microdata item
|
||||
func NewItem() *Item {
|
||||
return &Item{
|
||||
Properties: make(propertyMap, 0),
|
||||
Properties: make(propertyMap),
|
||||
Types: make([]string, 0),
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ func (p *Parser) Parse() (*Microdata, error) {
|
||||
}
|
||||
|
||||
topLevelItemNodes := make([]*html.Node, 0)
|
||||
p.identifiedNodes = make(map[string]*html.Node, 0)
|
||||
p.identifiedNodes = make(map[string]*html.Node)
|
||||
|
||||
walk(tree, func(n *html.Node) {
|
||||
if n.Type == html.ElementNode {
|
||||
@@ -171,39 +171,47 @@ func (p *Parser) readItem(item *Item, node *html.Node) *Item {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var propertyValue string
|
||||
var propertyValue *string
|
||||
|
||||
switch node.DataAtom {
|
||||
case atom.Meta:
|
||||
if val, exists := getAttr("content", node); exists {
|
||||
propertyValue = val
|
||||
propertyValue = &val
|
||||
}
|
||||
case atom.Audio, atom.Embed, atom.Iframe, atom.Img, atom.Source, atom.Track, atom.Video:
|
||||
if urlValue, exists := getAttr("src", node); exists {
|
||||
if parsedURL, err := p.base.Parse(urlValue); err == nil {
|
||||
propertyValue = parsedURL.String()
|
||||
parsedStr := parsedURL.String()
|
||||
propertyValue = &parsedStr
|
||||
}
|
||||
}
|
||||
case atom.A, atom.Area, atom.Link:
|
||||
if urlValue, exists := getAttr("href", node); exists {
|
||||
if parsedURL, err := p.base.Parse(urlValue); err == nil {
|
||||
propertyValue = parsedURL.String()
|
||||
parsedStr := parsedURL.String()
|
||||
propertyValue = &parsedStr
|
||||
}
|
||||
}
|
||||
case atom.Object:
|
||||
if urlValue, exists := getAttr("data", node); exists {
|
||||
propertyValue = urlValue
|
||||
propertyValue = &urlValue
|
||||
}
|
||||
case atom.Data, atom.Meter:
|
||||
if urlValue, exists := getAttr("value", node); exists {
|
||||
propertyValue = urlValue
|
||||
propertyValue = &urlValue
|
||||
}
|
||||
case atom.Time:
|
||||
if urlValue, exists := getAttr("datetime", node); exists {
|
||||
propertyValue = urlValue
|
||||
propertyValue = &urlValue
|
||||
}
|
||||
|
||||
default:
|
||||
// The "content" attribute can be found on other tags besides the meta tag.
|
||||
if val, ok := getAttr("content", node); ok {
|
||||
propertyValue = &val
|
||||
break
|
||||
}
|
||||
|
||||
var text bytes.Buffer
|
||||
walk(node, func(n *html.Node) {
|
||||
if n.Type == html.TextNode {
|
||||
@@ -211,14 +219,22 @@ func (p *Parser) readItem(item *Item, node *html.Node) *Item {
|
||||
}
|
||||
|
||||
})
|
||||
propertyValue = text.String()
|
||||
|
||||
val := text.String()
|
||||
propertyValue = &val
|
||||
}
|
||||
|
||||
if len(propertyValue) > 0 {
|
||||
if propertyValue == nil {
|
||||
if val, ok := getAttr("content", node); ok {
|
||||
propertyValue = &val
|
||||
}
|
||||
}
|
||||
|
||||
if propertyValue != nil {
|
||||
for _, propertyName := range strings.Split(strings.TrimSpace(itemprop), " ") {
|
||||
propertyName = strings.TrimSpace(propertyName)
|
||||
if propertyName != "" {
|
||||
item.AddString(propertyName, propertyValue)
|
||||
item.AddString(propertyName, *propertyValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user