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,468 @@
|
|
|
1
|
+
"""Blog pack checks that look across posts and files: dates, links, clusters, archives,
|
|
2
|
+
feeds, sitemap, pagination, refresh and Search Console data. Called from ``blog.run_blog``."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import math
|
|
7
|
+
import re
|
|
8
|
+
from collections import Counter
|
|
9
|
+
from datetime import date
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from urllib.parse import unquote, urlsplit
|
|
12
|
+
|
|
13
|
+
from bs4 import BeautifulSoup
|
|
14
|
+
|
|
15
|
+
from ..aeo.extract import parse_date
|
|
16
|
+
from . import feeds as feedmod
|
|
17
|
+
from .blog import (
|
|
18
|
+
MAX_FILE_BYTES,
|
|
19
|
+
MAX_SUGGESTIONS_PER_POST,
|
|
20
|
+
NO_WORD_BOUNDARY_LANGS,
|
|
21
|
+
THIN_ARCHIVE_POSTS,
|
|
22
|
+
WPM,
|
|
23
|
+
_nfc,
|
|
24
|
+
_pick,
|
|
25
|
+
_rel,
|
|
26
|
+
parse_iso_date,
|
|
27
|
+
)
|
|
28
|
+
from .mdscan import hidden_line_numbers, html_tags, strip_inline_code
|
|
29
|
+
from .model import ADVICE, ERROR, WARNING
|
|
30
|
+
|
|
31
|
+
UPDATED_MARKERS = ("last updated", "last modified", "updated on", "modified on", "updated",
|
|
32
|
+
"revised")
|
|
33
|
+
PUBLISHED_MARKERS = ("published on", "published", "posted on", "posted")
|
|
34
|
+
ARTICLE_TYPES = {"article", "blogposting", "newsarticle", "techarticle", "scholarlyarticle"}
|
|
35
|
+
MAX_LD_BYTES = 200_000
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _seg(url_or_path: str) -> str:
|
|
39
|
+
path = urlsplit(url_or_path).path if "://" in url_or_path else url_or_path.split("#")[0].split("?")[0]
|
|
40
|
+
parts = [unquote(x) for x in path.split("/") if x]
|
|
41
|
+
while parts and parts[-1].lower() in ("index", "index.html", "index.htm", "index.md"):
|
|
42
|
+
parts.pop()
|
|
43
|
+
if not parts:
|
|
44
|
+
return ""
|
|
45
|
+
last = parts[-1]
|
|
46
|
+
for ext in (".html", ".htm", ".md", ".mdx", ".markdown"):
|
|
47
|
+
if last.lower().endswith(ext):
|
|
48
|
+
last = last[: -len(ext)]
|
|
49
|
+
return _nfc(last)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _host(url: str) -> str | None:
|
|
53
|
+
try:
|
|
54
|
+
h = urlsplit(url).netloc.lower()
|
|
55
|
+
except ValueError:
|
|
56
|
+
return None
|
|
57
|
+
return h or None
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _visible_dates(lines, hidden) -> list[tuple[str, date, int, str]]:
|
|
61
|
+
out = []
|
|
62
|
+
for ln in lines:
|
|
63
|
+
if ln.no in hidden:
|
|
64
|
+
continue
|
|
65
|
+
text = strip_inline_code(ln.text).strip().lstrip(">-* ").replace("**", "").replace("__", "")
|
|
66
|
+
low = text.casefold()
|
|
67
|
+
for kind, markers in (("updated", UPDATED_MARKERS), ("published", PUBLISHED_MARKERS)):
|
|
68
|
+
hit = next((m for m in markers if low.startswith(m)), None)
|
|
69
|
+
if hit:
|
|
70
|
+
rest = text[len(hit):].lstrip(" :–—-\t")
|
|
71
|
+
d = parse_date(rest[:60], at_start=True)
|
|
72
|
+
if d:
|
|
73
|
+
out.append((kind, d, ln.no, text[:60]))
|
|
74
|
+
break
|
|
75
|
+
return out
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _ld_dates(text: str) -> list[tuple[str, date]]:
|
|
79
|
+
out: list[tuple[str, date]] = []
|
|
80
|
+
low = text.lower()
|
|
81
|
+
for off, attrs, raw in html_tags(text, "script"):
|
|
82
|
+
if "ld+json" not in attrs.get("type", "").lower():
|
|
83
|
+
continue
|
|
84
|
+
start = off + len(raw)
|
|
85
|
+
end = low.find("</script", start, start + MAX_LD_BYTES)
|
|
86
|
+
if end == -1:
|
|
87
|
+
continue
|
|
88
|
+
try:
|
|
89
|
+
data = json.loads(text[start:end])
|
|
90
|
+
except (ValueError, RecursionError):
|
|
91
|
+
continue
|
|
92
|
+
stack = [data]
|
|
93
|
+
budget = 2000
|
|
94
|
+
while stack and budget:
|
|
95
|
+
budget -= 1
|
|
96
|
+
node = stack.pop()
|
|
97
|
+
if isinstance(node, list):
|
|
98
|
+
stack.extend(node[:200])
|
|
99
|
+
elif isinstance(node, dict):
|
|
100
|
+
types = node.get("@type")
|
|
101
|
+
types = [types] if isinstance(types, str) else (types if isinstance(types, list) else [])
|
|
102
|
+
if any(isinstance(t, str) and t.lower() in ARTICLE_TYPES for t in types):
|
|
103
|
+
for key in ("datePublished", "dateModified"):
|
|
104
|
+
v = node.get(key)
|
|
105
|
+
d = parse_iso_date(v) or (parse_iso_date(v[:10]) if isinstance(v, str) else None)
|
|
106
|
+
if d:
|
|
107
|
+
out.append((key, d))
|
|
108
|
+
graph = node.get("@graph")
|
|
109
|
+
if isinstance(graph, list):
|
|
110
|
+
stack.extend(graph[:200])
|
|
111
|
+
return out
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def cross_checks(run, html_files, xml_files, gsc_csv, gsc_prev_csv, use_git) -> None:
|
|
115
|
+
rep = run.rep
|
|
116
|
+
root = run.root
|
|
117
|
+
valid = [p for p in run.posts if p.ok and not p.archive]
|
|
118
|
+
published = [p for p in valid if not p.draft]
|
|
119
|
+
archives = [p for p in run.posts if p.ok and p.archive]
|
|
120
|
+
|
|
121
|
+
slug_index: dict[str, list] = {}
|
|
122
|
+
stem_index: dict[str, list] = {}
|
|
123
|
+
for p in valid:
|
|
124
|
+
slug_index.setdefault(p.slug, []).append(p)
|
|
125
|
+
stem_index.setdefault(p.stem, []).append(p)
|
|
126
|
+
|
|
127
|
+
def lookup(seg: str):
|
|
128
|
+
got = slug_index.get(seg) or stem_index.get(seg) or []
|
|
129
|
+
return got[0] if len(got) == 1 else None
|
|
130
|
+
|
|
131
|
+
# --- duplicate slugs
|
|
132
|
+
for slug, group in sorted(slug_index.items()):
|
|
133
|
+
if len(group) > 1:
|
|
134
|
+
for p in group:
|
|
135
|
+
others = ", ".join(q.path for q in group if q is not p)
|
|
136
|
+
run.add("blog.slug.duplicate", ERROR,
|
|
137
|
+
f"slug {slug!r} is also used by {others}; two posts cannot share a URL",
|
|
138
|
+
"[guideline]", p.path)
|
|
139
|
+
|
|
140
|
+
# --- own hosts, sitemap, feeds
|
|
141
|
+
for p in valid:
|
|
142
|
+
_, c = _pick(p.fm.data, "canonical")
|
|
143
|
+
if isinstance(c, str) and (h := _host(c)):
|
|
144
|
+
run.own_hosts.add(h)
|
|
145
|
+
sitemap_entries: list[tuple[str, date | None, str, str]] = []
|
|
146
|
+
feeds: list[feedmod.FeedInfo] = []
|
|
147
|
+
for x in xml_files:
|
|
148
|
+
rel = _rel(root, x)
|
|
149
|
+
name = x.name.lower()
|
|
150
|
+
if name.startswith("sitemap"):
|
|
151
|
+
entries, problem = feedmod.parse_sitemap(x)
|
|
152
|
+
if problem:
|
|
153
|
+
if problem[0] == "unsafe":
|
|
154
|
+
run.add("blog.sitemap.unsafe-xml", ERROR, problem[1], "[standard]", rel)
|
|
155
|
+
elif problem[0] != "not-a-feed":
|
|
156
|
+
run.add("blog.sitemap.unreadable", WARNING,
|
|
157
|
+
f"sitemap could not be read ({problem[0]}): {problem[1][:120]}",
|
|
158
|
+
"[standard]", rel)
|
|
159
|
+
continue
|
|
160
|
+
for loc, d, raw in entries or []:
|
|
161
|
+
if (h := _host(loc)):
|
|
162
|
+
run.own_hosts.add(h)
|
|
163
|
+
sitemap_entries.append((loc, d, raw or "", rel))
|
|
164
|
+
elif name in feedmod.FEED_NAMES:
|
|
165
|
+
info, problem = feedmod.parse_feed(x, rel)
|
|
166
|
+
if problem:
|
|
167
|
+
code, detail = problem
|
|
168
|
+
if code == "unsafe":
|
|
169
|
+
run.add("blog.feed.unsafe-xml", ERROR, detail, "[standard]", rel)
|
|
170
|
+
elif code in ("malformed", "too-large", "unreadable"):
|
|
171
|
+
run.add("blog.feed.unreadable", ERROR,
|
|
172
|
+
f"feed could not be read ({code}): {detail[:120]}", "[standard]", rel)
|
|
173
|
+
continue
|
|
174
|
+
feeds.append(info)
|
|
175
|
+
if info.channel_link and (h := _host(info.channel_link)):
|
|
176
|
+
run.own_hosts.add(h)
|
|
177
|
+
for prob_id, sev, msg in info.problems:
|
|
178
|
+
run.add(prob_id, sev, msg, "[standard]", rel)
|
|
179
|
+
|
|
180
|
+
# --- posts summary
|
|
181
|
+
for p in sorted(run.posts, key=lambda q: q.path):
|
|
182
|
+
if p.archive:
|
|
183
|
+
continue
|
|
184
|
+
lang = None
|
|
185
|
+
_, lv = _pick(p.fm.data, "language")
|
|
186
|
+
if isinstance(lv, str):
|
|
187
|
+
lang = lv.strip()
|
|
188
|
+
rt = None
|
|
189
|
+
if p.ok and not (lang and lang.lower().startswith(NO_WORD_BOUNDARY_LANGS)):
|
|
190
|
+
rt = max(1, math.ceil(p.words / WPM))
|
|
191
|
+
rep.posts.append({
|
|
192
|
+
"path": p.path, "slug": p.slug if p.ok else None, "title": p.title,
|
|
193
|
+
"language": lang, "words": p.words, "reading_time_minutes": rt,
|
|
194
|
+
"tags": p.tags, "draft": p.draft, "status": "ok" if p.ok else "unparsed"})
|
|
195
|
+
|
|
196
|
+
# --- date consistency
|
|
197
|
+
sitemap_by_seg: dict[str, list] = {}
|
|
198
|
+
for loc, d, raw, rel in sitemap_entries:
|
|
199
|
+
sitemap_by_seg.setdefault(_seg(loc), []).append((loc, d, raw, rel))
|
|
200
|
+
feed_by_post: dict[str, list] = {}
|
|
201
|
+
for info in feeds:
|
|
202
|
+
for e in info.entries:
|
|
203
|
+
target = None
|
|
204
|
+
for ref in (e.link, e.guid):
|
|
205
|
+
if ref and (q := lookup(_seg(ref))):
|
|
206
|
+
target = q
|
|
207
|
+
break
|
|
208
|
+
if target is None:
|
|
209
|
+
continue
|
|
210
|
+
feed_by_post.setdefault(target.path, []).append((info, e))
|
|
211
|
+
if target.draft:
|
|
212
|
+
run.add("blog.feed.draft-listed", WARNING,
|
|
213
|
+
f"draft post {target.slug!r} is listed in the feed", "[guideline]",
|
|
214
|
+
info.path)
|
|
215
|
+
for p in valid:
|
|
216
|
+
d_pub, d_upd = p.dates.get("date"), p.dates.get("updated")
|
|
217
|
+
expected_mod = d_upd or d_pub
|
|
218
|
+
mod_src = "updated" if d_upd else "date"
|
|
219
|
+
hidden = hidden_line_numbers(p.lines)
|
|
220
|
+
for kind, d, lineno, snippet in _visible_dates(p.lines, hidden):
|
|
221
|
+
if kind == "updated" and d != d_upd:
|
|
222
|
+
shown = d_upd.isoformat() if d_upd else "missing"
|
|
223
|
+
run.add("blog.dates.visible-mismatch", WARNING,
|
|
224
|
+
f"visible {snippet!r} says {d.isoformat()} but frontmatter updated is "
|
|
225
|
+
f"{shown}", "[guideline]", p.path, lineno)
|
|
226
|
+
elif kind == "published" and d_pub and d != d_pub:
|
|
227
|
+
run.add("blog.dates.visible-mismatch", WARNING,
|
|
228
|
+
f"visible {snippet!r} says {d.isoformat()} but frontmatter date is "
|
|
229
|
+
f"{d_pub.isoformat()}", "[guideline]", p.path, lineno)
|
|
230
|
+
joined = "\n".join(ln.text for ln in p.lines)
|
|
231
|
+
for key, d in _ld_dates(joined):
|
|
232
|
+
if key == "datePublished" and d_pub and d != d_pub:
|
|
233
|
+
run.add("blog.dates.schema-mismatch", WARNING,
|
|
234
|
+
f"JSON-LD datePublished {d.isoformat()} differs from frontmatter date "
|
|
235
|
+
f"{d_pub.isoformat()}", "[guideline]", p.path)
|
|
236
|
+
if key == "dateModified" and expected_mod and d != expected_mod:
|
|
237
|
+
run.add("blog.dates.schema-mismatch", WARNING,
|
|
238
|
+
f"JSON-LD dateModified {d.isoformat()} differs from frontmatter "
|
|
239
|
+
f"{mod_src} {expected_mod.isoformat()}", "[guideline]", p.path)
|
|
240
|
+
if p.draft:
|
|
241
|
+
continue
|
|
242
|
+
hits = sitemap_by_seg.get(p.slug) or sitemap_by_seg.get(p.stem) or []
|
|
243
|
+
if len(hits) > 1:
|
|
244
|
+
run.note(f"sitemap has {len(hits)} entries ending in '{p.slug}' (ambiguous); date "
|
|
245
|
+
f"comparison skipped for {p.path}")
|
|
246
|
+
elif len(hits) == 1 and hits[0][1] and expected_mod and hits[0][1] != expected_mod:
|
|
247
|
+
run.add("blog.dates.sitemap-mismatch", WARNING,
|
|
248
|
+
f"sitemap lastmod {hits[0][1].isoformat()} differs from frontmatter "
|
|
249
|
+
f"{mod_src} {expected_mod.isoformat()} ({hits[0][3]})", "[guideline]", p.path)
|
|
250
|
+
for info, e in feed_by_post.get(p.path, []):
|
|
251
|
+
if info.kind == "rss" and e.date and e.date not in (d_pub, d_upd) and (d_pub or d_upd):
|
|
252
|
+
run.add("blog.dates.feed-mismatch", WARNING,
|
|
253
|
+
f"feed pubDate {e.date.isoformat()} matches neither frontmatter date "
|
|
254
|
+
f"({d_pub.isoformat() if d_pub else 'missing'}) nor updated "
|
|
255
|
+
f"({d_upd.isoformat() if d_upd else 'missing'}) ({info.path})",
|
|
256
|
+
"[guideline]", p.path)
|
|
257
|
+
if info.kind == "atom":
|
|
258
|
+
if e.date and e.date not in (d_pub, d_upd) and (d_pub or d_upd):
|
|
259
|
+
run.add("blog.dates.feed-mismatch", WARNING,
|
|
260
|
+
f"feed updated {e.date.isoformat()} matches neither frontmatter "
|
|
261
|
+
f"updated nor date ({info.path})", "[guideline]", p.path)
|
|
262
|
+
if e.published and d_pub and e.published != d_pub:
|
|
263
|
+
run.add("blog.dates.feed-mismatch", WARNING,
|
|
264
|
+
f"feed published {e.published.isoformat()} differs from frontmatter "
|
|
265
|
+
f"date {d_pub.isoformat()} ({info.path})", "[guideline]", p.path)
|
|
266
|
+
if feeds:
|
|
267
|
+
matched = {path for path in feed_by_post}
|
|
268
|
+
missing = [p for p in published if p.path not in matched]
|
|
269
|
+
if missing and len(published) > 0:
|
|
270
|
+
names = ", ".join(sorted(p.slug for p in missing)[:10])
|
|
271
|
+
more = "" if len(missing) <= 10 else f" and {len(missing) - 10} more"
|
|
272
|
+
run.add("blog.feed.missing-posts", ADVICE,
|
|
273
|
+
f"{len(missing)} published post(s) are not in any feed: {names}{more} "
|
|
274
|
+
"(feeds often list only recent posts; ignore if that is deliberate)",
|
|
275
|
+
"[guideline]", feeds[0].path)
|
|
276
|
+
elif published and not any(
|
|
277
|
+
f.id.startswith("blog.feed.") for f in rep.findings):
|
|
278
|
+
run.add("blog.feed.none", ADVICE,
|
|
279
|
+
"no RSS or Atom feed found in the project (rss.xml, feed.xml, atom.xml, "
|
|
280
|
+
"index.xml); readers and aggregators need one to follow the blog",
|
|
281
|
+
"[guideline]")
|
|
282
|
+
|
|
283
|
+
# --- related, links, orphans
|
|
284
|
+
known = {p.slug for p in valid} | {p.stem for p in valid}
|
|
285
|
+
for p in valid:
|
|
286
|
+
rel_val = p.fm.data.get("related")
|
|
287
|
+
if isinstance(rel_val, list):
|
|
288
|
+
for item in rel_val:
|
|
289
|
+
if isinstance(item, str) and _nfc(item.strip()) not in known:
|
|
290
|
+
run.add("blog.related.unknown", WARNING,
|
|
291
|
+
f"related lists {item!r} but no post has that slug",
|
|
292
|
+
"[guideline]", p.path)
|
|
293
|
+
|
|
294
|
+
inbound: Counter = Counter()
|
|
295
|
+
for p in valid:
|
|
296
|
+
for _lineno, ref in p.refs:
|
|
297
|
+
target = ref.target.strip()
|
|
298
|
+
if target.startswith(("mailto:", "tel:", "javascript:")):
|
|
299
|
+
continue
|
|
300
|
+
if "://" in target or target.startswith("//"):
|
|
301
|
+
host = _host(target if "://" in target else "https:" + target)
|
|
302
|
+
if host not in run.own_hosts:
|
|
303
|
+
continue
|
|
304
|
+
q = lookup(_seg(target))
|
|
305
|
+
if q is not None and q is not p:
|
|
306
|
+
p.out_slugs.add(q.path)
|
|
307
|
+
if not p.draft:
|
|
308
|
+
inbound[q.path] += 1
|
|
309
|
+
if len(published) >= 2:
|
|
310
|
+
for p in published:
|
|
311
|
+
if inbound[p.path] == 0:
|
|
312
|
+
run.add("blog.links.orphan", ADVICE,
|
|
313
|
+
"no other published post links to this one; internal links help "
|
|
314
|
+
"readers and crawlers find it", "[guideline]", p.path)
|
|
315
|
+
if not p.out_slugs:
|
|
316
|
+
run.add("blog.links.no-outbound", ADVICE,
|
|
317
|
+
"this post links to no other post", "[guideline]", p.path)
|
|
318
|
+
|
|
319
|
+
# --- clusters and link suggestions
|
|
320
|
+
def tkey(t: str) -> str:
|
|
321
|
+
return _nfc(t).casefold().replace("_", "-").replace(" ", "-")
|
|
322
|
+
|
|
323
|
+
by_tag: dict[str, list] = {}
|
|
324
|
+
for p in published:
|
|
325
|
+
for t in {tkey(t) for t in p.tags}:
|
|
326
|
+
by_tag.setdefault(t, []).append(p)
|
|
327
|
+
for tag, group in sorted(by_tag.items()):
|
|
328
|
+
if len(group) < 2:
|
|
329
|
+
continue
|
|
330
|
+
pillars = [p for p in group if p.fm.data.get("pillar") is True
|
|
331
|
+
or p.fm.data.get("hub") is True]
|
|
332
|
+
if pillars:
|
|
333
|
+
hub = min(pillars, key=lambda p: p.path)
|
|
334
|
+
else:
|
|
335
|
+
hub = min(group, key=lambda p: (-inbound[p.path], -p.words, p.path))
|
|
336
|
+
rep.clusters.append({"tag": tag, "posts": sorted(p.slug for p in group),
|
|
337
|
+
"hub": hub.slug,
|
|
338
|
+
"spokes": sorted(p.slug for p in group if p is not hub),
|
|
339
|
+
"hub_reason": "pillar/hub frontmatter" if pillars else
|
|
340
|
+
"most inbound internal links, then longest"})
|
|
341
|
+
suggestions: list[dict] = []
|
|
342
|
+
for a in published:
|
|
343
|
+
shared_by_b: dict[str, tuple[object, list[str]]] = {}
|
|
344
|
+
a_tags = {tkey(t) for t in a.tags}
|
|
345
|
+
for t in a_tags:
|
|
346
|
+
for b in by_tag.get(t, []):
|
|
347
|
+
if b is not a and b.path not in a.out_slugs:
|
|
348
|
+
shared_by_b.setdefault(b.path, (b, []))[1].append(t)
|
|
349
|
+
ranked = sorted(shared_by_b.values(), key=lambda bt: (-len(bt[1]), bt[0].slug))
|
|
350
|
+
text = " ".join(strip_inline_code(ln.text) for ln in a.lines)
|
|
351
|
+
link_free = _strip_links(text)
|
|
352
|
+
for b, tags in ranked[:MAX_SUGGESTIONS_PER_POST]:
|
|
353
|
+
anchor = None
|
|
354
|
+
if b.title and 4 <= len(b.title) <= 200:
|
|
355
|
+
m = re.search(re.escape(b.title), link_free[:200_000], re.IGNORECASE)
|
|
356
|
+
if m:
|
|
357
|
+
anchor = m.group(0)
|
|
358
|
+
suggestions.append({"from": a.slug, "to": b.slug, "from_path": a.path,
|
|
359
|
+
"to_path": b.path, "via_tags": sorted(tags), "anchor": anchor,
|
|
360
|
+
"evidence": "[guideline]"})
|
|
361
|
+
rep.link_suggestions = suggestions[:2000]
|
|
362
|
+
|
|
363
|
+
# --- tags: spelling variants and thin archives
|
|
364
|
+
spellings: dict[str, Counter] = {}
|
|
365
|
+
first_user: dict[str, dict[str, str]] = {}
|
|
366
|
+
for p in sorted(published, key=lambda q: q.path):
|
|
367
|
+
for t in p.tags:
|
|
368
|
+
spellings.setdefault(tkey(t), Counter())[t] += 1
|
|
369
|
+
first_user.setdefault(tkey(t), {}).setdefault(t, p.path)
|
|
370
|
+
for key, counter in sorted(spellings.items()):
|
|
371
|
+
if len(counter) > 1:
|
|
372
|
+
majority = counter.most_common(1)[0][0]
|
|
373
|
+
minority = sorted(s for s in counter if s != majority)
|
|
374
|
+
run.add("blog.tags.case-variants", WARNING,
|
|
375
|
+
"tag spelled more than one way: " + ", ".join(
|
|
376
|
+
f"{s!r} ({n})" for s, n in counter.most_common())
|
|
377
|
+
+ "; each spelling can get its own archive page and split the cluster",
|
|
378
|
+
"[guideline]", first_user[key][minority[0]])
|
|
379
|
+
tag_counts = {k: len(v) for k, v in by_tag.items()}
|
|
380
|
+
|
|
381
|
+
def is_noindex(fm_data: dict) -> bool:
|
|
382
|
+
robots = fm_data.get("robots")
|
|
383
|
+
return (fm_data.get("noindex") is True or fm_data.get("index") is False
|
|
384
|
+
or (isinstance(robots, str) and "noindex" in robots.lower()))
|
|
385
|
+
|
|
386
|
+
for a in archives:
|
|
387
|
+
key = tkey(str(a.fm.data.get("tag") or a.fm.data.get("slug") or a.stem))
|
|
388
|
+
n = tag_counts.get(key, 0)
|
|
389
|
+
if n < THIN_ARCHIVE_POSTS and not is_noindex(a.fm.data):
|
|
390
|
+
run.add("blog.tags.thin-archive-indexable", WARNING,
|
|
391
|
+
f"archive for {key!r} lists {n} post(s) (fewer than {THIN_ARCHIVE_POSTS}) "
|
|
392
|
+
"and is indexable; thin archives add near-empty pages. Mark it noindex "
|
|
393
|
+
"or merge the tag", "[guideline]", a.path)
|
|
394
|
+
|
|
395
|
+
# --- html: tag archives and pagination
|
|
396
|
+
for h in html_files:
|
|
397
|
+
rel = _rel(root, h)
|
|
398
|
+
parts = Path(rel).parts
|
|
399
|
+
try:
|
|
400
|
+
if h.stat().st_size > MAX_FILE_BYTES:
|
|
401
|
+
continue
|
|
402
|
+
soup = BeautifulSoup(h.read_bytes().decode("utf-8", "replace"), "html.parser")
|
|
403
|
+
except OSError:
|
|
404
|
+
continue
|
|
405
|
+
lowparts = [x.lower() for x in parts[:-1]]
|
|
406
|
+
# pagination: .../page/N/index.html
|
|
407
|
+
for i, part in enumerate(lowparts[:-1]):
|
|
408
|
+
if part == "page" and lowparts[i + 1].isdigit() and int(lowparts[i + 1]) >= 2:
|
|
409
|
+
n = lowparts[i + 1]
|
|
410
|
+
canon = next((t.get("href") for t in soup.find_all("link")
|
|
411
|
+
if "canonical" in (t.get("rel") or []) and t.get("href")), None)
|
|
412
|
+
if canon:
|
|
413
|
+
cpath = urlsplit(canon).path
|
|
414
|
+
if cpath.rstrip("/").endswith(f"/page/{n}"):
|
|
415
|
+
break
|
|
416
|
+
dirpath = "/" + "/".join(parts[:-1])
|
|
417
|
+
if dirpath.endswith(cpath.rstrip("/") + f"/page/{n}"):
|
|
418
|
+
run.add("blog.pagination.canonical-to-first", ERROR,
|
|
419
|
+
f"page {n} of a paginated list has canonical {canon!r}, the "
|
|
420
|
+
"first page; Google treats paginated pages as separate pages "
|
|
421
|
+
"and may drop the items that only appear here. Use a "
|
|
422
|
+
"self-referencing canonical", "[guideline]", rel)
|
|
423
|
+
else:
|
|
424
|
+
run.add("blog.pagination.canonical-not-self", WARNING,
|
|
425
|
+
f"page {n} canonical is {canon!r}, not the page itself",
|
|
426
|
+
"[guideline]", rel)
|
|
427
|
+
break
|
|
428
|
+
# tag/category HTML archives
|
|
429
|
+
for i, part in enumerate(lowparts):
|
|
430
|
+
if part in ("tag", "tags", "category", "categories") and i + 1 < len(parts) - 1:
|
|
431
|
+
key = tkey(parts[i + 1])
|
|
432
|
+
robots = next((m.get("content", "") for m in soup.find_all("meta")
|
|
433
|
+
if (m.get("name") or "").lower() == "robots"), "")
|
|
434
|
+
targets = {q.path for a in soup.find_all("a", href=True)
|
|
435
|
+
if (q := lookup(_seg(a["href"]))) and not q.draft}
|
|
436
|
+
if len(targets) < THIN_ARCHIVE_POSTS and "noindex" not in robots.lower():
|
|
437
|
+
run.add("blog.tags.thin-archive-indexable", WARNING,
|
|
438
|
+
f"archive for {key!r} links {len(targets)} post(s) (fewer than "
|
|
439
|
+
f"{THIN_ARCHIVE_POSTS}) and is indexable; mark it noindex or "
|
|
440
|
+
"merge the tag", "[guideline]", rel)
|
|
441
|
+
break
|
|
442
|
+
|
|
443
|
+
# --- refresh and Search Console
|
|
444
|
+
from .refresh import check_refresh
|
|
445
|
+
check_refresh(run, valid, use_git)
|
|
446
|
+
if gsc_csv or gsc_prev_csv:
|
|
447
|
+
from .gsc import analyse_gsc
|
|
448
|
+
rep.gsc = analyse_gsc(run, valid, gsc_csv, gsc_prev_csv)
|
|
449
|
+
else:
|
|
450
|
+
run.note("cannibalization and content-decay checks need a Search Console export "
|
|
451
|
+
"(--gsc-csv); none was given, so they were not run")
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def _strip_links(text: str) -> str:
|
|
455
|
+
"""Remove ``[label](target)`` spans so a suggested anchor never sits inside a link."""
|
|
456
|
+
out: list[str] = []
|
|
457
|
+
i, n = 0, len(text)
|
|
458
|
+
while i < n:
|
|
459
|
+
if text[i] == "[":
|
|
460
|
+
close = text.find("](", i, i + 500)
|
|
461
|
+
end = text.find(")", close, close + 800) if close != -1 else -1
|
|
462
|
+
if close != -1 and end != -1:
|
|
463
|
+
out.append(" ")
|
|
464
|
+
i = end + 1
|
|
465
|
+
continue
|
|
466
|
+
out.append(text[i])
|
|
467
|
+
i += 1
|
|
468
|
+
return "".join(out)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""AI-crawler policy for the product pack.
|
|
2
|
+
|
|
3
|
+
The taxonomy, robots.txt reading and snippet generator now live in ``omnirank.crawlers``
|
|
4
|
+
(dated table in ``data/ai_crawlers.json``, per-entry ``verified`` flag). This module only
|
|
5
|
+
re-exports the names the product pack and its tests have always imported, so there is one
|
|
6
|
+
implementation and one table.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from ..crawlers import ( # noqa: F401
|
|
11
|
+
CATEGORIES,
|
|
12
|
+
CRAWLERS,
|
|
13
|
+
DISCLAIMER,
|
|
14
|
+
TABLE_CHECKED_ON,
|
|
15
|
+
TRADEOFFS,
|
|
16
|
+
VALID_CHOICES,
|
|
17
|
+
Crawler,
|
|
18
|
+
describe,
|
|
19
|
+
render_snippet,
|
|
20
|
+
star_rules,
|
|
21
|
+
tokens_for,
|
|
22
|
+
validate_choices,
|
|
23
|
+
)
|