omnirank 0.5.0__py3-none-any.whl
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.
- omnirank/__init__.py +14 -0
- omnirank/__main__.py +6 -0
- omnirank/adapters/__init__.py +202 -0
- omnirank/adapters/astro.py +338 -0
- omnirank/adapters/base.py +372 -0
- omnirank/adapters/html.py +561 -0
- omnirank/adapters/jsx.py +340 -0
- omnirank/adapters/nextjs.py +692 -0
- omnirank/aeo/__init__.py +9 -0
- omnirank/aeo/extract.py +383 -0
- omnirank/aeo/propose.py +84 -0
- omnirank/aeo/rules.py +964 -0
- omnirank/aeo/runner.py +148 -0
- omnirank/applicability.py +98 -0
- omnirank/apply/__init__.py +23 -0
- omnirank/apply/engine.py +1254 -0
- omnirank/apply/journal.py +139 -0
- omnirank/apply/patch.py +144 -0
- omnirank/audit.py +185 -0
- omnirank/bands.py +106 -0
- omnirank/brief/__init__.py +0 -0
- omnirank/brief/analyze.py +197 -0
- omnirank/brief/constants.py +89 -0
- omnirank/brief/cost.py +62 -0
- omnirank/brief/egress.py +23 -0
- omnirank/brief/fetchpages.py +239 -0
- omnirank/brief/render.py +151 -0
- omnirank/brief/runner.py +369 -0
- omnirank/brief/serp.py +274 -0
- omnirank/brief/text.py +181 -0
- omnirank/cli.py +844 -0
- omnirank/clock.py +22 -0
- omnirank/cms/__init__.py +1 -0
- omnirank/cms/runner.py +170 -0
- omnirank/cms/wordpress.py +495 -0
- omnirank/cms/wordpress_apply.py +508 -0
- omnirank/cms/wordpress_plan.py +280 -0
- omnirank/config.py +81 -0
- omnirank/connect/__init__.py +4 -0
- omnirank/connect/bing.py +284 -0
- omnirank/connect/cloud_setup.py +43 -0
- omnirank/connect/confirm.py +242 -0
- omnirank/connect/constants.py +226 -0
- omnirank/connect/doctor.py +270 -0
- omnirank/connect/ga4.py +749 -0
- omnirank/connect/ga4_ai.py +123 -0
- omnirank/connect/google_auth.py +657 -0
- omnirank/connect/gsc.py +630 -0
- omnirank/connect/gsc_reports.py +169 -0
- omnirank/connect/http.py +310 -0
- omnirank/connect/indexnow.py +373 -0
- omnirank/connect/naver.py +536 -0
- omnirank/connect/runner.py +515 -0
- omnirank/connect/runner_ga4_ai.py +59 -0
- omnirank/connect/runner_more.py +489 -0
- omnirank/connect/runner_regional.py +260 -0
- omnirank/connect/secrets.py +190 -0
- omnirank/connect/urlcheck.py +41 -0
- omnirank/connect/yandex.py +350 -0
- omnirank/crawl/__init__.py +11 -0
- omnirank/crawl/analyze.py +493 -0
- omnirank/crawl/crawler.py +491 -0
- omnirank/crawl/custom.py +175 -0
- omnirank/crawl/export.py +67 -0
- omnirank/crawl/fetcher.py +212 -0
- omnirank/crawl/parse.py +102 -0
- omnirank/crawl/render.py +148 -0
- omnirank/crawl/robotsgate.py +198 -0
- omnirank/crawl/runner.py +295 -0
- omnirank/crawl/sitemap.py +99 -0
- omnirank/crawl/text.py +20 -0
- omnirank/crawl/urls.py +100 -0
- omnirank/crawlers.py +564 -0
- omnirank/data/ai_crawlers.json +269 -0
- omnirank/data/ai_referrers.json +42 -0
- omnirank/fetch.py +107 -0
- omnirank/fixes/__init__.py +92 -0
- omnirank/fixes/base.py +232 -0
- omnirank/fixes/canonical.py +243 -0
- omnirank/fixes/schema.py +126 -0
- omnirank/formats.py +134 -0
- omnirank/framework.py +223 -0
- omnirank/gates/__init__.py +48 -0
- omnirank/gates/aeo.py +114 -0
- omnirank/gates/contradictions.py +280 -0
- omnirank/gates/crawler_policy.py +85 -0
- omnirank/gates/geo.py +152 -0
- omnirank/gates/hygiene.py +81 -0
- omnirank/gates/jsonld.py +282 -0
- omnirank/gates/onpage.py +177 -0
- omnirank/gates/perf.py +115 -0
- omnirank/gates/security.py +264 -0
- omnirank/gates/seo.py +118 -0
- omnirank/gates/site.py +248 -0
- omnirank/geo_artifacts.py +199 -0
- omnirank/html.py +79 -0
- omnirank/keywords/__init__.py +5 -0
- omnirank/keywords/constants.py +69 -0
- omnirank/keywords/engine.py +384 -0
- omnirank/keywords/report.py +143 -0
- omnirank/keywords/runner.py +160 -0
- omnirank/keywords/source.py +60 -0
- omnirank/keywords/text.py +45 -0
- omnirank/locator.py +480 -0
- omnirank/logs/__init__.py +0 -0
- omnirank/logs/analyze.py +127 -0
- omnirank/logs/bots.py +69 -0
- omnirank/logs/ipranges.py +191 -0
- omnirank/logs/parse.py +452 -0
- omnirank/logs/paths.py +22 -0
- omnirank/logs/privacy.py +105 -0
- omnirank/logs/runner.py +179 -0
- omnirank/mcp_server.py +1480 -0
- omnirank/netguard.py +525 -0
- omnirank/packs/__init__.py +6 -0
- omnirank/packs/backlinks.py +535 -0
- omnirank/packs/blog.py +544 -0
- omnirank/packs/blog_cross.py +468 -0
- omnirank/packs/crawlers.py +23 -0
- omnirank/packs/entity.py +492 -0
- omnirank/packs/feeds.py +150 -0
- omnirank/packs/frontmatter.py +59 -0
- omnirank/packs/gsc.py +421 -0
- omnirank/packs/local.py +879 -0
- omnirank/packs/mdscan.py +326 -0
- omnirank/packs/miniyaml.py +378 -0
- omnirank/packs/model.py +46 -0
- omnirank/packs/product.py +979 -0
- omnirank/packs/refresh.py +165 -0
- omnirank/packs/runner.py +277 -0
- omnirank/packs/sitescan.py +294 -0
- omnirank/packs/textsafe.py +79 -0
- omnirank/packs/xmlsafe.py +92 -0
- omnirank/page.py +42 -0
- omnirank/registry.py +302 -0
- omnirank/report.py +251 -0
- omnirank/report_cmd/__init__.py +7 -0
- omnirank/report_cmd/delta.py +58 -0
- omnirank/report_cmd/files.py +64 -0
- omnirank/report_cmd/model.py +208 -0
- omnirank/report_cmd/notify.py +195 -0
- omnirank/report_cmd/pdf.py +83 -0
- omnirank/report_cmd/portfolio.py +342 -0
- omnirank/report_cmd/render.py +379 -0
- omnirank/report_cmd/runner.py +267 -0
- omnirank/robots.py +172 -0
- omnirank/scanner/__init__.py +10 -0
- omnirank/scanner/badge.py +90 -0
- omnirank/scanner/cache.py +69 -0
- omnirank/scanner/cli.py +96 -0
- omnirank/scanner/engine.py +289 -0
- omnirank/scanner/limits.py +98 -0
- omnirank/scanner/server.py +143 -0
- omnirank/scanner/service.py +328 -0
- omnirank/schema/__init__.py +13 -0
- omnirank/schema/catalog.py +679 -0
- omnirank/schema/catalog_specs.py +350 -0
- omnirank/schema/core.py +306 -0
- omnirank/schema/extract.py +396 -0
- omnirank/schema/gate.py +121 -0
- omnirank/schema/runner.py +213 -0
- omnirank/schema/validate.py +504 -0
- omnirank/schema/vocab.py +305 -0
- omnirank/schemas/omnirank.config.schema.json +268 -0
- omnirank/track/__init__.py +0 -0
- omnirank/track/ai_prompts.py +207 -0
- omnirank/track/analysis.py +197 -0
- omnirank/track/constants.py +155 -0
- omnirank/track/cost.py +229 -0
- omnirank/track/discover.py +277 -0
- omnirank/track/discover_cli.py +309 -0
- omnirank/track/discover_constants.py +95 -0
- omnirank/track/engines.py +216 -0
- omnirank/track/estimate_view.py +212 -0
- omnirank/track/history.py +261 -0
- omnirank/track/runner.py +586 -0
- omnirank/track/stats.py +138 -0
- omnirank/track/storage.py +128 -0
- omnirank-0.5.0.dist-info/METADATA +47 -0
- omnirank-0.5.0.dist-info/RECORD +183 -0
- omnirank-0.5.0.dist-info/WHEEL +5 -0
- omnirank-0.5.0.dist-info/entry_points.txt +2 -0
- omnirank-0.5.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"""Defects provable from the site's OWN declarations, with no external truth.
|
|
2
|
+
|
|
3
|
+
The category `docs/research/2026-08-04-competitive-gap-analysis.md` SS1 identifies
|
|
4
|
+
as the one OmniRank can credibly own: a URL submitted for crawling in the sitemap
|
|
5
|
+
and forbidden in robots.txt; a canonical pointing at a page that is noindexed, that
|
|
6
|
+
redirects, or that 404s; a page declared as an hreflang alternate while forbidding
|
|
7
|
+
its own indexing. Every one is 100% precision because both halves of the
|
|
8
|
+
contradiction come from the site itself.
|
|
9
|
+
|
|
10
|
+
Two rules govern every function here, and both are load-bearing:
|
|
11
|
+
|
|
12
|
+
1. Never judge a URL OmniRank did not see. A target outside the crawled set is
|
|
13
|
+
either probed (bounded, deduplicated) or left unjudged -- never guessed at.
|
|
14
|
+
2. A gate that could not run returns a NotEvaluated entry, never silence. Silence
|
|
15
|
+
is indistinguishable from a pass in the report, which is the failure this
|
|
16
|
+
project exists to refuse.
|
|
17
|
+
|
|
18
|
+
Like `hygiene`, this module has no `run()`: its three checks take genuinely
|
|
19
|
+
different inputs (robots text, the crawled set, probed targets), and a single
|
|
20
|
+
entry point would have to take all of them.
|
|
21
|
+
"""
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
from urllib.parse import urlsplit
|
|
25
|
+
|
|
26
|
+
import httpx
|
|
27
|
+
|
|
28
|
+
from .. import robots
|
|
29
|
+
from ..fetch import Fetched, fetch
|
|
30
|
+
from ..page import PageData
|
|
31
|
+
from ..report import Finding, NotEvaluated
|
|
32
|
+
from . import site
|
|
33
|
+
|
|
34
|
+
GATE_ROBOTS_SITEMAP = "robots-sitemap"
|
|
35
|
+
GATE_CANONICAL_TARGET = "canonical-target"
|
|
36
|
+
GATE_HREFLANG_NOINDEX = "hreflang-noindex"
|
|
37
|
+
|
|
38
|
+
# How many canonical targets outside the crawled set OmniRank will fetch in one
|
|
39
|
+
# audit. A cap rather than an unbounded pass: a 200-page site whose every canonical
|
|
40
|
+
# points at an uncrawled URL would otherwise double the audit's request count
|
|
41
|
+
# without warning. Targets past the cap are reported as budget-exceeded, never
|
|
42
|
+
# skipped silently.
|
|
43
|
+
MAX_CANONICAL_PROBES = 25
|
|
44
|
+
|
|
45
|
+
_MATCHER_LIMITATION = {
|
|
46
|
+
robots.UNSUPPORTED_WILDCARDS:
|
|
47
|
+
"the published rules use path wildcards (* or $)",
|
|
48
|
+
robots.UNSUPPORTED_LONGEST_MATCH:
|
|
49
|
+
"the published rules pair an Allow with an overlapping Disallow",
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _f(id_: str, gate: str, url: str, severity: str, observed: str,
|
|
54
|
+
expected: str, fix: str) -> Finding:
|
|
55
|
+
return Finding(id=id_, severity=severity, layer="seo", url=url, gate=gate,
|
|
56
|
+
observed=observed, expected=expected, fix=fix)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def check_sitemap_vs_robots(
|
|
60
|
+
client: httpx.Client, site_url: str, sitemap_urls: list[str] | None,
|
|
61
|
+
) -> tuple[list[Finding], list[NotEvaluated]]:
|
|
62
|
+
"""Sitemap URLs that the site's own robots.txt forbids crawling.
|
|
63
|
+
|
|
64
|
+
The same class of self-contradiction as `seo.noindex.in-sitemap`, and rated the
|
|
65
|
+
same: the site submits a URL for crawling in one file and forbids it in
|
|
66
|
+
another, so one of the two declarations is wrong and no external data is needed
|
|
67
|
+
to know that.
|
|
68
|
+
|
|
69
|
+
Returns no verdict at all when robots.txt is unreachable, when there is no
|
|
70
|
+
sitemap, or when this interpreter's matcher cannot evaluate the rules the site
|
|
71
|
+
actually published -- see omnirank/robots.py for why the last one is real.
|
|
72
|
+
|
|
73
|
+
Only sitemap URLs on robots.txt's OWN host are judged against it.
|
|
74
|
+
`RobotFileParser.can_fetch()` discards the host and matches on path alone, so
|
|
75
|
+
passing it a cross-host URL would judge that URL by a robots.txt that never
|
|
76
|
+
governed it -- a sitemap index legitimately listing `blog.`/`cdn.` URLs would
|
|
77
|
+
otherwise get those paths judged by the audited host's rules and produce a
|
|
78
|
+
fabricated finding. Off-host URLs are reported `not-applicable` instead of
|
|
79
|
+
silently dropped.
|
|
80
|
+
"""
|
|
81
|
+
site_url = site_url.rstrip("/")
|
|
82
|
+
if not sitemap_urls:
|
|
83
|
+
return [], [NotEvaluated(gate=GATE_ROBOTS_SITEMAP, site=site_url,
|
|
84
|
+
reason="no-sitemap")]
|
|
85
|
+
|
|
86
|
+
robots_url = f"{site_url}/robots.txt"
|
|
87
|
+
result = fetch(client, robots_url)
|
|
88
|
+
if not result.ok:
|
|
89
|
+
return [], [NotEvaluated(gate=GATE_ROBOTS_SITEMAP, url=robots_url,
|
|
90
|
+
reason="page-unreachable")]
|
|
91
|
+
|
|
92
|
+
host = urlsplit(robots_url).netloc
|
|
93
|
+
same_host = [u for u in sitemap_urls if urlsplit(u).netloc == host]
|
|
94
|
+
off_host_not_evaluated = [
|
|
95
|
+
NotEvaluated(gate=GATE_ROBOTS_SITEMAP, url=u, reason="not-applicable")
|
|
96
|
+
for u in sitemap_urls if urlsplit(u).netloc != host
|
|
97
|
+
]
|
|
98
|
+
if not same_host:
|
|
99
|
+
return [], off_host_not_evaluated
|
|
100
|
+
|
|
101
|
+
verdict = robots.disallowed_urls(result.text, same_host)
|
|
102
|
+
if not verdict.evaluated:
|
|
103
|
+
return [], off_host_not_evaluated + [NotEvaluated(
|
|
104
|
+
gate=GATE_ROBOTS_SITEMAP, url=robots_url, reason="matcher-unsupported")]
|
|
105
|
+
|
|
106
|
+
findings = [
|
|
107
|
+
_f("seo.robots-sitemap.disallowed", GATE_ROBOTS_SITEMAP, url, "error",
|
|
108
|
+
f"listed in sitemap.xml, and Disallow-ed to {robots.DEFAULT_AGENT} "
|
|
109
|
+
f"by {robots_url}",
|
|
110
|
+
"either crawlable and listed, or disallowed and unlisted",
|
|
111
|
+
"Remove the Disallow rule in robots.txt, or drop this URL from the "
|
|
112
|
+
"sitemap. Submitting a URL for crawling while forbidding the crawl is a "
|
|
113
|
+
"contradiction the site makes with itself: engines waste budget "
|
|
114
|
+
"discovering a URL they are then not permitted to fetch. Only you know "
|
|
115
|
+
"which of the two declarations is the intended one.")
|
|
116
|
+
for url in verdict.disallowed
|
|
117
|
+
]
|
|
118
|
+
return findings, off_host_not_evaluated
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def matcher_limitation(reason: str) -> str:
|
|
122
|
+
"""Human-readable explanation for a `matcher-unsupported` notEvaluated entry.
|
|
123
|
+
|
|
124
|
+
Kept next to the check that produces it so the two cannot drift; the CLI has no
|
|
125
|
+
other place to learn what the reason means.
|
|
126
|
+
"""
|
|
127
|
+
detail = _MATCHER_LIMITATION.get(reason, "the published rules")
|
|
128
|
+
return (f"robots.txt was fetched, but {detail}, and urllib.robotparser on this "
|
|
129
|
+
"interpreter does not evaluate those the way RFC 9309 specifies "
|
|
130
|
+
"(fixed in Python 3.14). OmniRank refuses to answer rather than report "
|
|
131
|
+
"a result it knows may be wrong. Re-run on Python 3.14 or later for "
|
|
132
|
+
"full coverage.")
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _canonical_pairs(pages: list[PageData]) -> list[tuple[PageData, str, str]]:
|
|
136
|
+
"""(page, absolute target, target key) for every page with a foreign canonical.
|
|
137
|
+
|
|
138
|
+
Self-canonicals are dropped: a page canonicalising to itself contradicts
|
|
139
|
+
nothing, even when it is noindexed -- that is a coherent "exclude this page"
|
|
140
|
+
configuration, and seo.noindex.in-sitemap owns the sitemap half of it.
|
|
141
|
+
"""
|
|
142
|
+
pairs: list[tuple[PageData, str, str]] = []
|
|
143
|
+
for page in pages:
|
|
144
|
+
target = site.canonical_target(page)
|
|
145
|
+
if not target:
|
|
146
|
+
continue # the per-URL gate's problem
|
|
147
|
+
key = site.canonical_key(target)
|
|
148
|
+
if key == site.canonical_key(page.url):
|
|
149
|
+
continue # self-canonical, correct
|
|
150
|
+
pairs.append((page, target, key))
|
|
151
|
+
return pairs
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _noindexed(page: PageData, target: str) -> Finding:
|
|
155
|
+
return _f("seo.canonical-target.noindexed", GATE_CANONICAL_TARGET, page.url,
|
|
156
|
+
"error",
|
|
157
|
+
f"canonical points to {target}, which carries a noindex directive",
|
|
158
|
+
"a canonical pointing at an indexable page",
|
|
159
|
+
f"Remove the noindex on {target}, or point this page's canonical "
|
|
160
|
+
"somewhere indexable. Naming a page engines are forbidden to index as "
|
|
161
|
+
"the canonical version of this one discards this page's signals "
|
|
162
|
+
"without transferring them anywhere: both URLs leave the index.")
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def check_canonical_targets(
|
|
166
|
+
client: httpx.Client, pages: list[PageData],
|
|
167
|
+
) -> tuple[list[Finding], list[NotEvaluated]]:
|
|
168
|
+
"""Canonicals whose target is noindexed, redirects, or does not exist.
|
|
169
|
+
|
|
170
|
+
Targets already in the crawled set are judged from the PageData already held --
|
|
171
|
+
no second fetch. Targets outside it are probed once each, deduplicated, up to
|
|
172
|
+
MAX_CANONICAL_PROBES; past that they are reported as budget-exceeded. Nothing
|
|
173
|
+
is ever judged from a URL OmniRank did not actually see.
|
|
174
|
+
|
|
175
|
+
A 5xx or transport failure on a probe is `page-unreachable`, not `.not-found`:
|
|
176
|
+
a transient origin error is not a missing page, and calling it one would be a
|
|
177
|
+
guess dressed as a finding.
|
|
178
|
+
"""
|
|
179
|
+
crawled = {site.canonical_key(p.url): p for p in pages}
|
|
180
|
+
findings: list[Finding] = []
|
|
181
|
+
not_evaluated: list[NotEvaluated] = []
|
|
182
|
+
|
|
183
|
+
# target key -> the outcome of probing it, so N pages sharing one broken target
|
|
184
|
+
# cost one request and still each get told.
|
|
185
|
+
probed: dict[str, Fetched | None] = {}
|
|
186
|
+
budget = MAX_CANONICAL_PROBES
|
|
187
|
+
|
|
188
|
+
for page, target, key in _canonical_pairs(pages):
|
|
189
|
+
known = crawled.get(key)
|
|
190
|
+
if known is not None:
|
|
191
|
+
# Already fetched and 200 by construction (unreachable URLs never
|
|
192
|
+
# become PageData), so only the noindex question remains.
|
|
193
|
+
if site.is_noindex(known):
|
|
194
|
+
findings.append(_noindexed(page, target))
|
|
195
|
+
continue
|
|
196
|
+
|
|
197
|
+
if key not in probed:
|
|
198
|
+
if budget <= 0:
|
|
199
|
+
probed[key] = None
|
|
200
|
+
not_evaluated.append(NotEvaluated(
|
|
201
|
+
gate=GATE_CANONICAL_TARGET, url=target, reason="budget-exceeded"))
|
|
202
|
+
else:
|
|
203
|
+
budget -= 1
|
|
204
|
+
probed[key] = fetch(client, target)
|
|
205
|
+
|
|
206
|
+
result = probed[key]
|
|
207
|
+
if result is None:
|
|
208
|
+
continue # already recorded as unevaluated
|
|
209
|
+
|
|
210
|
+
if result.is_redirect:
|
|
211
|
+
location = (result.headers.get("location", "") or "").strip() or "(no Location)"
|
|
212
|
+
findings.append(_f(
|
|
213
|
+
"seo.canonical-target.redirects", GATE_CANONICAL_TARGET, page.url,
|
|
214
|
+
"warning",
|
|
215
|
+
f"canonical points to {target}, which returns HTTP {result.status}",
|
|
216
|
+
"a canonical pointing at a URL that resolves 200",
|
|
217
|
+
f"Point this page's canonical straight at {location}. A canonical "
|
|
218
|
+
"that redirects makes engines resolve one more hop than they need "
|
|
219
|
+
"to, and a stale canonical is a symptom of a URL change the rest of "
|
|
220
|
+
"the markup has not caught up with."))
|
|
221
|
+
elif result.status in (404, 410):
|
|
222
|
+
findings.append(_f(
|
|
223
|
+
"seo.canonical-target.not-found", GATE_CANONICAL_TARGET, page.url,
|
|
224
|
+
"error",
|
|
225
|
+
f"canonical points to {target}, which returns HTTP {result.status}",
|
|
226
|
+
"a canonical pointing at a URL that resolves 200",
|
|
227
|
+
f"Restore {target}, or point this page's canonical at a URL that "
|
|
228
|
+
"exists. Nominating a missing page as the canonical version of this "
|
|
229
|
+
"one asks engines to index a URL that is not there, so this page's "
|
|
230
|
+
"signals go nowhere."))
|
|
231
|
+
elif result.ok:
|
|
232
|
+
if site.is_noindex(PageData.from_fetched(result)):
|
|
233
|
+
findings.append(_noindexed(page, target))
|
|
234
|
+
else:
|
|
235
|
+
# 5xx, 401, 403, or a transport failure (status 0). None of these means
|
|
236
|
+
# "gone", and OmniRank does not guess which one it is.
|
|
237
|
+
not_evaluated.append(NotEvaluated(
|
|
238
|
+
gate=GATE_CANONICAL_TARGET, url=target, reason="page-unreachable"))
|
|
239
|
+
|
|
240
|
+
return findings, not_evaluated
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def check_hreflang_noindex(pages: list[PageData]) -> list[Finding]:
|
|
244
|
+
"""Pages that declare a noindexed page as their locale alternate.
|
|
245
|
+
|
|
246
|
+
An hreflang set asserts that these URLs are intentional per-locale versions of
|
|
247
|
+
one another. Naming a page engines are forbidden to index nullifies the pair:
|
|
248
|
+
engines discard hreflang annotations whose target they cannot resolve, so the
|
|
249
|
+
DECLARING page loses its international targeting too -- which is why the
|
|
250
|
+
finding attaches there rather than to the noindexed page.
|
|
251
|
+
|
|
252
|
+
Crawled-set only, and no network I/O, so this gate can never fail to run and
|
|
253
|
+
returns a bare list. x-default is exempt: site.alternates excludes it, because
|
|
254
|
+
it is a fallback pointer rather than a language pair.
|
|
255
|
+
"""
|
|
256
|
+
by_key = {site.canonical_key(p.url): p for p in pages}
|
|
257
|
+
findings: list[Finding] = []
|
|
258
|
+
|
|
259
|
+
for page in pages:
|
|
260
|
+
page_key = site.canonical_key(page.url)
|
|
261
|
+
for href in sorted(site.alternates(page)):
|
|
262
|
+
target_key = site.canonical_key(href)
|
|
263
|
+
if target_key == page_key:
|
|
264
|
+
continue # self-reference is normal
|
|
265
|
+
target = by_key.get(target_key)
|
|
266
|
+
if target is None:
|
|
267
|
+
continue # outside the crawled set
|
|
268
|
+
if not site.is_noindex(target):
|
|
269
|
+
continue
|
|
270
|
+
findings.append(_f(
|
|
271
|
+
"seo.hreflang-noindex.alternate", GATE_HREFLANG_NOINDEX, page.url,
|
|
272
|
+
"error",
|
|
273
|
+
f"declares {href} as a locale alternate, and that page carries a "
|
|
274
|
+
"noindex directive",
|
|
275
|
+
"every hreflang alternate indexable",
|
|
276
|
+
f"Remove the noindex on {href}, or drop it from this page's hreflang "
|
|
277
|
+
"set. An alternate engines may not index cannot be returned for any "
|
|
278
|
+
"locale, and an annotation whose target cannot be resolved is "
|
|
279
|
+
"discarded -- taking this page's international targeting with it."))
|
|
280
|
+
return findings
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""The `crawler-policy` finding family: what robots.txt currently does per AI-crawler category.
|
|
2
|
+
|
|
3
|
+
Informational by design. Per-category findings are `info` (they cost no score and can never
|
|
4
|
+
fail a build); `geo.crawler-policy.mismatch` is a `warning` that exists only when the owner
|
|
5
|
+
stated a choice in config (`crawlerPolicy`) and robots.txt does not match it. Nothing here
|
|
6
|
+
recommends allowing or blocking: the text shows what each choice costs and says the choice
|
|
7
|
+
is the owner's. See `omnirank.crawlers` for the dated taxonomy and the parsing rules.
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
|
|
13
|
+
import httpx
|
|
14
|
+
|
|
15
|
+
from .. import crawlers
|
|
16
|
+
from ..config import Config
|
|
17
|
+
from ..fetch import fetch
|
|
18
|
+
from ..report import Finding, NotEvaluated
|
|
19
|
+
|
|
20
|
+
GATE = "crawler-policy"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class PolicyResult:
|
|
25
|
+
findings: list[Finding] = field(default_factory=list)
|
|
26
|
+
not_evaluated: list[NotEvaluated] = field(default_factory=list)
|
|
27
|
+
analysis: dict | None = None
|
|
28
|
+
robots_text: str | None = None
|
|
29
|
+
choices: dict[str, str] = field(default_factory=dict)
|
|
30
|
+
mismatches: list[dict] = field(default_factory=list)
|
|
31
|
+
|
|
32
|
+
def to_report(self) -> dict | None:
|
|
33
|
+
if self.analysis is None:
|
|
34
|
+
return None
|
|
35
|
+
return crawlers.report_dict(self.analysis, self.choices, self.mismatches)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _f(id_: str, severity: str, url: str, observed: str, expected: str, fix: str) -> Finding:
|
|
39
|
+
return Finding(id=id_, severity=severity, layer="geo", url=url, gate=GATE,
|
|
40
|
+
observed=observed, expected=expected, fix=fix) # type: ignore[arg-type]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def run(client: httpx.Client, config: Config) -> PolicyResult:
|
|
44
|
+
site = config.site_url
|
|
45
|
+
url = f"{site}/robots.txt"
|
|
46
|
+
result = PolicyResult(choices=crawlers.policy_from_config(config.crawler_policy))
|
|
47
|
+
got = fetch(client, url)
|
|
48
|
+
if got.ok:
|
|
49
|
+
text = got.text
|
|
50
|
+
elif 400 <= got.status < 500: # RFC 9309: unavailable robots.txt = no restrictions
|
|
51
|
+
text = None
|
|
52
|
+
else: # unreachable, redirected, or a server error
|
|
53
|
+
result.not_evaluated.append(NotEvaluated(
|
|
54
|
+
gate=GATE, reason="page-unreachable", site=site))
|
|
55
|
+
return result
|
|
56
|
+
result.robots_text = text
|
|
57
|
+
a = crawlers.analyse(text)
|
|
58
|
+
result.analysis = a
|
|
59
|
+
result.mismatches = crawlers.intent_mismatches(a, result.choices)
|
|
60
|
+
|
|
61
|
+
for c in a["categories"]:
|
|
62
|
+
info = crawlers.TRADEOFFS[c["id"]]
|
|
63
|
+
mine = result.choices.get(c["id"])
|
|
64
|
+
toks = ", ".join(f"{t['token']} [{t['marker']}]" for t in c["tokens"])
|
|
65
|
+
extra = (f" (robots.txt was cut at the {a['truncated_by']} cap)" if a["truncated"]
|
|
66
|
+
else "")
|
|
67
|
+
if a.get("unparseable"):
|
|
68
|
+
extra += f" (not evaluated: {a['unparseable']})"
|
|
69
|
+
result.findings.append(_f(
|
|
70
|
+
f"geo.crawler-policy.{crawlers.CATEGORY_FINDING_SUFFIX[c['id']]}", "info", url,
|
|
71
|
+
f"{info['label']}: robots.txt says {c['state']}{extra}. Tokens: {toks}",
|
|
72
|
+
(f"your configured choice: {mine}" if mine else
|
|
73
|
+
"an owner decision per category; no choice recorded (config `crawlerPolicy`)"),
|
|
74
|
+
f"If allowed: {info['if_allowed']} If blocked: {info['if_blocked']} "
|
|
75
|
+
f"OmniRank does not recommend either: the choice is yours. {crawlers.ADVISORY_NOTE}"))
|
|
76
|
+
for m in result.mismatches:
|
|
77
|
+
result.findings.append(_f(
|
|
78
|
+
"geo.crawler-policy.mismatch", "warning", url,
|
|
79
|
+
f"{m['category']}: robots.txt does not match your choice to {m['choice']}: "
|
|
80
|
+
f"{m['detail']}",
|
|
81
|
+
f"robots.txt matching your configured choice for {m['category']}: {m['choice']}",
|
|
82
|
+
"Either update robots.txt, or change `crawlerPolicy` if your intent changed; "
|
|
83
|
+
"`omnirank sweep --crawler-snippet` prints a robots.txt snippet for your choices "
|
|
84
|
+
f"(stdout only). {crawlers.ADVISORY_NOTE}"))
|
|
85
|
+
return result
|
omnirank/gates/geo.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
|
|
8
|
+
from ..fetch import fetch
|
|
9
|
+
from ..report import Finding
|
|
10
|
+
|
|
11
|
+
AI_CRAWLERS = (
|
|
12
|
+
"GPTBot", "OAI-SearchBot", "ChatGPT-User", "ClaudeBot", "anthropic-ai",
|
|
13
|
+
"Claude-Web", "PerplexityBot", "Perplexity-User", "Google-Extended",
|
|
14
|
+
"Applebot-Extended", "Meta-ExternalAgent", "Amazonbot", "CCBot", "Bytespider",
|
|
15
|
+
"Cohere-AI", "DuckAssistBot", "Diffbot", "YouBot", "PetalBot",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
LICENCE_MARKERS = ("cc by", "cc-by", "creative commons", "licence", "license",
|
|
19
|
+
"attribution", "how to cite")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# Every user-facing llms.txt / llms-full.txt message carries this. Google's own statement was
|
|
23
|
+
# NOT read as a primary page: it is attributed to the owner's notes and marked unverified.
|
|
24
|
+
LLMS_NOTE = (
|
|
25
|
+
"[experimental] llms.txt and llms-full.txt are agent/developer-convenience files, "
|
|
26
|
+
"not a ranking or citation lever; Google has said it does not use it "
|
|
27
|
+
"(attributed to the owner's notes; Google's own page was not read, so unverified here).")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _f(id_: str, gate: str, url: str, severity: str, observed: str,
|
|
31
|
+
expected: str, fix: str) -> Finding:
|
|
32
|
+
return Finding(id=id_, severity=severity, layer="geo", url=url, gate=gate,
|
|
33
|
+
observed=observed, expected=expected, fix=fix)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _artifact(client: httpx.Client, site_url: str, path: str, gate: str,
|
|
37
|
+
forbidden_hint: bool,
|
|
38
|
+
severity: str = "error") -> tuple[list[Finding], str | None]:
|
|
39
|
+
url = f"{site_url}/{path}"
|
|
40
|
+
result = fetch(client, url)
|
|
41
|
+
if result.ok:
|
|
42
|
+
return [], result.text
|
|
43
|
+
|
|
44
|
+
stem = path.replace(".txt", "").replace(".json", "")
|
|
45
|
+
note = f" {LLMS_NOTE}" if path.startswith("llms") else ""
|
|
46
|
+
if forbidden_hint and result.status == 403:
|
|
47
|
+
return [_f(
|
|
48
|
+
f"geo.{stem}.forbidden", gate, url, severity,
|
|
49
|
+
f"HTTP 403 at {path}", "HTTP 200",
|
|
50
|
+
"On OpenNext/CloudFront, .txt and .json paths route to the S3 origin, so a "
|
|
51
|
+
"dynamic route returns 403. Write this as a physical file into publicDir "
|
|
52
|
+
"during prebuild and deploy, never as a dynamic route." + note)], None
|
|
53
|
+
|
|
54
|
+
return [_f(
|
|
55
|
+
f"geo.{stem}.missing", gate, url, severity,
|
|
56
|
+
f"HTTP {result.status} at {path}", "HTTP 200",
|
|
57
|
+
(f"Optional: generate {path} at build time and serve it as a static file "
|
|
58
|
+
if path.startswith("llms") else
|
|
59
|
+
f"Generate {path} at build time and serve it as a static file ")
|
|
60
|
+
+ "(`omnirank geo` writes one)." + note)], None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
_TOTAL_DISALLOW = re.compile(r"^disallow:\s*/\s*(#.*)?$", re.IGNORECASE | re.MULTILINE)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _find_block(text: str, agent: str) -> str | None:
|
|
67
|
+
match = re.search(
|
|
68
|
+
rf"^user-agent:\s*{re.escape(agent)}\s*$(.*?)(?=^user-agent:|\Z)",
|
|
69
|
+
text, re.IGNORECASE | re.MULTILINE | re.DOTALL)
|
|
70
|
+
return match.group(1) if match else None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _blocks_everything(block_body: str) -> bool:
|
|
74
|
+
return bool(_TOTAL_DISALLOW.search(block_body))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _robots(client: httpx.Client, site_url: str) -> list[Finding]:
|
|
78
|
+
url = f"{site_url}/robots.txt"
|
|
79
|
+
result = fetch(client, url)
|
|
80
|
+
if not result.ok:
|
|
81
|
+
return [_f("geo.ai-allowlist.missing", "ai-allowlist", url, "info",
|
|
82
|
+
f"HTTP {result.status} at /robots.txt", "HTTP 200",
|
|
83
|
+
"Without a robots.txt no crawler is told anything. Whether to allow or "
|
|
84
|
+
"block each AI-crawler category is your choice; see the crawler-policy "
|
|
85
|
+
"section of this sweep and docs/crawler-policy.md. robots.txt is advisory.")]
|
|
86
|
+
|
|
87
|
+
wildcard_block = _find_block(result.text, "*")
|
|
88
|
+
wildcard_blocks_everyone = wildcard_block is not None and _blocks_everything(wildcard_block)
|
|
89
|
+
|
|
90
|
+
blocked: list[str] = []
|
|
91
|
+
for agent in AI_CRAWLERS:
|
|
92
|
+
own_block = _find_block(result.text, agent)
|
|
93
|
+
if own_block is not None:
|
|
94
|
+
if _blocks_everything(own_block):
|
|
95
|
+
blocked.append(agent)
|
|
96
|
+
elif wildcard_blocks_everyone:
|
|
97
|
+
blocked.append(agent)
|
|
98
|
+
|
|
99
|
+
if blocked:
|
|
100
|
+
return [_f("geo.ai-allowlist.blocked", "ai-allowlist", url, "info",
|
|
101
|
+
f"robots.txt blocks {', '.join(blocked)}",
|
|
102
|
+
"a deliberate per-category choice (neither blocking nor allowing is a defect)",
|
|
103
|
+
"Blocking AI crawlers is a legitimate choice with a cost and a benefit; "
|
|
104
|
+
"OmniRank does not recommend either way. See the crawler-policy section "
|
|
105
|
+
"of this sweep and docs/crawler-policy.md, and set `crawlerPolicy` in "
|
|
106
|
+
"your config to have robots.txt checked against your intent.")]
|
|
107
|
+
return []
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _citation_licence(text: str, site_url: str) -> list[Finding]:
|
|
111
|
+
lowered = text.lower()
|
|
112
|
+
if any(marker in lowered for marker in LICENCE_MARKERS):
|
|
113
|
+
return []
|
|
114
|
+
# [experimental] llms.txt (not a ranking or citation lever): this fires only when an
|
|
115
|
+
# llms.txt exists, is info-only, and says nothing about being cited or ranked.
|
|
116
|
+
return [_f("geo.citation-licence.missing", "citation-licence",
|
|
117
|
+
f"{site_url}/llms.txt", "info",
|
|
118
|
+
"no licence or attribution statement in llms.txt",
|
|
119
|
+
"an explicit reuse statement, if you want one (optional)",
|
|
120
|
+
"If you publish llms.txt you may state reuse terms in a 'How to cite us' "
|
|
121
|
+
"section; this does not make anything cite you. " + LLMS_NOTE)]
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def run(client: httpx.Client, site_url: str) -> list[Finding]:
|
|
125
|
+
site_url = site_url.rstrip("/")
|
|
126
|
+
findings: list[Finding] = []
|
|
127
|
+
|
|
128
|
+
# [experimental] llms.txt / llms-full.txt: info-only, not a ranking or citation lever.
|
|
129
|
+
llms_findings, llms_text = _artifact(client, site_url, "llms.txt", "llms-txt", False, "info")
|
|
130
|
+
findings.extend(llms_findings)
|
|
131
|
+
|
|
132
|
+
full_findings, _ = _artifact(client, site_url, "llms-full.txt", "llms-full", True, "info")
|
|
133
|
+
findings.extend(full_findings)
|
|
134
|
+
|
|
135
|
+
facts_findings, facts_text = _artifact(client, site_url, "facts.json", "facts-json", True)
|
|
136
|
+
findings.extend(facts_findings)
|
|
137
|
+
|
|
138
|
+
if facts_text is not None:
|
|
139
|
+
try:
|
|
140
|
+
json.loads(facts_text)
|
|
141
|
+
except json.JSONDecodeError as exc:
|
|
142
|
+
findings.append(_f(
|
|
143
|
+
"geo.facts-json.invalid", "facts-json", f"{site_url}/facts.json",
|
|
144
|
+
"error", f"facts.json is not valid JSON: {exc.msg}", "parseable JSON",
|
|
145
|
+
"Regenerate facts.json; engines that cannot parse it will ignore it."))
|
|
146
|
+
|
|
147
|
+
findings.extend(_robots(client, site_url))
|
|
148
|
+
|
|
149
|
+
if llms_text is not None:
|
|
150
|
+
findings.extend(_citation_licence(llms_text, site_url))
|
|
151
|
+
|
|
152
|
+
return findings
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from collections import Counter
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
|
|
8
|
+
from ..fetch import fetch
|
|
9
|
+
from ..report import Finding
|
|
10
|
+
|
|
11
|
+
_LASTMOD = re.compile(r"<lastmod>\s*([^<\s]+)\s*</lastmod>", re.IGNORECASE)
|
|
12
|
+
MIN_ENTRIES_FOR_INFLATION = 10
|
|
13
|
+
INFLATION_RATIO = 0.9
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _f(id_: str, gate: str, url: str, severity: str, observed: str,
|
|
17
|
+
expected: str, fix: str) -> Finding:
|
|
18
|
+
return Finding(id=id_, severity=severity, layer="seo", url=url, gate=gate,
|
|
19
|
+
observed=observed, expected=expected, fix=fix)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def check_removed(client: httpx.Client, urls: list[str]) -> list[Finding]:
|
|
23
|
+
findings: list[Finding] = []
|
|
24
|
+
for url in urls:
|
|
25
|
+
result = fetch(client, url)
|
|
26
|
+
if result.is_redirect or result.status == 410:
|
|
27
|
+
continue
|
|
28
|
+
if result.status >= 500 or result.status == 0:
|
|
29
|
+
findings.append(_f(
|
|
30
|
+
"seo.crawl-hygiene.server-error", "crawl-hygiene", url, "error",
|
|
31
|
+
f"HTTP {result.status}", "3xx redirect or 410 Gone",
|
|
32
|
+
"A 5xx for an unknown slug usually means a dynamic route shipped with "
|
|
33
|
+
"dynamicParams=false. Set dynamicParams=true and permanentRedirect "
|
|
34
|
+
"unknown slugs to their hub."))
|
|
35
|
+
elif result.status == 404:
|
|
36
|
+
findings.append(_f(
|
|
37
|
+
"seo.crawl-hygiene.not-found", "crawl-hygiene", url, "warning",
|
|
38
|
+
"HTTP 404", "3xx redirect or 410 Gone",
|
|
39
|
+
"Redirect this to a live, topically relevant page, or return 410 so "
|
|
40
|
+
"Google deindexes cleanly instead of re-checking for months."))
|
|
41
|
+
return findings
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def check_sitemap(client: httpx.Client, site_url: str, sample: list[str]) -> list[Finding]:
|
|
45
|
+
findings: list[Finding] = []
|
|
46
|
+
for url in sample:
|
|
47
|
+
result = fetch(client, url)
|
|
48
|
+
if result.ok:
|
|
49
|
+
continue
|
|
50
|
+
if result.is_redirect:
|
|
51
|
+
findings.append(_f(
|
|
52
|
+
"seo.sitemap-health.redirect", "sitemap-health", url, "warning",
|
|
53
|
+
f"HTTP {result.status} from a sitemap URL", "HTTP 200",
|
|
54
|
+
"Sitemaps should list final URLs only. Replace this entry with its "
|
|
55
|
+
"redirect target."))
|
|
56
|
+
else:
|
|
57
|
+
findings.append(_f(
|
|
58
|
+
"seo.sitemap-health.dead-url", "sitemap-health", url, "error",
|
|
59
|
+
f"HTTP {result.status} from a sitemap URL", "HTTP 200",
|
|
60
|
+
"Remove the entry or restore the page. Submitting dead URLs wastes "
|
|
61
|
+
"crawl budget and erodes trust in the sitemap."))
|
|
62
|
+
return findings
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def check_lastmod(sitemap_xml: str, site_url: str) -> list[Finding]:
|
|
66
|
+
dates = _LASTMOD.findall(sitemap_xml)
|
|
67
|
+
if len(dates) < MIN_ENTRIES_FOR_INFLATION:
|
|
68
|
+
return []
|
|
69
|
+
|
|
70
|
+
day, count = Counter(d[:10] for d in dates).most_common(1)[0]
|
|
71
|
+
if count / len(dates) <= INFLATION_RATIO:
|
|
72
|
+
return []
|
|
73
|
+
|
|
74
|
+
return [_f(
|
|
75
|
+
"seo.lastmod-inflation.uniform", "lastmod-inflation",
|
|
76
|
+
f"{site_url}/sitemap.xml", "warning",
|
|
77
|
+
f"{count} of {len(dates)} entries share lastmod {day}",
|
|
78
|
+
"lastmod reflecting real per-URL change dates",
|
|
79
|
+
"Stamp lastmod from real publish/update timestamps and use a stable constant "
|
|
80
|
+
"for static routes. Re-stamping every URL each build teaches crawlers to "
|
|
81
|
+
"ignore the signal.")]
|