crawlscope 0.10.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -0
- data/README.md +7 -0
- data/UPGRADE.md +84 -0
- data/docs/architecture.md +73 -0
- data/docs/link-map.md +203 -0
- data/docs/rails.md +9 -0
- data/docs/rules.md +49 -0
- data/lib/crawlscope/cli.rb +86 -5
- data/lib/crawlscope/configuration.rb +2 -1
- data/lib/crawlscope/crawl.rb +11 -79
- data/lib/crawlscope/crawling/fetcher_factory.rb +31 -0
- data/lib/crawlscope/crawling/target.rb +45 -0
- data/lib/crawlscope/crawling/target_resolver.rb +75 -0
- data/lib/crawlscope/documents/canonical.rb +22 -0
- data/lib/crawlscope/documents/robots.rb +57 -0
- data/lib/crawlscope/http.rb +37 -13
- data/lib/crawlscope/link_map/audit.rb +240 -0
- data/lib/crawlscope/link_map/extractor.rb +59 -0
- data/lib/crawlscope/link_map/graph.rb +165 -0
- data/lib/crawlscope/link_map/manifest.rb +68 -0
- data/lib/crawlscope/link_map/report.rb +217 -0
- data/lib/crawlscope/link_map/robots_policy.rb +72 -0
- data/lib/crawlscope/link_map/scope.rb +82 -0
- data/lib/crawlscope/link_map/sitemap_urls.rb +103 -0
- data/lib/crawlscope/page.rb +4 -0
- data/lib/crawlscope/rake_tasks.rb +11 -1
- data/lib/crawlscope/reporter.rb +19 -162
- data/lib/crawlscope/reporting/issue_presenter.rb +162 -0
- data/lib/crawlscope/reporting/url_formatter.rb +29 -0
- data/lib/crawlscope/rule_registry.rb +2 -2
- data/lib/crawlscope/rules/content_quality.rb +18 -0
- data/lib/crawlscope/rules/indexability.rb +9 -14
- data/lib/crawlscope/rules/links/canonical_checks.rb +102 -0
- data/lib/crawlscope/rules/links/extractor.rb +100 -0
- data/lib/crawlscope/rules/links/graph.rb +39 -0
- data/lib/crawlscope/rules/links/inbound_checks.rb +124 -0
- data/lib/crawlscope/rules/links/outgoing_checks.rb +104 -0
- data/lib/crawlscope/rules/links/resolution_check.rb +88 -0
- data/lib/crawlscope/rules/links/scope.rb +23 -0
- data/lib/crawlscope/rules/links/target_lookup.rb +38 -0
- data/lib/crawlscope/rules/links/url_checks.rb +54 -0
- data/lib/crawlscope/rules/links.rb +18 -600
- data/lib/crawlscope/rules/metadata.rb +2 -2
- data/lib/crawlscope/rules/structured_data.rb +26 -77
- data/lib/crawlscope/rules/uniqueness.rb +1 -1
- data/lib/crawlscope/run.rb +16 -0
- data/lib/crawlscope/schemas.rb +10 -2
- data/lib/crawlscope/server_timing/reporter.rb +2 -13
- data/lib/crawlscope/sitemap.rb +16 -5
- data/lib/crawlscope/structured_data/audit.rb +17 -76
- data/lib/crawlscope/structured_data/check.rb +2 -0
- data/lib/crawlscope/structured_data/document.rb +14 -1
- data/lib/crawlscope/structured_data/entry.rb +31 -0
- data/lib/crawlscope/structured_data/outcome.rb +11 -0
- data/lib/crawlscope/structured_data/report.rb +6 -14
- data/lib/crawlscope/structured_data/reporter.rb +6 -11
- data/lib/crawlscope/structured_data/validator.rb +64 -0
- data/lib/crawlscope/version.rb +1 -1
- data/lib/tasks/crawlscope_tasks.rake +6 -1
- data/test/crawlscope/cli_test.rb +21 -0
- data/test/crawlscope/content_quality_rule_test.rb +51 -0
- data/test/crawlscope/link_map_test.rb +337 -0
- data/test/crawlscope/links_rule_test.rb +16 -0
- data/test/crawlscope/rake_tasks_test.rb +10 -0
- data/test/crawlscope/reporter_test.rb +12 -0
- data/test/crawlscope/schema_registry_test.rb +22 -0
- data/test/crawlscope/structured_data_audit_test.rb +60 -0
- data/test/crawlscope/structured_data_report_test.rb +32 -0
- data/test/crawlscope/structured_data_rule_test.rb +11 -1
- data/test/crawlscope/structured_data_validator_test.rb +24 -0
- metadata +46 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b4873e04bb4a26d3fb4bd2fa4e5f08f879a03391df0f4b95fa1c1c9d454c333f
|
|
4
|
+
data.tar.gz: 0c6712a5c9187adc383d988cd8702f28201652d515d085de9a3604f754bcf1ba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6c6bad08e6e1a60df82a9b17fadaa556f1acbab71e9e46af2065dddae0846546c3298fc5941297c1c1944c9d6161ecd155f8e4da423b60ab9600865b0d459eb7
|
|
7
|
+
data.tar.gz: f967564ccb9e3dace5fbda693cf674e1b69f741437b2204c05eb61684e1d062ec25e2a2079fc75335349fb13ec51c0f64bdacd46b3f00e53d5d1f6645a08edfc
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.11.0] - 2026-11-28
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- add internal link maps and reachability reports
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [0.10.2] - 2026-11-15
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- unify validation and reporting responsibilities
|
|
23
|
+
|
|
24
|
+
- enforce required structured data types by URL
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
|
|
31
|
+
- accept date-only review publication dates
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
8
35
|
## [0.10.1] - 2026-11-08
|
|
9
36
|
|
|
10
37
|
|
data/README.md
CHANGED
|
@@ -30,6 +30,13 @@ The default rule set includes:
|
|
|
30
30
|
- content-quality checks
|
|
31
31
|
- internal-link checks
|
|
32
32
|
|
|
33
|
+
## Internal link map
|
|
34
|
+
|
|
35
|
+
Run `crawlscope link-map --url https://example.com` to export a sitemap-based
|
|
36
|
+
internal link graph, inspect observed click depth, and compare expected links.
|
|
37
|
+
The command also supports CSV, DOT, and before/after snapshots. See the
|
|
38
|
+
[link map guide](docs/link-map.md) for CLI, Ruby, and Rails examples.
|
|
39
|
+
|
|
33
40
|
## Documentation
|
|
34
41
|
|
|
35
42
|
This README and the linked repository guides describe the checked-out code.
|
data/UPGRADE.md
CHANGED
|
@@ -37,6 +37,90 @@ in the README; the shared workflow does not inherit another gem's permission.
|
|
|
37
37
|
|
|
38
38
|
## Next Release
|
|
39
39
|
|
|
40
|
+
### Validation console output
|
|
41
|
+
|
|
42
|
+
`crawlscope validate` and `crawlscope:validate` now show a link map summary
|
|
43
|
+
using the pages validation fetched. Exit codes are unchanged. If a script
|
|
44
|
+
expects the previous console output, pass `--no-link-map` to the CLI or set
|
|
45
|
+
`LINK_MAP=0` for Rake. Ruby callers can pass
|
|
46
|
+
`Crawlscope::Reporter.new(io: io, link_map: false)` to `Crawlscope::Run.new`.
|
|
47
|
+
|
|
48
|
+
### Review publication dates
|
|
49
|
+
|
|
50
|
+
Standalone and nested reviews now accept a date (`2026-09-16`) or timestamp for
|
|
51
|
+
`datePublished`, matching [Schema.org's Date or DateTime contract](https://schema.org/datePublished).
|
|
52
|
+
Invalid calendar dates still fail validation. Hosts no longer need to invent a
|
|
53
|
+
time to validate a review whose source publishes only its date.
|
|
54
|
+
|
|
55
|
+
### Required structured-data types
|
|
56
|
+
|
|
57
|
+
Set `config.required_structured_data_types` to a callback accepting a URL and
|
|
58
|
+
returning the types that page must contain. Separate strings require all types;
|
|
59
|
+
nested arrays accept alternatives, such as `[["Article", "BlogPosting",
|
|
60
|
+
"NewsArticle"]]`. The default remains no additional type requirements.
|
|
61
|
+
See [the rule configuration](docs/rules.md#required-types-by-url) for examples.
|
|
62
|
+
|
|
63
|
+
The default sitemap rule and direct URL audits apply the same requirements.
|
|
64
|
+
Custom rule registries must pass the callback through `required_types:` when
|
|
65
|
+
constructing their structured-data rule. Custom configuration objects supplied
|
|
66
|
+
to `Run` or `StructuredData::Check` can expose `required_structured_data_types`
|
|
67
|
+
to opt in. Existing objects without that optional setting retain their behavior.
|
|
68
|
+
|
|
69
|
+
### Shared audit outcomes and internal architecture
|
|
70
|
+
|
|
71
|
+
Direct structured-data audits now fail when an HTML page has no structured data
|
|
72
|
+
or contains a JSON-LD or microdata item missing `@type`. Detailed output,
|
|
73
|
+
summaries, and CLI/Rake exit status agree on these failures. Summary categories
|
|
74
|
+
also include failures on successful responses other than HTTP 200 and browser
|
|
75
|
+
responses without a status. Non-HTML responses remain successful skips.
|
|
76
|
+
|
|
77
|
+
Hosts using `validate_json_ld` or `crawlscope ldjson` must add the missing markup
|
|
78
|
+
or type to pass validation. Summary URL rows now retain the full URL, including
|
|
79
|
+
the host and query string; update text parsers that expected path-only rows.
|
|
80
|
+
The JSON report retains its existing shape and includes missing-type errors in
|
|
81
|
+
`validation_errors`.
|
|
82
|
+
|
|
83
|
+
JobPosting count checks are now opt-in and scoped to a host-supplied path
|
|
84
|
+
pattern. Crawlscope no longer assumes `/careers/...` identifies job detail
|
|
85
|
+
pages or that multiple JobPosting items are invalid on other pages. Hosts that
|
|
86
|
+
need exactly one JobPosting on job detail pages can replace the default rule:
|
|
87
|
+
|
|
88
|
+
```ruby
|
|
89
|
+
Crawlscope.configure do |config|
|
|
90
|
+
config.rule_registry = -> {
|
|
91
|
+
registry = Crawlscope::RuleRegistry.default(site_name: config.site_name)
|
|
92
|
+
rules = registry.rules.map do |rule|
|
|
93
|
+
if rule.code == :structured_data
|
|
94
|
+
Crawlscope::Rules::StructuredData.new(job_posting_path: %r{/careers/[^/]+/?\z})
|
|
95
|
+
else
|
|
96
|
+
rule
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
Crawlscope::RuleRegistry.new(rules: rules, default_codes: registry.default_codes)
|
|
100
|
+
}
|
|
101
|
+
end
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Use your application's actual job path pattern. The former
|
|
105
|
+
`Rules::StructuredData::CAREER_DETAIL_PATH` constant is removed; pass the pattern
|
|
106
|
+
directly when constructing the rule.
|
|
107
|
+
|
|
108
|
+
Existing `Crawl`, `Reporter`, rule entry points, issue fields, and
|
|
109
|
+
`StructuredData::Audit::Page` / `Outcome` constructors remain available.
|
|
110
|
+
Internal responsibilities now live under `Crawling`, `Documents`, `Reporting`,
|
|
111
|
+
and `Rules::Links`; see [architecture](docs/architecture.md) for extension points.
|
|
112
|
+
|
|
113
|
+
### Images missing alt attributes
|
|
114
|
+
|
|
115
|
+
The default `content_quality` rule now emits one `missing_image_alt` warning per
|
|
116
|
+
HTML page containing `<img>` elements without an `alt` attribute. Empty
|
|
117
|
+
`alt=""` attributes remain valid for decorative images. Details include `count`
|
|
118
|
+
and `image_sources`; text reports list the affected image sources.
|
|
119
|
+
|
|
120
|
+
No host configuration changes are required. Applications that count warnings or
|
|
121
|
+
fail crawls on warnings should expect this additional check. Add appropriate alt
|
|
122
|
+
text to informative images or `alt=""` to decorative images to resolve warnings.
|
|
123
|
+
|
|
40
124
|
### Query links retain their own URL identity
|
|
41
125
|
|
|
42
126
|
URL normalization now preserves query strings and still removes fragments.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
Crawlscope separates fetching, document interpretation, audit policy, and
|
|
4
|
+
presentation. Public entry points remain small coordinators. The directories
|
|
5
|
+
below contain the collaborators they use:
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
lib/crawlscope/
|
|
9
|
+
crawling/
|
|
10
|
+
fetcher_factory.rb HTTP/browser construction and browser load errors
|
|
11
|
+
target_resolver.rb URL normalization, page reuse, and target caching
|
|
12
|
+
target.rb Resolved target status and indexability
|
|
13
|
+
documents/
|
|
14
|
+
canonical.rb Canonical href extraction and URL resolution
|
|
15
|
+
robots.rb Shared robots directive interpretation
|
|
16
|
+
reporting/
|
|
17
|
+
issue_presenter.rb Issue headings, rows, evidence, and measurements
|
|
18
|
+
url_formatter.rb URL display that preserves origin and query identity
|
|
19
|
+
rules/
|
|
20
|
+
links.rb Public links rule; assembles one invocation
|
|
21
|
+
links/
|
|
22
|
+
extractor.rb Internal anchor extraction
|
|
23
|
+
scope.rb Shared link inclusion policy
|
|
24
|
+
target_lookup.rb Per-invocation target lookup and batch resolution
|
|
25
|
+
resolution_check.rb Broken and redirected link checks
|
|
26
|
+
graph.rb Inbound counts and source URLs
|
|
27
|
+
inbound_checks.rb Incoming-link policies
|
|
28
|
+
outgoing_checks.rb Outgoing-link and discovered sitemap policies
|
|
29
|
+
canonical_checks.rb Canonical target status and inbound-link policies
|
|
30
|
+
url_checks.rb URL hygiene
|
|
31
|
+
structured_data/
|
|
32
|
+
document.rb JSON-LD and microdata extraction
|
|
33
|
+
validator.rb Shared parse, type-presence, and schema validation
|
|
34
|
+
entry.rb Per-URL outcome and failure classification
|
|
35
|
+
outcome.rb Overall success derived from entries
|
|
36
|
+
audit.rb Fetches direct URLs and adapts validation findings
|
|
37
|
+
report.rb Summary selection and JSON serialization
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`Configuration` selects rules and runtime settings. `Run` invokes an audit and
|
|
41
|
+
its reporter. `Crawl` coordinates sitemap expansion, fetching, response checks,
|
|
42
|
+
and rule execution; `Crawling::TargetResolver` supplies rules with cached target
|
|
43
|
+
resolution through the existing `Context` protocol.
|
|
44
|
+
|
|
45
|
+
The links rule creates its collaborators for each call. A reused rule instance
|
|
46
|
+
does not retain a previous crawl's resolver or target cache. `Graph` indexes
|
|
47
|
+
resolved incoming links once, excludes self-links and noindex targets, and
|
|
48
|
+
retains full URL identity. Inbound and canonical checks ask the same graph for
|
|
49
|
+
counts instead of maintaining separate counting algorithms. Path inclusion
|
|
50
|
+
policy lives in `Scope`.
|
|
51
|
+
|
|
52
|
+
Both structured-data entry points use `StructuredData::Validator`. It returns
|
|
53
|
+
items and findings without writing output or choosing command exit status.
|
|
54
|
+
`Rules::StructuredData` translates findings into the sitemap audit's existing
|
|
55
|
+
warning issues. `StructuredData::Audit` translates them into direct-URL entries.
|
|
56
|
+
Host path requirements belong in explicit rule configuration.
|
|
57
|
+
|
|
58
|
+
`StructuredData::Entry` owns failure classification: fetch failure, missing
|
|
59
|
+
markup, validation failure, or success. `Outcome#ok?` and summary categories use
|
|
60
|
+
that classification. The legacy `Audit::Page` and `Audit::Outcome` constants are
|
|
61
|
+
aliases, preserving their constructors and fields.
|
|
62
|
+
|
|
63
|
+
`Reporter` owns text layout and ordering; `Reporting::IssuePresenter` formats
|
|
64
|
+
one issue without performing I/O. `Reporting::UrlFormatter` is shared by crawl
|
|
65
|
+
and timing reports. Structured-data errors use the same `ErrorFormatter` in
|
|
66
|
+
both audit reports. Existing `Issue#message` values remain available to API
|
|
67
|
+
consumers; presenters use structured evidence for richer text rows.
|
|
68
|
+
|
|
69
|
+
When adding a check, put document interpretation in a shared document object,
|
|
70
|
+
policy in a rule, and text formatting in a presenter. Keep network access behind
|
|
71
|
+
the fetcher and resolver interfaces. Add behavior tests at the public rule or
|
|
72
|
+
command boundary; use direct collaborator tests for policies that need their
|
|
73
|
+
own examples. Run `bundle exec rake verify` before handing off changes.
|
data/docs/link-map.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# Internal link map
|
|
2
|
+
|
|
3
|
+
Use `link-map` to see where internal links appear, which pages have a verified
|
|
4
|
+
path from an entry root, and where observed links differ from your site's
|
|
5
|
+
manifest. The standalone command reads public HTML over HTTP and has its own
|
|
6
|
+
exit status. Validation prints a summary from the pages it already fetched.
|
|
7
|
+
|
|
8
|
+
## CLI
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
bundle exec crawlscope link-map --url https://www.example.com > before.json
|
|
12
|
+
bundle exec crawlscope link-map --url https://www.example.com \
|
|
13
|
+
--inventory search-console.csv --manifest links.json --root / --root /guides/ \
|
|
14
|
+
--view contextual --cluster onboarding --priority --format csv --table pairs
|
|
15
|
+
bundle exec crawlscope link-map --url https://www.example.com \
|
|
16
|
+
--follow-limit 200 --follow-depth 3 --exclude-path /account > discovered.json
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Supply the public site origin with `--url` or `URL`. The default sitemap is
|
|
20
|
+
`/sitemap.xml`. Use `--sitemap` or `SITEMAP` for a local file or a same-origin
|
|
21
|
+
sitemap URL. A local sitemap index reads child files from its own directory
|
|
22
|
+
tree. A remote index reads same-origin child URLs. Sitemap and robots requests
|
|
23
|
+
are crawl control files and can be outside the configured page path prefixes.
|
|
24
|
+
Use direct URLs for these files, since the command needs a response at the
|
|
25
|
+
specified sitemap URL and at `/robots.txt`.
|
|
26
|
+
|
|
27
|
+
Inventory accepts one URL per line or a UTF-8 CSV with a `URL`, `Page`,
|
|
28
|
+
`Pages`, or `Top pages` header. The inventory and manifest annotate the graph.
|
|
29
|
+
To fetch an inventory URL outside the sitemap, include it as an entry root or
|
|
30
|
+
enable link following and reach it through an observed link.
|
|
31
|
+
|
|
32
|
+
JSON contains nodes, individual link occurrences, unique directed
|
|
33
|
+
source–target pairs, expected edges, unrooted clusters, coverage exclusions,
|
|
34
|
+
and structured issues. Use `--format text` for a console summary with export
|
|
35
|
+
commands. CSV exports one table at a time. Choose `nodes`,
|
|
36
|
+
`occurrences`, `pairs`, `expected_edges`, or `issues`. Array and object fields use
|
|
37
|
+
JSON within their CSV cells. Spreadsheet formula prefixes are escaped in CSV.
|
|
38
|
+
A completed report returns status 0 even when it contains diagnostics or
|
|
39
|
+
partial coverage. Invalid configuration or an unreadable root sitemap returns 1.
|
|
40
|
+
|
|
41
|
+
## Rake and validation summary
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
bundle exec rake crawlscope:link_map URL=https://www.example.com > link-map.json
|
|
45
|
+
bundle exec rake 'crawlscope:link_map[https://www.example.com,sitemap.xml,csv,nodes]' > nodes.csv
|
|
46
|
+
bundle exec rake 'crawlscope:link_map[,,text]' URL=https://www.example.com
|
|
47
|
+
bundle exec rake crawlscope:validate URL=https://www.example.com
|
|
48
|
+
bundle exec crawlscope link-map --url https://www.example.com --format text
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The export task also works with `bin/rails crawlscope:link_map` and uses the host
|
|
52
|
+
configuration. Validation prints a link map summary by default, including
|
|
53
|
+
reachability, missing coverage, unique link pairs, contextual inlink gaps,
|
|
54
|
+
and commands for exporting JSON, CSV, DOT, and rendering SVG with Graphviz.
|
|
55
|
+
Rake runs show Rake export commands. CLI runs show CLI export commands.
|
|
56
|
+
The summary reuses the sitemap pages already fetched by validation, including
|
|
57
|
+
browser-rendered HTML when enabled. If validation did not fetch the entry
|
|
58
|
+
root, the summary flags the missing coverage. Standalone exports use their
|
|
59
|
+
own public HTTP crawl and can start at the entry root even when it is absent
|
|
60
|
+
from the sitemap. Validation issues determine the exit status. Use
|
|
61
|
+
`--no-link-map` on the CLI or `LINK_MAP=0` with Rake to hide the section.
|
|
62
|
+
|
|
63
|
+
## Coverage and limits
|
|
64
|
+
|
|
65
|
+
- Every occurrence has its source, href with query and fragment removed,
|
|
66
|
+
normalized target, anchor text, image alt text, recognized `rel` values, and
|
|
67
|
+
position. A pair lists counts for all, contextual, and followable occurrences
|
|
68
|
+
between the same URLs. Contextual means an anchor inside `main`, `article`, or a
|
|
69
|
+
main landmark outside a navigation, footer, or sidebar landmark. Unmarked
|
|
70
|
+
links have position `unknown` in the all-link view. Inbound source counts
|
|
71
|
+
exclude links from a page to itself.
|
|
72
|
+
- Click depth is the fewest observed HTML link clicks from any entry root, with
|
|
73
|
+
roots at depth 0. A verified same-origin redirect can connect to its final
|
|
74
|
+
HTML response at the same depth. Link and page-level `nofollow` stay in the
|
|
75
|
+
report and are excluded from traversal. A `noindex` HTML page can still be
|
|
76
|
+
reachable. Indexability reflects the observed HTTP response, HTML, canonical,
|
|
77
|
+
and noindex directives. Coverage marked `unobserved`, `fetch_failed`,
|
|
78
|
+
`robots_disallowed`, `robots_unavailable`, or `page_limit` is partial evidence.
|
|
79
|
+
- `sitemap_reached` and `inventory_reached` record observed reachability for
|
|
80
|
+
each membership. A sitemap-only node has neither an observed path from a
|
|
81
|
+
root nor a recorded incoming link. Unreachable clusters group two or more
|
|
82
|
+
fetched HTML pages connected to each other by followable links with no
|
|
83
|
+
observed path from a root. A limit or failed fetch can hide paths. Sitemap
|
|
84
|
+
membership and inventory membership cannot reveal links on pages the crawl
|
|
85
|
+
did not fetch.
|
|
86
|
+
- Default requests cover the sitemap, the configured roots (default `/`), and
|
|
87
|
+
allowed redirects from those URLs. A positive `--follow-limit` adds a
|
|
88
|
+
breadth-first crawl of observed links from the entry roots. `--follow-depth`
|
|
89
|
+
caps which newly linked pages are requested. The total cap on starting page
|
|
90
|
+
requests is `--max-pages` (default 10,000), with up to five redirect hops per
|
|
91
|
+
request. `--max-edges` caps retained occurrences (default 100,000). Pages
|
|
92
|
+
are read in batches with a 5 MiB body limit. `outgoing_complete` is false
|
|
93
|
+
when the occurrence cap cut short a page's extraction. The sitemap reader caps sitemap
|
|
94
|
+
files at 100, distinct sitemap URLs at 100,000, and each sitemap body at 50
|
|
95
|
+
MiB. Exclusions and per-node coverage show where these limits applied.
|
|
96
|
+
- Requests use the explicit origin and allowed path prefixes, including
|
|
97
|
+
redirects. Supply repeated `--path` and `--exclude-path` flags to control the
|
|
98
|
+
public area being audited. Query URLs are excluded from requests and pair
|
|
99
|
+
counts. The export may retain a query-bearing occurrence with a sanitized
|
|
100
|
+
href, no target, and `query` coverage. Credentials, headers, bodies, and
|
|
101
|
+
cross-origin URL values are omitted from artifacts. Use a public origin
|
|
102
|
+
and keep private data out of published paths, anchor text, and manifest
|
|
103
|
+
labels, which are report fields.
|
|
104
|
+
- The command sends no authentication or profiling token. It reads
|
|
105
|
+
`robots.txt` directives for `Crawlscope`, falling back to `*`. The
|
|
106
|
+
longest matching Allow or Disallow rule wins, with Allow winning ties.
|
|
107
|
+
HTTP 404 and 410 indicate an absent policy. Other failures, redirects, and
|
|
108
|
+
invalid or oversized policies prevent page requests. [Robots Exclusion Protocol (RFC 9309)](https://www.rfc-editor.org/rfc/rfc9309.html)
|
|
109
|
+
|
|
110
|
+
## Intended links and a before/after comparison
|
|
111
|
+
|
|
112
|
+
Name priority pages and topic clusters in a host-app manifest, then add the
|
|
113
|
+
specific links you expect:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"pages": {
|
|
118
|
+
"/guides/setup": {"priority": true, "page_type": "guide", "cluster": "onboarding"},
|
|
119
|
+
"/guides/getting-started": {"page_type": "overview", "cluster": "onboarding"}
|
|
120
|
+
},
|
|
121
|
+
"edges": [
|
|
122
|
+
{
|
|
123
|
+
"source": "/guides/getting-started",
|
|
124
|
+
"target": "/guides/setup",
|
|
125
|
+
"type": "next_step",
|
|
126
|
+
"position": "main",
|
|
127
|
+
"reason": "Readers need the setup steps after choosing an installation method."
|
|
128
|
+
}
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
A manifest edge matches its exact normalized source and target URLs, plus
|
|
134
|
+
`position` when supplied. `type` names the intended relationship for reviewers.
|
|
135
|
+
Include an `approved_exception` string to record the reason a missing edge is
|
|
136
|
+
acceptable. An expected link can be observed, missing, excepted, or unknown
|
|
137
|
+
when the source or edge coverage is incomplete.
|
|
138
|
+
|
|
139
|
+
Run the audit with the manifest and save a baseline:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
bundle exec crawlscope link-map --url https://www.example.com --manifest links.json > before.json
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
If `/guides/setup` has
|
|
146
|
+
only a nav link and the report identifies the missing main-content link from
|
|
147
|
+
`/guides/getting-started`, add a descriptive link where that guide introduces
|
|
148
|
+
setup. Use the same roots, inputs, and crawl limits for the second snapshot:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
bundle exec crawlscope link-map --url https://www.example.com --manifest links.json > after.json
|
|
152
|
+
bundle exec crawlscope link-map diff before.json after.json > changes.json
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
In the diff, look for the added pair or occurrence and an expected edge moving from
|
|
156
|
+
`missing` to `observed`. A smaller click depth is only expected when the new
|
|
157
|
+
link shortens the route. The measurements describe the audited HTML. Track
|
|
158
|
+
any impact on visitors and search performance separately.
|
|
159
|
+
|
|
160
|
+
Export DOT and use Graphviz's scalable layout to render the full graph:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
bundle exec crawlscope link-map --url https://www.example.com --format dot > links.dot
|
|
164
|
+
sfdp -Gsplines=line -Tsvg links.dot -o links.svg
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Boxes identify entry roots, dashed outlines identify URLs with no observed
|
|
168
|
+
click depth, and double borders identify priority pages. Edge labels give
|
|
169
|
+
occurrence counts. The `sfdp` engine uses straight edges to keep rendering
|
|
170
|
+
practical for dense graphs. To get a left-to-right diagram of a smaller graph,
|
|
171
|
+
filter by cluster or priority before rendering with
|
|
172
|
+
`dot -Tsvg links.dot -o links.svg`. These filters keep links touching the selected pages and keep the
|
|
173
|
+
neighboring nodes for context. Depth and inbound counts reflect the original
|
|
174
|
+
audit, even when a filter or contextual view hides links.
|
|
175
|
+
|
|
176
|
+
## Ruby and Rails
|
|
177
|
+
|
|
178
|
+
```ruby
|
|
179
|
+
require "crawlscope"
|
|
180
|
+
require "json"
|
|
181
|
+
|
|
182
|
+
report = Crawlscope::Run.new.link_map(
|
|
183
|
+
base_url: "https://www.example.com",
|
|
184
|
+
sitemap_path: "https://www.example.com/sitemap.xml",
|
|
185
|
+
roots: ["/"],
|
|
186
|
+
manifest: JSON.parse(File.read("links.json"))
|
|
187
|
+
)
|
|
188
|
+
report.to_h[:issues]
|
|
189
|
+
File.open("nodes.csv", "w") { |io| report.write(io, format: :csv, table: :nodes) }
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
In a Rails app with the installed initializer, apply it inside a task or
|
|
193
|
+
runner script before calling `Run#link_map`:
|
|
194
|
+
|
|
195
|
+
```ruby
|
|
196
|
+
CrawlscopeConfiguration.apply
|
|
197
|
+
report = Crawlscope::Run.new.link_map
|
|
198
|
+
File.open(Rails.root.join("tmp", "link-map.json"), "w") { |io| report.write(io) }
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
The run uses the configured base URL, sitemap, timeout, concurrency, and fetch
|
|
202
|
+
executor. You can pass audit options directly as keywords. See the Rails
|
|
203
|
+
integration guide for how to configure the initializer. [Rails integration](rails.md)
|
data/docs/rails.md
CHANGED
|
@@ -103,6 +103,15 @@ because async fetch execution is only supported with HTTP rendering.
|
|
|
103
103
|
|
|
104
104
|
`crawlscope:validate:ldjson` is separate because it directly checks the URL or semicolon-separated URLs in `URL`; it does not crawl the sitemap. Without `URL`, it checks the configured base URL, falling back to `http://localhost:3000`.
|
|
105
105
|
|
|
106
|
+
## Internal link map
|
|
107
|
+
|
|
108
|
+
Run `bin/rails crawlscope:link_map` to export JSON using the application's
|
|
109
|
+
sitemap settings. `bin/rails crawlscope:validate` includes the link map
|
|
110
|
+
summary using the pages it already fetched. Set `LINK_MAP=0` to hide the
|
|
111
|
+
summary. In a runner script or task, use
|
|
112
|
+
`Crawlscope::Run.new.link_map` after applying the generated configuration.
|
|
113
|
+
[Link map guide](link-map.md)
|
|
114
|
+
|
|
106
115
|
## Structured Data URL Audit
|
|
107
116
|
|
|
108
117
|
For one-off structured-data checks:
|
data/docs/rules.md
CHANGED
|
@@ -40,6 +40,53 @@ Checks:
|
|
|
40
40
|
- schema validation failures from the configured registry
|
|
41
41
|
- direct URL structured-data audits through `crawlscope:validate:ldjson`
|
|
42
42
|
|
|
43
|
+
Sitemap and direct URL audits share the same document validator, including
|
|
44
|
+
missing `@type` checks. Direct URL audits treat missing markup as a failure;
|
|
45
|
+
sitemap audits retain their warning severity for structured-data findings.
|
|
46
|
+
|
|
47
|
+
### Required types by URL
|
|
48
|
+
|
|
49
|
+
Schema validation checks the markup a page contains. To detect a missing type
|
|
50
|
+
even when other valid markup exists, configure a URL policy:
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
Crawlscope.configure do |config|
|
|
54
|
+
config.required_structured_data_types = ->(url) {
|
|
55
|
+
case URI(url).path
|
|
56
|
+
when %r{\A/guides/[^/]+/?\z}
|
|
57
|
+
[["Article", "BlogPosting", "NewsArticle"]]
|
|
58
|
+
when "/guides"
|
|
59
|
+
["CollectionPage", "ItemList"]
|
|
60
|
+
when %r{/benchmark/?\z}
|
|
61
|
+
["WebPage", "Dataset"]
|
|
62
|
+
else
|
|
63
|
+
[]
|
|
64
|
+
end
|
|
65
|
+
}
|
|
66
|
+
end
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Each string requires that type. A nested array accepts any of its types.
|
|
70
|
+
Return an empty array for URLs without a type requirement. The callback receives
|
|
71
|
+
the full URL; the host owns the route policy and content classification.
|
|
72
|
+
|
|
73
|
+
The default sitemap rule and direct URL audits use this policy. A missing
|
|
74
|
+
requirement produces `structured_data_missing_required_type` in sitemap
|
|
75
|
+
findings and a validation failure in direct audits, including their reports and
|
|
76
|
+
exit status. Top-level items, JSON-LD type arrays and `@graph` nodes count;
|
|
77
|
+
an article linked inside an ItemList does not satisfy an article-page requirement.
|
|
78
|
+
Microdata items also count. Custom rule registries must pass the callback to
|
|
79
|
+
`Rules::StructuredData.new(required_types: callback)` themselves.
|
|
80
|
+
|
|
81
|
+
This checks type presence; the schema registry still validates supported types.
|
|
82
|
+
An index, product page or dataset should not acquire Article markup solely
|
|
83
|
+
because an external crawler classified its prose as an article.
|
|
84
|
+
|
|
85
|
+
Job detail pages can opt into an exactly-one-JobPosting policy with
|
|
86
|
+
`Rules::StructuredData.new(job_posting_path: your_path_pattern)` in a custom
|
|
87
|
+
rule registry. No host route patterns are assumed by default. See
|
|
88
|
+
[UPGRADE](../UPGRADE.md) for an example registry configuration.
|
|
89
|
+
|
|
43
90
|
## Uniqueness
|
|
44
91
|
|
|
45
92
|
Checks:
|
|
@@ -57,6 +104,8 @@ For larger crawls, exact duplicate checks still run and Crawlscope reports
|
|
|
57
104
|
|
|
58
105
|
Checks:
|
|
59
106
|
|
|
107
|
+
- missing `alt` attributes on `<img>` elements throughout the page, including
|
|
108
|
+
headers and footers (empty `alt=""` is allowed for decorative images)
|
|
60
109
|
- thin visible text
|
|
61
110
|
- low visible-text-to-HTML ratio
|
|
62
111
|
- low unique-token ratio
|
data/lib/crawlscope/cli.rb
CHANGED
|
@@ -8,13 +8,14 @@ module Crawlscope
|
|
|
8
8
|
new(argv, out: out, err: err, **options).call
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
def initialize(argv, out:, err:, configuration: Configuration.new, task: nil)
|
|
11
|
+
def initialize(argv, out:, err:, configuration: Configuration.new, task: nil, invocation: :cli)
|
|
12
12
|
@argv = Array(argv).dup
|
|
13
13
|
@out = out
|
|
14
14
|
@err = err
|
|
15
15
|
@configuration = configuration
|
|
16
16
|
@configuration.output = out
|
|
17
17
|
@task = task
|
|
18
|
+
@invocation = invocation
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
def call
|
|
@@ -28,6 +29,8 @@ module Crawlscope
|
|
|
28
29
|
run_validate
|
|
29
30
|
when "ldjson"
|
|
30
31
|
run_ldjson
|
|
32
|
+
when "link-map"
|
|
33
|
+
run_link_map
|
|
31
34
|
when "version", "--version", "-v"
|
|
32
35
|
@out.puts(Crawlscope::VERSION)
|
|
33
36
|
0
|
|
@@ -37,7 +40,7 @@ module Crawlscope
|
|
|
37
40
|
@err.puts(general_usage)
|
|
38
41
|
1
|
|
39
42
|
end
|
|
40
|
-
rescue OptionParser::
|
|
43
|
+
rescue OptionParser::ParseError, ConfigurationError, ArgumentError => error
|
|
41
44
|
@err.puts(error.message)
|
|
42
45
|
@err.puts("")
|
|
43
46
|
@err.puts(general_usage)
|
|
@@ -54,15 +57,88 @@ module Crawlscope
|
|
|
54
57
|
Usage:
|
|
55
58
|
crawlscope validate --url https://example.com [options]
|
|
56
59
|
crawlscope ldjson --url https://example.com/page [options]
|
|
60
|
+
crawlscope link-map --url https://example.com [options]
|
|
61
|
+
crawlscope link-map diff BEFORE.json AFTER.json
|
|
57
62
|
crawlscope version
|
|
58
63
|
|
|
59
64
|
Commands:
|
|
60
65
|
validate Audit URLs for metadata, structured data, uniqueness, and links
|
|
61
66
|
ldjson Validate structured data on one or more URLs
|
|
67
|
+
link-map Inspect and compare internal link graphs
|
|
62
68
|
version Print the gem version
|
|
63
69
|
TEXT
|
|
64
70
|
end
|
|
65
71
|
|
|
72
|
+
def run_link_map
|
|
73
|
+
return diff_link_maps if @argv.first == "diff"
|
|
74
|
+
|
|
75
|
+
options = {base_url: normalized_string(ENV["URL"]), sitemap_path: normalized_string(ENV["SITEMAP"])}
|
|
76
|
+
output = {}
|
|
77
|
+
manifest_path = inventory_path = nil
|
|
78
|
+
|
|
79
|
+
parser = OptionParser.new do |opts|
|
|
80
|
+
opts.banner = "Usage: crawlscope link-map --url https://example.com [options]"
|
|
81
|
+
opts.on("--url URL", "Site origin") { |value| options[:base_url] = value }
|
|
82
|
+
opts.on("--sitemap PATH_OR_URL", "Local or same-origin sitemap") { |value| options[:sitemap_path] = value }
|
|
83
|
+
opts.on("--root URL", "Entry root (repeatable, default /)") { |value| (options[:roots] ||= []) << value }
|
|
84
|
+
opts.on("--path PREFIX", "Allowed path prefix (repeatable)") { |value| (options[:paths] ||= []) << value }
|
|
85
|
+
opts.on("--exclude-path PREFIX", "Excluded path prefix (repeatable)") { |value| (options[:exclude_paths] ||= []) << value }
|
|
86
|
+
opts.on("--inventory PATH", "Additional URLs, one per line or in a CSV URL column") { |value| inventory_path = value }
|
|
87
|
+
opts.on("--manifest PATH", "Expected links and page metadata as JSON") { |value| manifest_path = value }
|
|
88
|
+
opts.on("--max-pages COUNT", Integer, "Cap starting page requests") { |value| options[:max_pages] = value }
|
|
89
|
+
opts.on("--max-edges COUNT", Integer, "Cap stored link occurrences") { |value| options[:max_edges] = value }
|
|
90
|
+
opts.on("--follow-limit COUNT", Integer, "Maximum additional link-discovered pages") { |value| options[:follow_limit] = value }
|
|
91
|
+
opts.on("--follow-depth COUNT", Integer, "Deepest newly discovered page to fetch") { |value| options[:follow_depth] = value }
|
|
92
|
+
opts.on("--format FORMAT", %w[json csv dot text], "Output format (default json)") { |value| output[:format] = value }
|
|
93
|
+
opts.on("--table TABLE", %w[nodes occurrences pairs expected_edges issues], "CSV table (default occurrences)") { |value| output[:table] = value }
|
|
94
|
+
opts.on("--view VIEW", %w[all contextual], "Link view (default all)") { |value| output[:view] = value }
|
|
95
|
+
opts.on("--cluster NAME", "Show links involving this topic cluster") { |value| output[:cluster] = value }
|
|
96
|
+
opts.on("--priority", "Show links involving priority pages") { output[:priority] = true }
|
|
97
|
+
opts.on("-h", "--help", "Show link-map options") do
|
|
98
|
+
@out.puts(opts)
|
|
99
|
+
return 0
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
parser.parse!(@argv)
|
|
103
|
+
raise ConfigurationError, "Unexpected link map arguments" unless @argv.empty?
|
|
104
|
+
|
|
105
|
+
options[:manifest] = read_link_map_json(manifest_path) if manifest_path
|
|
106
|
+
options[:inventory] = read_link_map_inventory(inventory_path) if inventory_path
|
|
107
|
+
task.link_map(**options).write(@out, sitemap_path: options[:sitemap_path] || @configuration.sitemap_path, invocation: @invocation, **output)
|
|
108
|
+
0
|
|
109
|
+
rescue SystemCallError
|
|
110
|
+
raise ConfigurationError, "Unable to read link map input"
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def diff_link_maps
|
|
114
|
+
@argv.shift
|
|
115
|
+
raise ConfigurationError, "Usage: crawlscope link-map diff BEFORE.json AFTER.json" unless @argv.size == 2
|
|
116
|
+
|
|
117
|
+
before, after = @argv.map { |path| read_link_map_json(path) }
|
|
118
|
+
@out.puts(JSON.generate(LinkMap::Report.diff(before, after)))
|
|
119
|
+
0
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def read_link_map_json(path)
|
|
123
|
+
require "json"
|
|
124
|
+
JSON.parse(File.read(path))
|
|
125
|
+
rescue JSON::ParserError, SystemCallError
|
|
126
|
+
raise ConfigurationError, "Unable to read link map JSON input"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def read_link_map_inventory(path)
|
|
130
|
+
return File.readlines(path, chomp: true).map(&:strip).reject(&:empty?) unless File.extname(path).casecmp?(".csv")
|
|
131
|
+
|
|
132
|
+
require "csv"
|
|
133
|
+
csv = CSV.read(path, headers: true, encoding: "bom|utf-8")
|
|
134
|
+
header = csv.headers.find { |name| %w[url page pages].include?(name.to_s.strip.downcase) || name.to_s.strip.casecmp?("top pages") }
|
|
135
|
+
raise ConfigurationError, "Link map inventory CSV needs a URL, Page, or Top pages header" unless header
|
|
136
|
+
|
|
137
|
+
csv[header].compact.map(&:strip).reject(&:empty?)
|
|
138
|
+
rescue CSV::MalformedCSVError
|
|
139
|
+
raise ConfigurationError, "Unable to read link map inventory CSV"
|
|
140
|
+
end
|
|
141
|
+
|
|
66
142
|
def run_ldjson
|
|
67
143
|
options = {
|
|
68
144
|
debug: env_enabled?("DEBUG"),
|
|
@@ -127,6 +203,7 @@ module Crawlscope
|
|
|
127
203
|
|
|
128
204
|
def run_validate
|
|
129
205
|
options = {
|
|
206
|
+
link_map: ENV["LINK_MAP"] != "0",
|
|
130
207
|
url: normalized_string(ENV["URL"]),
|
|
131
208
|
rule_names: normalized_string(ENV["RULES"]),
|
|
132
209
|
sitemap_path: normalized_string(ENV["SITEMAP"])
|
|
@@ -154,6 +231,10 @@ module Crawlscope
|
|
|
154
231
|
options[:rule_names] = value
|
|
155
232
|
end
|
|
156
233
|
|
|
234
|
+
opts.on("--[no-]link-map", "Show the link map from validation pages (default on)") do |value|
|
|
235
|
+
options[:link_map] = value
|
|
236
|
+
end
|
|
237
|
+
|
|
157
238
|
opts.on("--renderer NAME", "Use http or browser rendering") do |value|
|
|
158
239
|
configure_renderer(value.to_sym)
|
|
159
240
|
end
|
|
@@ -179,7 +260,7 @@ module Crawlscope
|
|
|
179
260
|
parser.parse!(@argv)
|
|
180
261
|
@configuration.fetch_executor = :threaded if @configuration.renderer == :browser && !fetch_executor_configured
|
|
181
262
|
|
|
182
|
-
result = task.validate(
|
|
263
|
+
result = task(link_map: options[:link_map]).validate(
|
|
183
264
|
base_url: options[:url],
|
|
184
265
|
sitemap_path: options[:sitemap_path],
|
|
185
266
|
rule_names: options[:rule_names]
|
|
@@ -262,8 +343,8 @@ module Crawlscope
|
|
|
262
343
|
[normalized_string(@configuration.base_url) || "http://localhost:3000"]
|
|
263
344
|
end
|
|
264
345
|
|
|
265
|
-
def task
|
|
266
|
-
@task ||= Run.new(configuration: @configuration, reporter: Reporter.new(io: @out))
|
|
346
|
+
def task(link_map: true)
|
|
347
|
+
@task ||= Run.new(configuration: @configuration, reporter: Reporter.new(io: @out, link_map: link_map, invocation: @invocation))
|
|
267
348
|
end
|
|
268
349
|
end
|
|
269
350
|
end
|