diff options
| author | Shulhan <ms@kilabit.info> | 2026-02-12 01:04:40 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2026-02-12 01:04:40 +0700 |
| commit | 9c7ee77376294e9abd70ca356e26d0ab16ad7466 (patch) | |
| tree | 2fc279d233575571389ea89d2ba0be16314bc7dd /brokenlinks/worker.go | |
| parent | 8100b3be0730173a77f1a64f9ac6bc8862a159ac (diff) | |
| download | jarink-9c7ee77376294e9abd70ca356e26d0ab16ad7466.tar.xz | |
brokenlinks: store the anchor or image source in link
In the struct Link, we add field Value that store the href from A element
or src from IMG element.
This allow us to debug any error during scan, especially joining path
and link.
Diffstat (limited to 'brokenlinks/worker.go')
| -rw-r--r-- | brokenlinks/worker.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/brokenlinks/worker.go b/brokenlinks/worker.go index 387cc05..79ae796 100644 --- a/brokenlinks/worker.go +++ b/brokenlinks/worker.go @@ -89,8 +89,10 @@ func newWorker(opts Options) (wrk *worker, err error) { } wrk.baseUrl = &url.URL{ - Scheme: wrk.opts.scanUrl.Scheme, - Host: wrk.opts.scanUrl.Host, + Scheme: wrk.opts.scanUrl.Scheme, + Host: wrk.opts.scanUrl.Host, + Path: `/`, + RawPath: `/`, } if opts.PastResultFile == "" { @@ -304,8 +306,6 @@ func (wrk *worker) scan(linkq jarink.Link) (resultq map[string]jarink.Link) { return resultq } - var parentUrl *url.URL - // Check and get the redirect location or use the original URL. location := httpResp.Header.Get(`Location`) if location == `` { @@ -314,6 +314,7 @@ func (wrk *worker) scan(linkq jarink.Link) (resultq map[string]jarink.Link) { linkq.Url = location } + var parentUrl *url.URL parentUrl, err = url.Parse(location) if err != nil { linkq.StatusCode = StatusBadLink @@ -415,6 +416,7 @@ func (wrk *worker) processLink(parentUrl *url.URL, val string, kind int) ( linkq = &jarink.Link{ ParentUrl: parentUrl, + Value: val, Kind: kind, } @@ -452,7 +454,7 @@ func (wrk *worker) processLink(parentUrl *url.URL, val string, kind int) ( // "parent/page.ext" + "val" => "parent/val" tmp, _ := url.Parse(parentUrl.String()) tmp.Path = path.Dir(tmp.Path) - linkq.Url = parentUrl.JoinPath(tmp.Path).String() + linkq.Url = tmp.JoinPath(val).String() } return linkq } |
