Compare commits

...
15 Commits
Author SHA1 Message Date
roman a92a1fd3a1 имя модуля 2024-05-15 16:37:47 +03:00
roman dc3bbfce4d дополнительные варианты поиска контента 2024-05-15 16:35:31 +03:00
github-actions[bot]andBot 546a05f94b Update package dependencies + tidy (#44)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2024-05-08 09:08:55 +01:00
github-actions[bot]andBot 76a516f2a3 Update package dependencies + tidy (#43)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2024-04-10 12:36:20 +01:00
github-actions[bot]andBot c79426ef98 Update package dependencies + tidy (#42)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2024-04-04 13:02:13 +01:00
Ian Davis d23fd33d0d Updated github workflows 2024-03-14 10:48:58 +00:00
github-actions[bot]andBot 1a5ca78da5 Update package dependencies + tidy (#41)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2024-03-06 12:00:44 +00:00
Ian Davis 5147d5f6cd Updated github workflows 2024-02-21 10:52:50 +00:00
github-actions[bot]andBot 1971468038 Update package dependencies + tidy (#40)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2024-02-14 09:46:47 +00:00
github-actions[bot]andBot 0d98c9d29d Update package dependencies + tidy (#39)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2024-01-10 10:04:51 +00:00
github-actions[bot]andBot fba0473ccd Update package dependencies + tidy (#38)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2023-11-29 09:04:00 +00:00
Ian Davis d3f130af1c Updated github workflows 2023-11-25 13:56:48 +00:00
Ian Davis f953915e15 Updated github workflows 2023-11-25 13:51:42 +00:00
Ian Davis fc1ff57fc8 Updated github workflows 2023-11-25 13:47:07 +00:00
Ian Davis feb7d5cf4b Updated github workflows 2023-11-25 13:39:16 +00:00
6 changed files with 81 additions and 51 deletions

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ jobs:
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Install Go - name: Install Go
uses: actions/setup-go@v4 uses: actions/setup-go@v5
with: with:
go-version-file: 'go.mod' go-version-file: 'go.mod'
+43 -32
View File
@@ -8,6 +8,48 @@ on:
- master - master
name: Run tests name: Run tests
jobs: jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Get StaticCheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Gomod
run: |
go mod tidy
if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then
echo "go.sum was added by go mod tidy"
exit 1
fi
git diff --exit-code -- go.sum go.mod
- name: Gofmt
if: ${{ success() || failure() }} # run this step even if the previous one failed
run: |
out=$(gofmt -s -l .)
if [[ -n "$out" ]]; then
echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}'
exit 1
fi
- name: Vet
if: ${{ success() || failure() }} # run this step even if the previous one failed
run: go vet ./...
- name: StaticCheck
if: ${{ success() || failure() }} # run this step even if the previous one failed
run: staticcheck ./...
test: test:
strategy: strategy:
matrix: matrix:
@@ -20,41 +62,10 @@ jobs:
submodules: recursive submodules: recursive
- name: Install Go - name: Install Go
uses: actions/setup-go@v4 uses: actions/setup-go@v5
with: with:
go-version-file: 'go.mod' go-version-file: 'go.mod'
- name: Get StaticCheck
if: ${{ matrix.os == 'ubuntu' }}
run: go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Gomod
if: ${{ matrix.os == 'ubuntu' }}
run: |
go mod tidy
if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then
echo "go.sum was added by go mod tidy"
exit 1
fi
git diff --exit-code -- go.sum go.mod
- name: Gofmt
if: ${{ matrix.os == 'ubuntu' && (success() || failure()) }} # run this step even if the previous one failed
run: |
out=$(gofmt -s -l .)
if [[ -n "$out" ]]; then
echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}'
exit 1
fi
- name: Vet
if: ${{ matrix.os == 'ubuntu' && (success() || failure()) }} # run this step even if the previous one failed
run: go vet ./...
- name: StaticCheck
if: ${{ matrix.os == 'ubuntu' && (success() || failure()) }} # run this step even if the previous one failed
run: staticcheck ./...
- name: Test - name: Test
run: go test ./... run: go test ./...
+5 -2
View File
@@ -5,9 +5,12 @@ on:
workflows: ["Run tests"] workflows: ["Run tests"]
types: types:
- completed - completed
branches:
- main
- master
jobs: jobs:
build: version:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }} if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps: steps:
@@ -16,6 +19,6 @@ jobs:
- name: Bump version and push tag - name: Bump version and push tag
id: tag_version id: tag_version
uses: mathieudutour/github-tag-action@v6.1 uses: mathieudutour/github-tag-action@v6.2
with: with:
github_token: ${{ secrets.GITHUB_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }}
+2 -2
View File
@@ -1,5 +1,5 @@
module github.com/iand/microdata module git.ukamnya.ru/ukamnya/microdata
go 1.21.4 go 1.21.4
require golang.org/x/net v0.18.0 require golang.org/x/net v0.25.0
+2 -2
View File
@@ -1,2 +1,2 @@
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
+28 -12
View File
@@ -31,7 +31,7 @@ type Item struct {
// NewItem creates a new microdata item // NewItem creates a new microdata item
func NewItem() *Item { func NewItem() *Item {
return &Item{ return &Item{
Properties: make(propertyMap, 0), Properties: make(propertyMap),
Types: make([]string, 0), Types: make([]string, 0),
} }
} }
@@ -104,7 +104,7 @@ func (p *Parser) Parse() (*Microdata, error) {
} }
topLevelItemNodes := make([]*html.Node, 0) 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) { walk(tree, func(n *html.Node) {
if n.Type == html.ElementNode { if n.Type == html.ElementNode {
@@ -171,39 +171,47 @@ func (p *Parser) readItem(item *Item, node *html.Node) *Item {
} }
} }
} else { } else {
var propertyValue string var propertyValue *string
switch node.DataAtom { switch node.DataAtom {
case atom.Meta: case atom.Meta:
if val, exists := getAttr("content", node); exists { 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: case atom.Audio, atom.Embed, atom.Iframe, atom.Img, atom.Source, atom.Track, atom.Video:
if urlValue, exists := getAttr("src", node); exists { if urlValue, exists := getAttr("src", node); exists {
if parsedURL, err := p.base.Parse(urlValue); err == nil { if parsedURL, err := p.base.Parse(urlValue); err == nil {
propertyValue = parsedURL.String() parsedStr := parsedURL.String()
propertyValue = &parsedStr
} }
} }
case atom.A, atom.Area, atom.Link: case atom.A, atom.Area, atom.Link:
if urlValue, exists := getAttr("href", node); exists { if urlValue, exists := getAttr("href", node); exists {
if parsedURL, err := p.base.Parse(urlValue); err == nil { if parsedURL, err := p.base.Parse(urlValue); err == nil {
propertyValue = parsedURL.String() parsedStr := parsedURL.String()
propertyValue = &parsedStr
} }
} }
case atom.Object: case atom.Object:
if urlValue, exists := getAttr("data", node); exists { if urlValue, exists := getAttr("data", node); exists {
propertyValue = urlValue propertyValue = &urlValue
} }
case atom.Data, atom.Meter: case atom.Data, atom.Meter:
if urlValue, exists := getAttr("value", node); exists { if urlValue, exists := getAttr("value", node); exists {
propertyValue = urlValue propertyValue = &urlValue
} }
case atom.Time: case atom.Time:
if urlValue, exists := getAttr("datetime", node); exists { if urlValue, exists := getAttr("datetime", node); exists {
propertyValue = urlValue propertyValue = &urlValue
} }
default: 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 var text bytes.Buffer
walk(node, func(n *html.Node) { walk(node, func(n *html.Node) {
if n.Type == html.TextNode { 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), " ") { for _, propertyName := range strings.Split(strings.TrimSpace(itemprop), " ") {
propertyName = strings.TrimSpace(propertyName) propertyName = strings.TrimSpace(propertyName)
if propertyName != "" { if propertyName != "" {
item.AddString(propertyName, propertyValue) item.AddString(propertyName, *propertyValue)
} }
} }
} }