You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

parsemetas.go 904B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package apiclassic
  2. import "github.com/PuerkitoBio/goquery"
  3. type metaType uint8
  4. const (
  5. metaUnknown = metaType(iota)
  6. metaProperty
  7. metaItemProp
  8. )
  9. type metaTag struct {
  10. typ metaType
  11. name string
  12. content string
  13. }
  14. func enumMetas(s *goquery.Selection, next func(metaTag)bool) {
  15. // For each <meta>
  16. s.EachWithBreak(func(i int, s *goquery.Selection) bool {
  17. tag := metaTag{ metaUnknown, "", "" }
  18. listAttrs: for _, attr := range s.Nodes[0].Attr {
  19. switch attr.Key {
  20. case "property":
  21. tag.typ = metaProperty
  22. tag.name = attr.Val
  23. break listAttrs
  24. case "itemprop":
  25. tag.typ = metaItemProp
  26. tag.name = attr.Val
  27. break listAttrs
  28. case "content":
  29. tag.content = attr.Val
  30. break listAttrs
  31. }
  32. if tag.typ == metaUnknown { continue }
  33. if len(tag.content) == 0 { continue }
  34. // Callback tag
  35. if !next(tag) {
  36. return true
  37. }
  38. }
  39. return false
  40. })
  41. }