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
omnirank/formats.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""SARIF 2.1.0 and JUnit XML renderings of a report dict (``Report.to_dict()``).
|
|
2
|
+
|
|
3
|
+
Both are built only from fields the report really has: findings (id, severity, layer,
|
|
4
|
+
url, gate, observed, expected, fix, fixTier), the per-layer ``score`` keys and
|
|
5
|
+
``notEvaluated``. A report lists findings, not passing gates, so a gate that ran clean
|
|
6
|
+
appears in neither output; nothing is invented to fill that gap.
|
|
7
|
+
|
|
8
|
+
JUnit text may come from fetched pages, so characters illegal in XML 1.0 are replaced
|
|
9
|
+
with U+FFFD (see `_x`) rather than emitted; SARIF is JSON and needs no such step.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import re
|
|
15
|
+
import xml.etree.ElementTree as ET
|
|
16
|
+
|
|
17
|
+
from . import __version__
|
|
18
|
+
|
|
19
|
+
# Characters outside the XML 1.0 Char production (control characters, U+FFFE, U+FFFF and
|
|
20
|
+
# lone surrogates). Finding text comes from fetched pages and may contain them.
|
|
21
|
+
_XML_ILLEGAL = re.compile("[\x00-\x08\x0b\x0c\x0e-\x1f\ud800-\udfff\ufffe\uffff]")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _x(text: object) -> str:
|
|
25
|
+
"""Replace every character illegal in XML 1.0 with U+FFFD, so the JUnit output always
|
|
26
|
+
parses. Applied to every string `to_junit` emits (text, attributes, names)."""
|
|
27
|
+
return _XML_ILLEGAL.sub("\ufffd", str(text))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
SARIF_SCHEMA = "https://json.schemastore.org/sarif-2.1.0.json"
|
|
31
|
+
SARIF_LEVEL = {"error": "error", "warning": "warning", "info": "note"}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _message(f: dict) -> str:
|
|
35
|
+
return f"{f['id']} — observed: {f['observed']} Expected: {f['expected']} Fix: {f['fix']}"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def to_sarif(report: dict) -> dict:
|
|
39
|
+
rules: dict[str, dict] = {}
|
|
40
|
+
results: list[dict] = []
|
|
41
|
+
for f in report.get("findings", []):
|
|
42
|
+
if f["id"] not in rules:
|
|
43
|
+
rules[f["id"]] = {
|
|
44
|
+
"id": f["id"],
|
|
45
|
+
"name": f["id"],
|
|
46
|
+
"shortDescription": {"text": f["expected"]},
|
|
47
|
+
"help": {"text": f["fix"]},
|
|
48
|
+
"properties": {"layer": f["layer"], "gate": f["gate"],
|
|
49
|
+
"fixTier": f.get("fixTier")},
|
|
50
|
+
}
|
|
51
|
+
result: dict = {
|
|
52
|
+
"ruleId": f["id"],
|
|
53
|
+
"level": SARIF_LEVEL.get(f["severity"], "note"),
|
|
54
|
+
"message": {"text": _message(f)},
|
|
55
|
+
}
|
|
56
|
+
if f.get("url"):
|
|
57
|
+
result["locations"] = [
|
|
58
|
+
{"physicalLocation": {"artifactLocation": {"uri": f["url"]}}}]
|
|
59
|
+
results.append(result)
|
|
60
|
+
return {
|
|
61
|
+
"$schema": SARIF_SCHEMA,
|
|
62
|
+
"version": "2.1.0",
|
|
63
|
+
"runs": [{
|
|
64
|
+
"tool": {"driver": {
|
|
65
|
+
"name": "omnirank",
|
|
66
|
+
"version": __version__,
|
|
67
|
+
"informationUri": "https://github.com/bemoshiur/OmniRank",
|
|
68
|
+
"rules": list(rules.values()),
|
|
69
|
+
}},
|
|
70
|
+
"results": results,
|
|
71
|
+
}],
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _detail(f: dict) -> str:
|
|
76
|
+
return _x(f"{f['severity'].upper()} {f['id']} {f.get('url', '')}\n"
|
|
77
|
+
f"observed: {f['observed']}\nexpected: {f['expected']}\nfix: {f['fix']}")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def to_junit(report: dict) -> str:
|
|
81
|
+
findings = report.get("findings", [])
|
|
82
|
+
layers = [k for k in report.get("score", {}) if k != "overall"]
|
|
83
|
+
for f in findings:
|
|
84
|
+
if f["layer"] not in layers:
|
|
85
|
+
layers.append(f["layer"])
|
|
86
|
+
|
|
87
|
+
root = ET.Element("testsuites", name="omnirank")
|
|
88
|
+
totals = {"tests": 0, "failures": 0, "skipped": 0}
|
|
89
|
+
|
|
90
|
+
def _suite(name: str) -> ET.Element:
|
|
91
|
+
return ET.SubElement(root, "testsuite", name=_x(name))
|
|
92
|
+
|
|
93
|
+
def _seal(suite: ET.Element, tests: int, failures: int, skipped: int = 0) -> None:
|
|
94
|
+
suite.set("tests", str(tests))
|
|
95
|
+
suite.set("failures", str(failures))
|
|
96
|
+
suite.set("skipped", str(skipped))
|
|
97
|
+
totals["tests"] += tests
|
|
98
|
+
totals["failures"] += failures
|
|
99
|
+
totals["skipped"] += skipped
|
|
100
|
+
|
|
101
|
+
for layer in layers:
|
|
102
|
+
suite = _suite(layer)
|
|
103
|
+
by_gate: dict[str, list[dict]] = {}
|
|
104
|
+
for f in findings:
|
|
105
|
+
if f["layer"] == layer:
|
|
106
|
+
by_gate.setdefault(f["gate"], []).append(f)
|
|
107
|
+
failures = 0
|
|
108
|
+
for gate, items in by_gate.items():
|
|
109
|
+
case = ET.SubElement(suite, "testcase", classname=_x(layer), name=_x(gate))
|
|
110
|
+
errors = [f for f in items if f["severity"] == "error"]
|
|
111
|
+
if errors:
|
|
112
|
+
failures += 1
|
|
113
|
+
failure = ET.SubElement(
|
|
114
|
+
case, "failure", type="error",
|
|
115
|
+
message=_x(f"{gate}: {len(errors)} error finding(s), e.g. {errors[0]['id']}"))
|
|
116
|
+
failure.text = "\n\n".join(_detail(f) for f in errors)
|
|
117
|
+
rest = [f for f in items if f["severity"] != "error"]
|
|
118
|
+
if rest:
|
|
119
|
+
ET.SubElement(case, "system-out").text = "\n\n".join(_detail(f) for f in rest)
|
|
120
|
+
_seal(suite, len(by_gate), failures)
|
|
121
|
+
|
|
122
|
+
skipped_entries = report.get("notEvaluated", [])
|
|
123
|
+
if skipped_entries:
|
|
124
|
+
suite = _suite("not-evaluated")
|
|
125
|
+
for e in skipped_entries:
|
|
126
|
+
case = ET.SubElement(suite, "testcase", classname="not-evaluated", name=_x(e["gate"]))
|
|
127
|
+
target = e.get("url") or e.get("site") or ""
|
|
128
|
+
ET.SubElement(case, "skipped", message=_x(f"{e['reason']} {target}".strip()))
|
|
129
|
+
_seal(suite, len(skipped_entries), 0, len(skipped_entries))
|
|
130
|
+
|
|
131
|
+
for key, value in totals.items():
|
|
132
|
+
root.set(key, str(value))
|
|
133
|
+
ET.indent(root)
|
|
134
|
+
return ET.tostring(root, encoding="unicode", xml_declaration=False)
|
omnirank/framework.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"""Detect a project's routing convention from files on disk.
|
|
2
|
+
|
|
3
|
+
Detection MUST be able to return `unknown`. A bespoke project is the common
|
|
4
|
+
case, and a confident wrong answer here is worse than an admitted absence:
|
|
5
|
+
`unknown` produces a locator confidence of `none`, which demotes every fix on
|
|
6
|
+
that repo to display-only, which is exactly right. A wrong guess instead
|
|
7
|
+
produces a confident diff against the wrong file.
|
|
8
|
+
|
|
9
|
+
Confidence is reported, never hidden, and it propagates: locator.py caps its own
|
|
10
|
+
confidence at DETECTION_CEILING[confidence], and applicability.py caps the fix
|
|
11
|
+
at that. A `low`-confidence detection can therefore only ever produce
|
|
12
|
+
display-only fixes.
|
|
13
|
+
|
|
14
|
+
Ordering matters and is deliberate: a framework marker always beats a generic
|
|
15
|
+
one, so a stray `index.html` in an Astro project does not make it `static`.
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from collections.abc import Iterable
|
|
20
|
+
from dataclasses import dataclass
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from typing import Literal
|
|
23
|
+
|
|
24
|
+
Framework = Literal[
|
|
25
|
+
"next-app-router", "next-pages-router", "astro", "nuxt", "sveltekit",
|
|
26
|
+
"hugo", "jekyll", "eleventy", "wordpress", "static", "unknown",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
DetectionConfidence = Literal["high", "medium", "low", "none"]
|
|
30
|
+
|
|
31
|
+
# `stack.framework` in omnirank.config.schema.json uses a slightly different
|
|
32
|
+
# vocabulary: it predates this module, spells the Next pages router
|
|
33
|
+
# `next-pages`, and carries `shopify` and `other`, neither of which this module
|
|
34
|
+
# can locate against. Anything with no routing convention we implement maps to
|
|
35
|
+
# `unknown`, which is honest -- it is exactly what the locator can do with it.
|
|
36
|
+
CONFIG_FRAMEWORK_ALIASES: dict[str, Framework] = {
|
|
37
|
+
"next-app-router": "next-app-router",
|
|
38
|
+
"next-pages": "next-pages-router",
|
|
39
|
+
"next-pages-router": "next-pages-router",
|
|
40
|
+
"astro": "astro",
|
|
41
|
+
"nuxt": "nuxt",
|
|
42
|
+
"sveltekit": "sveltekit",
|
|
43
|
+
"hugo": "hugo",
|
|
44
|
+
"jekyll": "jekyll",
|
|
45
|
+
"eleventy": "eleventy",
|
|
46
|
+
"wordpress": "wordpress",
|
|
47
|
+
"static": "static",
|
|
48
|
+
"shopify": "unknown",
|
|
49
|
+
"other": "unknown",
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@dataclass(frozen=True)
|
|
54
|
+
class Detection:
|
|
55
|
+
"""What was detected, how sure we are, and the files that decided it.
|
|
56
|
+
|
|
57
|
+
`evidence` holds repo-relative POSIX paths (plus, occasionally, a short
|
|
58
|
+
explanatory string when the deciding fact is an ABSENCE). It exists so
|
|
59
|
+
`omnirank fix` can print why it believes what it believes -- a detector that
|
|
60
|
+
cannot show its work is indistinguishable from a guess.
|
|
61
|
+
|
|
62
|
+
INVARIANT: framework == "unknown" implies confidence == "none".
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
framework: Framework
|
|
66
|
+
confidence: DetectionConfidence
|
|
67
|
+
evidence: tuple[str, ...]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
UNKNOWN = Detection(framework="unknown", confidence="none",
|
|
71
|
+
evidence=("no framework marker found",))
|
|
72
|
+
|
|
73
|
+
_NEXT_CONFIGS = ("next.config.js", "next.config.mjs", "next.config.ts",
|
|
74
|
+
"next.config.cjs")
|
|
75
|
+
_ASTRO_CONFIGS = ("astro.config.mjs", "astro.config.js", "astro.config.ts",
|
|
76
|
+
"astro.config.mts", "astro.config.cjs")
|
|
77
|
+
_NUXT_CONFIGS = ("nuxt.config.ts", "nuxt.config.js", "nuxt.config.mjs")
|
|
78
|
+
_ELEVENTY_CONFIGS = (".eleventy.js", "eleventy.config.js", "eleventy.config.mjs",
|
|
79
|
+
"eleventy.config.cjs")
|
|
80
|
+
_HUGO_CONFIGS = ("hugo.toml", "hugo.yaml", "hugo.json")
|
|
81
|
+
_LAYOUT_FILES = ("layout.tsx", "layout.jsx", "layout.ts", "layout.js")
|
|
82
|
+
_APP_FILES = ("_app.tsx", "_app.jsx", "_app.ts", "_app.js")
|
|
83
|
+
_STATIC_ROOTS = ("", "public", "dist")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _first_file(root: Path, names: Iterable[str]) -> str | None:
|
|
87
|
+
for name in names:
|
|
88
|
+
if (root / name).is_file():
|
|
89
|
+
return name
|
|
90
|
+
return None
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _first_file_in(root: Path, dirs: Iterable[str],
|
|
94
|
+
names: Iterable[str]) -> str | None:
|
|
95
|
+
"""The first `<dir>/<name>` that exists, as a repo-relative POSIX path."""
|
|
96
|
+
for directory in dirs:
|
|
97
|
+
for name in names:
|
|
98
|
+
if (root / directory / name).is_file():
|
|
99
|
+
return f"{directory}/{name}"
|
|
100
|
+
return None
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _wordpress(root: Path) -> Detection | None:
|
|
104
|
+
if (root / "wp-config.php").is_file():
|
|
105
|
+
return Detection("wordpress", "high", ("wp-config.php",))
|
|
106
|
+
return None
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _next(root: Path) -> Detection | None:
|
|
110
|
+
config = _first_file(root, _NEXT_CONFIGS)
|
|
111
|
+
app = _first_file_in(root, ("app", "src/app"), _LAYOUT_FILES)
|
|
112
|
+
pages = _first_file_in(root, ("pages", "src/pages"), _APP_FILES)
|
|
113
|
+
if config is None and app is None and pages is None:
|
|
114
|
+
return None
|
|
115
|
+
|
|
116
|
+
evidence = tuple(item for item in (config, app, pages) if item is not None)
|
|
117
|
+
if app is not None and pages is not None:
|
|
118
|
+
# Next resolves a mixed-router project per route. This release cannot,
|
|
119
|
+
# and `low` is how it says so: locator.py turns `low` into confidence
|
|
120
|
+
# `none`, so every fix here is display-only rather than a coin flip.
|
|
121
|
+
return Detection("next-app-router", "low", evidence)
|
|
122
|
+
if app is not None:
|
|
123
|
+
return Detection("next-app-router", "high" if config else "medium", evidence)
|
|
124
|
+
if pages is not None:
|
|
125
|
+
return Detection("next-pages-router", "high" if config else "medium", evidence)
|
|
126
|
+
# A next.config.* with neither router directory: certainly Next, but we
|
|
127
|
+
# cannot say which router owns the head, and `unknown` never carries
|
|
128
|
+
# confidence.
|
|
129
|
+
return Detection("unknown", "none",
|
|
130
|
+
(*evidence, "no app/ or pages/ router directory"))
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _astro(root: Path) -> Detection | None:
|
|
134
|
+
config = _first_file(root, _ASTRO_CONFIGS)
|
|
135
|
+
return Detection("astro", "high", (config,)) if config else None
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _nuxt(root: Path) -> Detection | None:
|
|
139
|
+
config = _first_file(root, _NUXT_CONFIGS)
|
|
140
|
+
return Detection("nuxt", "high", (config,)) if config else None
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _sveltekit(root: Path) -> Detection | None:
|
|
144
|
+
if not (root / "svelte.config.js").is_file():
|
|
145
|
+
return None
|
|
146
|
+
if (root / "src" / "routes").is_dir():
|
|
147
|
+
return Detection("sveltekit", "high", ("svelte.config.js", "src/routes"))
|
|
148
|
+
return Detection("sveltekit", "medium", ("svelte.config.js",))
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _hugo(root: Path) -> Detection | None:
|
|
152
|
+
config = _first_file(root, _HUGO_CONFIGS)
|
|
153
|
+
if config:
|
|
154
|
+
return Detection("hugo", "high", (config,))
|
|
155
|
+
# `config.toml` alone is far too generic to decide on -- Rust, Netlify and
|
|
156
|
+
# a dozen other tools use that filename -- so it needs Hugo's own directory
|
|
157
|
+
# shape alongside it.
|
|
158
|
+
if ((root / "config.toml").is_file() and (root / "content").is_dir()
|
|
159
|
+
and (root / "layouts").is_dir()):
|
|
160
|
+
return Detection("hugo", "medium", ("config.toml", "content", "layouts"))
|
|
161
|
+
return None
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _jekyll(root: Path) -> Detection | None:
|
|
165
|
+
if not (root / "_config.yml").is_file():
|
|
166
|
+
return None
|
|
167
|
+
if (root / "_layouts").is_dir():
|
|
168
|
+
return Detection("jekyll", "high", ("_config.yml", "_layouts"))
|
|
169
|
+
return Detection("jekyll", "medium", ("_config.yml",))
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _eleventy(root: Path) -> Detection | None:
|
|
173
|
+
config = _first_file(root, _ELEVENTY_CONFIGS)
|
|
174
|
+
return Detection("eleventy", "high", (config,)) if config else None
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _static(root: Path) -> Detection | None:
|
|
178
|
+
"""`static` is the last detector tried (see `_DETECTORS` below): by the
|
|
179
|
+
time this runs, every framework-specific marker has already failed to
|
|
180
|
+
match, so an `index.html` at the repo root or a conventional build output
|
|
181
|
+
is as strong a signal as this module can get for "plain HTML, no
|
|
182
|
+
framework" -- `high`, the same confidence a single named config file
|
|
183
|
+
earns every other framework here (`astro.config.mjs`, `hugo.toml`, a
|
|
184
|
+
`wp-config.php`).
|
|
185
|
+
|
|
186
|
+
This was `medium` through v0.3.0, which -- via DETECTION_CEILING in
|
|
187
|
+
locator.py -- capped every static-site locate() at `inferred`, and
|
|
188
|
+
CONFIDENCE_CEILING caps `inferred` at `unsafe`. A bare static site,
|
|
189
|
+
the plain-HTML case users try first, could therefore NEVER reach
|
|
190
|
+
`applicability == "safe"` and `omnirank fix` could never emit a diff for
|
|
191
|
+
it, despite `_locate_static` and `canonical.missing` being fully
|
|
192
|
+
implemented and tested. Raising this to `high` does not weaken the
|
|
193
|
+
genuine ambiguity guard: `_locate_by_convention` in locator.py already
|
|
194
|
+
returns NOT_LOCATED (confidence `none`) whenever more than one on-disk
|
|
195
|
+
file could serve the SAME route (e.g. both `pricing.html` and
|
|
196
|
+
`pricing/index.html` exist) -- a per-route check that is completely
|
|
197
|
+
independent of this per-repo detection confidence and is unaffected by
|
|
198
|
+
it either way. The two axes stay orthogonal on purpose: this confidence
|
|
199
|
+
says "how sure are we this project has no framework", not "how sure are
|
|
200
|
+
we about any one route", which is what the locator's own guard is for.
|
|
201
|
+
"""
|
|
202
|
+
for base in _STATIC_ROOTS:
|
|
203
|
+
relative = f"{base}/index.html" if base else "index.html"
|
|
204
|
+
if (root / relative).is_file():
|
|
205
|
+
return Detection("static", "high", (relative,))
|
|
206
|
+
return None
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
# Order is load-bearing: every framework-specific marker is checked before the
|
|
210
|
+
# generic index.html sweep, so a build output inside a framework project never
|
|
211
|
+
# reclassifies it as `static`.
|
|
212
|
+
_DETECTORS = (_wordpress, _next, _astro, _nuxt, _sveltekit, _hugo, _jekyll,
|
|
213
|
+
_eleventy, _static)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def detect(root: str | Path) -> Detection:
|
|
217
|
+
"""The routing convention `root` uses, or UNKNOWN. Never raises."""
|
|
218
|
+
base = Path(root)
|
|
219
|
+
for detector in _DETECTORS:
|
|
220
|
+
found = detector(base)
|
|
221
|
+
if found is not None:
|
|
222
|
+
return found
|
|
223
|
+
return UNKNOWN
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Gate modules.
|
|
2
|
+
|
|
3
|
+
`seo` and `jsonld` each expose `run(html: str, url: str) -> list[Finding]`, scoring a
|
|
4
|
+
single already-fetched page.
|
|
5
|
+
|
|
6
|
+
`aeo` exposes `run(html: str, url: str, selector: str = ".answer-block", band: Band |
|
|
7
|
+
None = None) -> list[Finding]` — `selector` and `band` are additive keyword arguments
|
|
8
|
+
with defaults, so every pre-existing single-page call site keeps working unchanged.
|
|
9
|
+
`band` is the AnswerBlock word/character range to score against; see
|
|
10
|
+
`bands.resolve_band` for how one is picked per page.
|
|
11
|
+
|
|
12
|
+
`geo` instead exposes `run(client: httpx.Client, site_url: str) -> list[Finding]` —
|
|
13
|
+
it fetches llms.txt and llms-full.txt (both [experimental], info-only, not a ranking or citation lever), facts.json and
|
|
14
|
+
robots.txt itself rather than
|
|
15
|
+
scoring HTML the caller already has.
|
|
16
|
+
|
|
17
|
+
`site` exposes `run(pages: list[PageData], sitemap_urls: list[str] | None = None) ->
|
|
18
|
+
list[Finding]` — the cross-URL pass. Unlike every other module here it needs the whole
|
|
19
|
+
crawled set at once (duplicate titles/descriptions, canonical chains, hreflang
|
|
20
|
+
reciprocity are none of them checkable from a single page), so it takes the full list
|
|
21
|
+
of fetched `PageData` rather than one page's `html`/`url`.
|
|
22
|
+
|
|
23
|
+
`perf` exposes `run(page: PageData) -> list[Finding]` — performance signals derived
|
|
24
|
+
from the single HTTP response already captured on `page` (`page.elapsed_ms`,
|
|
25
|
+
`page.html`, `page.headers`), not a fresh `html`/`url` pair.
|
|
26
|
+
|
|
27
|
+
`hygiene` has no `run`. It exposes three functions instead, each returning
|
|
28
|
+
`list[Finding]`: `check_removed(client, urls)`, `check_sitemap(client, site_url,
|
|
29
|
+
sample)` and `check_lastmod(sitemap_xml, site_url)`.
|
|
30
|
+
|
|
31
|
+
`security` exposes `run_page(page: PageData) -> list[Finding]` for the per-response
|
|
32
|
+
header and markup gates, plus `check_https_redirect(client: httpx.Client, site_url:
|
|
33
|
+
str) -> tuple[list[Finding], list[NotEvaluated]]` for the one site-level probe. It
|
|
34
|
+
returns notEvaluated entries alongside findings rather than mutating a Report,
|
|
35
|
+
keeping the gate testable without one.
|
|
36
|
+
|
|
37
|
+
`contradictions` has no `run`, for the same reason `hygiene` does not: its checks
|
|
38
|
+
take different inputs. It exposes `check_sitemap_vs_robots(client, site_url,
|
|
39
|
+
sitemap_urls) -> tuple[list[Finding], list[NotEvaluated]]`,
|
|
40
|
+
`check_canonical_targets(client, pages) -> tuple[list[Finding], list[NotEvaluated]]`
|
|
41
|
+
and `check_hreflang_noindex(pages) -> list[Finding]`. The first two return
|
|
42
|
+
notEvaluated entries because they depend on network I/O that can fail.
|
|
43
|
+
|
|
44
|
+
`onpage` exposes `run(html: str, url: str) -> list[Finding]`, the same shape as
|
|
45
|
+
`seo` and `jsonld`. It is separate from `seo` because that module owns the <head>'s
|
|
46
|
+
indexing signals while this one owns body markup engines and assistive technology
|
|
47
|
+
both read.
|
|
48
|
+
"""
|
omnirank/gates/aeo.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
from bs4 import BeautifulSoup
|
|
6
|
+
|
|
7
|
+
from ..bands import DEFAULT_BAND, Band, measure
|
|
8
|
+
from ..html import find_ldjson_scripts
|
|
9
|
+
from ..report import Finding
|
|
10
|
+
|
|
11
|
+
MIN_FAQS = 3
|
|
12
|
+
LIST_TAGS = ("ul", "ol", "li")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _f(id_: str, gate: str, url: str, severity: str, observed: str,
|
|
16
|
+
expected: str, fix: str) -> Finding:
|
|
17
|
+
return Finding(id=id_, severity=severity, layer="aeo", url=url, gate=gate,
|
|
18
|
+
observed=observed, expected=expected, fix=fix)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _answer_block(soup: BeautifulSoup, url: str, selector: str,
|
|
22
|
+
band: Band) -> list[Finding]:
|
|
23
|
+
blocks = soup.select(selector)
|
|
24
|
+
if not blocks:
|
|
25
|
+
return [_f("aeo.answer-block.missing", "answer-block", url, "error",
|
|
26
|
+
f"no element matching {selector!r}", "one answer block near the top",
|
|
27
|
+
f'Add <div class="{selector.lstrip(".")}" data-speakable> with a '
|
|
28
|
+
f"{band.describe()} plain-prose answer.")]
|
|
29
|
+
|
|
30
|
+
block = blocks[0]
|
|
31
|
+
findings: list[Finding] = []
|
|
32
|
+
|
|
33
|
+
size = measure(block.get_text(" ", strip=True), band)
|
|
34
|
+
if not band.contains(size):
|
|
35
|
+
unit = "words" if band.unit == "words" else "characters"
|
|
36
|
+
findings.append(_f(
|
|
37
|
+
"aeo.answer-block.length", "answer-block", url, "error",
|
|
38
|
+
f"{size} {unit}", band.describe(),
|
|
39
|
+
"Rewrite to a single liftable paragraph in that range; answer engines "
|
|
40
|
+
"quote whole blocks, not fragments."))
|
|
41
|
+
|
|
42
|
+
if block.find(LIST_TAGS):
|
|
43
|
+
findings.append(_f(
|
|
44
|
+
"aeo.answer-block.list-markup", "answer-block", url, "error",
|
|
45
|
+
"list markup inside the answer block", "plain prose only",
|
|
46
|
+
"Remove <ul>/<ol>/<li>. The block must be one quotable paragraph."))
|
|
47
|
+
|
|
48
|
+
return findings
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _faq(soup: BeautifulSoup, url: str) -> list[Finding]:
|
|
52
|
+
# Summed, not `or`-ed: a <dt> is never itself a <details> element, so the two
|
|
53
|
+
# selectors can never double-count the same pair -- each match is a genuinely
|
|
54
|
+
# distinct FAQ pair. The old `len(dt) or len(details)` short-circuited on any
|
|
55
|
+
# non-zero <dt> count, so a page with 2 <dt> (maybe an unrelated glossary
|
|
56
|
+
# elsewhere) plus 20 real <details>-based FAQs reported "2 FAQ pairs" and
|
|
57
|
+
# demanded more, ignoring the 20 that were already there. Summing also covers a
|
|
58
|
+
# site mid-migration between the two markup styles without undercounting either.
|
|
59
|
+
pairs = len(soup.find_all("dt")) + len(soup.find_all("details"))
|
|
60
|
+
if pairs < MIN_FAQS:
|
|
61
|
+
# Warning, not error: demanding 3+ FAQs on every page -- pricing pages,
|
|
62
|
+
# about pages, 404s -- is not defensible advice, and treating it as a
|
|
63
|
+
# build-failing error meant one real site's pricing/about/legal pages
|
|
64
|
+
# alone contributed 57 error findings for a check that doesn't apply to
|
|
65
|
+
# most of them.
|
|
66
|
+
return [_f("aeo.faq.too-few", "faq", url, "warning",
|
|
67
|
+
f"{pairs} FAQ pairs", f">= {MIN_FAQS}",
|
|
68
|
+
"Add FAQs as semantic <dl>/<dt>/<dd> or <details>, mirrored by "
|
|
69
|
+
"FAQPage JSON-LD. Skip this on pages where an FAQ section "
|
|
70
|
+
"genuinely doesn't belong (pricing, about, legal, 404).")]
|
|
71
|
+
return []
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _speakable(soup: BeautifulSoup, url: str) -> list[Finding]:
|
|
75
|
+
findings: list[Finding] = []
|
|
76
|
+
for script in find_ldjson_scripts(soup):
|
|
77
|
+
try:
|
|
78
|
+
data = json.loads(script.string or "{}")
|
|
79
|
+
except json.JSONDecodeError:
|
|
80
|
+
continue
|
|
81
|
+
for selector in _speakable_selectors(data):
|
|
82
|
+
if not soup.select(selector):
|
|
83
|
+
findings.append(_f(
|
|
84
|
+
"aeo.speakable.unresolved", "speakable", url, "error",
|
|
85
|
+
f"speakable cssSelector {selector!r} matches no element",
|
|
86
|
+
"a selector resolving to real markup",
|
|
87
|
+
"Point speakable.cssSelector at the answer block that exists on "
|
|
88
|
+
"the page, or remove the claim."))
|
|
89
|
+
return findings
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _speakable_selectors(node: object) -> list[str]:
|
|
93
|
+
found: list[str] = []
|
|
94
|
+
if isinstance(node, dict):
|
|
95
|
+
speakable = node.get("speakable")
|
|
96
|
+
if isinstance(speakable, dict):
|
|
97
|
+
raw = speakable.get("cssSelector", [])
|
|
98
|
+
found.extend([raw] if isinstance(raw, str) else list(raw))
|
|
99
|
+
for value in node.values():
|
|
100
|
+
found.extend(_speakable_selectors(value))
|
|
101
|
+
elif isinstance(node, list):
|
|
102
|
+
for item in node:
|
|
103
|
+
found.extend(_speakable_selectors(item))
|
|
104
|
+
return found
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def run(html: str, url: str, selector: str = ".answer-block",
|
|
108
|
+
band: Band | None = None) -> list[Finding]:
|
|
109
|
+
soup = BeautifulSoup(html, "lxml")
|
|
110
|
+
return [
|
|
111
|
+
*_answer_block(soup, url, selector, band or DEFAULT_BAND),
|
|
112
|
+
*_faq(soup, url),
|
|
113
|
+
*_speakable(soup, url),
|
|
114
|
+
]
|