@consilioweb/payload-seo-analyzer 1.7.1 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -8
- package/dist/client.cjs +1179 -193
- package/dist/client.js +1179 -193
- package/dist/index.cjs +1378 -133
- package/dist/index.d.cts +43 -1
- package/dist/index.d.ts +43 -1
- package/dist/index.js +1379 -134
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -15,7 +15,7 @@ var MIN_WORDS_GENERIC = 300;
|
|
|
15
15
|
var MIN_WORDS_THIN = 100;
|
|
16
16
|
var MIN_WORDS_QUALITY_FAIL = 50;
|
|
17
17
|
var MIN_WORDS_QUALITY_WARN = 200;
|
|
18
|
-
var CORNERSTONE_MIN_WORDS =
|
|
18
|
+
var CORNERSTONE_MIN_WORDS = 600;
|
|
19
19
|
var THIN_AGING_MIN_WORDS = 500;
|
|
20
20
|
var KEYWORD_DENSITY_MAX = 3;
|
|
21
21
|
var KEYWORD_DENSITY_WARN = 2.5;
|
|
@@ -1228,6 +1228,44 @@ function buildSeoInputFromDoc(doc, collection, options) {
|
|
|
1228
1228
|
const meta = doc.meta || {};
|
|
1229
1229
|
const hero = doc.hero || {};
|
|
1230
1230
|
const isPost = collection === "posts";
|
|
1231
|
+
const canonicalUrl = typeof meta.canonicalUrl === "string" && meta.canonicalUrl || typeof doc.canonicalUrl === "string" && doc.canonicalUrl || void 0;
|
|
1232
|
+
let robotsMeta;
|
|
1233
|
+
const rawRobots = typeof meta.robots === "string" && meta.robots || typeof doc.robots === "string" && doc.robots || "";
|
|
1234
|
+
if (rawRobots) {
|
|
1235
|
+
robotsMeta = rawRobots;
|
|
1236
|
+
} else {
|
|
1237
|
+
const directives = [];
|
|
1238
|
+
if (doc.noindex === true || meta.noindex === true) directives.push("noindex");
|
|
1239
|
+
if (doc.nofollow === true || meta.nofollow === true) directives.push("nofollow");
|
|
1240
|
+
if (directives.length > 0) robotsMeta = directives.join(", ");
|
|
1241
|
+
}
|
|
1242
|
+
let author;
|
|
1243
|
+
let authorUrl;
|
|
1244
|
+
const populatedAuthors = doc.populatedAuthors;
|
|
1245
|
+
if (Array.isArray(populatedAuthors) && populatedAuthors.length > 0) {
|
|
1246
|
+
const a = populatedAuthors[0] || {};
|
|
1247
|
+
author = typeof a.name === "string" && a.name || typeof a.firstName === "string" && a.firstName || void 0;
|
|
1248
|
+
if (typeof a.url === "string") authorUrl = a.url;
|
|
1249
|
+
} else if (Array.isArray(doc.authors) && doc.authors.length > 0) {
|
|
1250
|
+
const a = doc.authors[0];
|
|
1251
|
+
if (a && typeof a === "object" && typeof a.name === "string") author = a.name;
|
|
1252
|
+
} else if (typeof doc.author === "string" && doc.author) {
|
|
1253
|
+
author = doc.author;
|
|
1254
|
+
} else if (doc.author && typeof doc.author === "object" && typeof doc.author.name === "string") {
|
|
1255
|
+
author = doc.author.name;
|
|
1256
|
+
}
|
|
1257
|
+
if (!authorUrl && typeof doc.authorUrl === "string") authorUrl = doc.authorUrl;
|
|
1258
|
+
const publishedAt = typeof doc.publishedAt === "string" && doc.publishedAt || typeof doc.createdAt === "string" && doc.createdAt || void 0;
|
|
1259
|
+
const displayedDate = typeof doc.publishedAt === "string" && doc.publishedAt || typeof doc.date === "string" && doc.date || void 0;
|
|
1260
|
+
let localeAlternates;
|
|
1261
|
+
const rawAlts = doc.localeAlternates || doc.alternates || doc.hreflang;
|
|
1262
|
+
if (Array.isArray(rawAlts)) {
|
|
1263
|
+
const mapped = rawAlts.filter((a) => !!a && typeof a === "object").map((a) => ({
|
|
1264
|
+
hreflang: String(a.hreflang || a.locale || a.lang || ""),
|
|
1265
|
+
href: String(a.href || a.url || "")
|
|
1266
|
+
})).filter((a) => a.hreflang && a.href);
|
|
1267
|
+
if (mapped.length > 0) localeAlternates = mapped;
|
|
1268
|
+
}
|
|
1231
1269
|
return {
|
|
1232
1270
|
metaTitle: meta.title || "",
|
|
1233
1271
|
metaDescription: meta.description || "",
|
|
@@ -1247,7 +1285,14 @@ function buildSeoInputFromDoc(doc, collection, options) {
|
|
|
1247
1285
|
isPost,
|
|
1248
1286
|
isCornerstone: !!doc.isCornerstone,
|
|
1249
1287
|
updatedAt: doc.updatedAt || void 0,
|
|
1288
|
+
publishedAt,
|
|
1250
1289
|
contentLastReviewed: doc.contentLastReviewed || void 0,
|
|
1290
|
+
displayedDate,
|
|
1291
|
+
author,
|
|
1292
|
+
authorUrl,
|
|
1293
|
+
localeAlternates,
|
|
1294
|
+
canonicalUrl,
|
|
1295
|
+
robotsMeta,
|
|
1251
1296
|
isGlobal: options?.isGlobal ?? false
|
|
1252
1297
|
};
|
|
1253
1298
|
}
|
|
@@ -1625,6 +1670,7 @@ function analyzeDoc(doc, collection, seoConfig) {
|
|
|
1625
1670
|
hasH1: h1Count > 0,
|
|
1626
1671
|
h1Count,
|
|
1627
1672
|
score: analysis.score,
|
|
1673
|
+
aiReadiness: analysis.aiReadiness ? analysis.aiReadiness.score : null,
|
|
1628
1674
|
level: analysis.level,
|
|
1629
1675
|
status: doc._status || "published",
|
|
1630
1676
|
updatedAt: doc.updatedAt || "",
|
|
@@ -1760,6 +1806,97 @@ function createAuditHandler(collections, seoConfig, globals = []) {
|
|
|
1760
1806
|
};
|
|
1761
1807
|
}
|
|
1762
1808
|
|
|
1809
|
+
// src/endpoints/indexationAudit.ts
|
|
1810
|
+
var INDEXATION_CHECK_IDS = /* @__PURE__ */ new Set([
|
|
1811
|
+
"robots-noindex",
|
|
1812
|
+
"robots-nofollow",
|
|
1813
|
+
"canonical-cross",
|
|
1814
|
+
"canonical-external",
|
|
1815
|
+
"canonical-invalid",
|
|
1816
|
+
"canonical-missing"
|
|
1817
|
+
]);
|
|
1818
|
+
function createIndexationAuditHandler(collections, seoConfig, globals = []) {
|
|
1819
|
+
return async (req) => {
|
|
1820
|
+
try {
|
|
1821
|
+
if (!req.user) {
|
|
1822
|
+
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
1823
|
+
}
|
|
1824
|
+
const { config: mergedConfig, ignoredSlugs } = await loadMergedConfig(req.payload, seoConfig);
|
|
1825
|
+
const entries = [];
|
|
1826
|
+
const inspect = (doc, collection, isGlobal = false) => {
|
|
1827
|
+
const input = buildSeoInputFromDoc(doc, collection, { isGlobal });
|
|
1828
|
+
const analysis = analyzeSeo(input, mergedConfig);
|
|
1829
|
+
const issues = analysis.checks.filter(
|
|
1830
|
+
(c) => c.group === "technical" && INDEXATION_CHECK_IDS.has(c.id) && c.status !== "pass"
|
|
1831
|
+
).map((c) => ({ id: c.id, status: c.status, message: c.message }));
|
|
1832
|
+
const noindex = (input.robotsMeta || "").toLowerCase().includes("noindex");
|
|
1833
|
+
if (issues.length > 0 || noindex) {
|
|
1834
|
+
entries.push({
|
|
1835
|
+
collection,
|
|
1836
|
+
id: doc.id ?? (isGlobal ? collection : ""),
|
|
1837
|
+
slug: doc.slug || "",
|
|
1838
|
+
title: doc.title || doc.slug || String(doc.id ?? collection),
|
|
1839
|
+
noindex,
|
|
1840
|
+
issues
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
};
|
|
1844
|
+
for (const collectionSlug of collections) {
|
|
1845
|
+
try {
|
|
1846
|
+
let page = 1;
|
|
1847
|
+
let hasMore = true;
|
|
1848
|
+
while (hasMore) {
|
|
1849
|
+
const result = await req.payload.find({
|
|
1850
|
+
collection: collectionSlug,
|
|
1851
|
+
limit: 100,
|
|
1852
|
+
page,
|
|
1853
|
+
depth: 1,
|
|
1854
|
+
overrideAccess: true
|
|
1855
|
+
});
|
|
1856
|
+
for (const doc of result.docs) {
|
|
1857
|
+
if (ignoredSlugs.includes(doc.slug)) continue;
|
|
1858
|
+
inspect(doc, collectionSlug);
|
|
1859
|
+
}
|
|
1860
|
+
hasMore = result.hasNextPage;
|
|
1861
|
+
page++;
|
|
1862
|
+
}
|
|
1863
|
+
} catch {
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
for (const globalSlug of globals) {
|
|
1867
|
+
try {
|
|
1868
|
+
const doc = await req.payload.findGlobal({
|
|
1869
|
+
slug: globalSlug,
|
|
1870
|
+
depth: 1,
|
|
1871
|
+
overrideAccess: true
|
|
1872
|
+
});
|
|
1873
|
+
if (doc) inspect(doc, `global:${globalSlug}`, true);
|
|
1874
|
+
} catch {
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
const noindexCount = entries.filter((e) => e.noindex).length;
|
|
1878
|
+
const canonicalIssueCount = entries.filter(
|
|
1879
|
+
(e) => e.issues.some((i) => i.id.startsWith("canonical"))
|
|
1880
|
+
).length;
|
|
1881
|
+
return Response.json(
|
|
1882
|
+
{
|
|
1883
|
+
entries,
|
|
1884
|
+
summary: {
|
|
1885
|
+
totalFlagged: entries.length,
|
|
1886
|
+
noindexCount,
|
|
1887
|
+
canonicalIssueCount
|
|
1888
|
+
}
|
|
1889
|
+
},
|
|
1890
|
+
{ headers: { "Cache-Control": "no-store" } }
|
|
1891
|
+
);
|
|
1892
|
+
} catch (error) {
|
|
1893
|
+
const message = error instanceof Error ? error.message : "Internal server error";
|
|
1894
|
+
req.payload.logger.error(`[seo] indexation-audit error: ${message}`);
|
|
1895
|
+
return Response.json({ error: message }, { status: 500 });
|
|
1896
|
+
}
|
|
1897
|
+
};
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1763
1900
|
// src/endpoints/history.ts
|
|
1764
1901
|
var TREND_THRESHOLD = 3;
|
|
1765
1902
|
function createHistoryHandler() {
|
|
@@ -2746,6 +2883,9 @@ function createAiGenerateHandler() {
|
|
|
2746
2883
|
}
|
|
2747
2884
|
|
|
2748
2885
|
// src/endpoints/cannibalization.ts
|
|
2886
|
+
function canonicalIntent(keyword) {
|
|
2887
|
+
return keyword.toLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "").replace(/[^\p{L}\p{N}\s]/gu, " ").split(/\s+/).filter(Boolean).sort().join(" ");
|
|
2888
|
+
}
|
|
2749
2889
|
function createCannibalizationHandler(collections, globals = []) {
|
|
2750
2890
|
return async (req) => {
|
|
2751
2891
|
try {
|
|
@@ -2775,26 +2915,28 @@ function createCannibalizationHandler(collections, globals = []) {
|
|
|
2775
2915
|
collection: collectionLabel,
|
|
2776
2916
|
score: 0
|
|
2777
2917
|
};
|
|
2778
|
-
const
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2918
|
+
const seenCanon = /* @__PURE__ */ new Set();
|
|
2919
|
+
const docKeywords = [];
|
|
2920
|
+
const addKeyword = (raw) => {
|
|
2921
|
+
if (typeof raw !== "string") return;
|
|
2922
|
+
const display = raw.trim();
|
|
2923
|
+
if (!display) return;
|
|
2924
|
+
const key = canonicalIntent(display);
|
|
2925
|
+
if (!key || seenCanon.has(key)) return;
|
|
2926
|
+
seenCanon.add(key);
|
|
2927
|
+
docKeywords.push({ display, key });
|
|
2928
|
+
};
|
|
2929
|
+
addKeyword(d.focusKeyword);
|
|
2782
2930
|
if (Array.isArray(d.focusKeywords)) {
|
|
2783
2931
|
for (const kw of d.focusKeywords) {
|
|
2784
|
-
|
|
2785
|
-
if (keyword && typeof keyword === "string" && keyword.trim()) {
|
|
2786
|
-
const normalized = keyword.trim().toLowerCase();
|
|
2787
|
-
if (!keywords.includes(normalized)) {
|
|
2788
|
-
keywords.push(normalized);
|
|
2789
|
-
}
|
|
2790
|
-
}
|
|
2932
|
+
addKeyword(typeof kw === "string" ? kw : kw?.keyword);
|
|
2791
2933
|
}
|
|
2792
2934
|
}
|
|
2793
|
-
for (const
|
|
2794
|
-
if (!keywordMap.has(
|
|
2795
|
-
keywordMap.set(
|
|
2935
|
+
for (const { display, key } of docKeywords) {
|
|
2936
|
+
if (!keywordMap.has(key)) {
|
|
2937
|
+
keywordMap.set(key, { display, pages: [] });
|
|
2796
2938
|
}
|
|
2797
|
-
keywordMap.get(
|
|
2939
|
+
keywordMap.get(key).pages.push(pageEntry);
|
|
2798
2940
|
}
|
|
2799
2941
|
}
|
|
2800
2942
|
const scoreMap = /* @__PURE__ */ new Map();
|
|
@@ -2820,13 +2962,13 @@ function createCannibalizationHandler(collections, globals = []) {
|
|
|
2820
2962
|
const conflicts = [];
|
|
2821
2963
|
let totalAffectedPages = 0;
|
|
2822
2964
|
const affectedPageIds = /* @__PURE__ */ new Set();
|
|
2823
|
-
for (const
|
|
2965
|
+
for (const { display, pages } of keywordMap.values()) {
|
|
2824
2966
|
if (pages.length < 2) continue;
|
|
2825
2967
|
const enrichedPages = pages.map((p) => ({
|
|
2826
2968
|
...p,
|
|
2827
2969
|
score: scoreMap.get(`${p.collection}::${p.id}`) || 0
|
|
2828
2970
|
}));
|
|
2829
|
-
conflicts.push({ keyword, pages: enrichedPages });
|
|
2971
|
+
conflicts.push({ keyword: display, pages: enrichedPages });
|
|
2830
2972
|
for (const p of enrichedPages) {
|
|
2831
2973
|
const pageKey = `${p.collection}::${p.id}`;
|
|
2832
2974
|
if (!affectedPageIds.has(pageKey)) {
|
|
@@ -3600,6 +3742,420 @@ function createPerformanceHandler() {
|
|
|
3600
3742
|
};
|
|
3601
3743
|
}
|
|
3602
3744
|
|
|
3745
|
+
// src/endpoints/coreWebVitals.ts
|
|
3746
|
+
var CWV_THRESHOLDS = {
|
|
3747
|
+
lcp: { good: 2500, poor: 4e3 },
|
|
3748
|
+
// ms
|
|
3749
|
+
inp: { good: 200, poor: 500 },
|
|
3750
|
+
// ms
|
|
3751
|
+
cls: { good: 0.1, poor: 0.25 }
|
|
3752
|
+
// unitless
|
|
3753
|
+
};
|
|
3754
|
+
function rate(value, t) {
|
|
3755
|
+
if (value === null || Number.isNaN(value)) return "unknown";
|
|
3756
|
+
if (value <= t.good) return "good";
|
|
3757
|
+
if (value <= t.poor) return "needs-improvement";
|
|
3758
|
+
return "poor";
|
|
3759
|
+
}
|
|
3760
|
+
function resolveSiteUrl(seoConfig) {
|
|
3761
|
+
return (seoConfig?.siteUrl || process.env.NEXT_PUBLIC_SERVER_URL || process.env.PAYLOAD_PUBLIC_SERVER_URL || void 0)?.replace(/\/$/, "");
|
|
3762
|
+
}
|
|
3763
|
+
function createCoreWebVitalsHandler(seoConfig) {
|
|
3764
|
+
return async (req) => {
|
|
3765
|
+
try {
|
|
3766
|
+
if (!req.user) {
|
|
3767
|
+
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
3768
|
+
}
|
|
3769
|
+
const reqUrl = new URL(req.url);
|
|
3770
|
+
const target = reqUrl.searchParams.get("url");
|
|
3771
|
+
const strategy = reqUrl.searchParams.get("strategy") === "desktop" ? "desktop" : "mobile";
|
|
3772
|
+
if (!target) {
|
|
3773
|
+
return Response.json({ error: "Missing required query param: url" }, { status: 400 });
|
|
3774
|
+
}
|
|
3775
|
+
const siteUrl = resolveSiteUrl(seoConfig);
|
|
3776
|
+
if (!siteUrl) {
|
|
3777
|
+
return Response.json(
|
|
3778
|
+
{ error: "siteUrl is not configured \u2014 set it in the plugin config or NEXT_PUBLIC_SERVER_URL." },
|
|
3779
|
+
{ status: 400 }
|
|
3780
|
+
);
|
|
3781
|
+
}
|
|
3782
|
+
let targetOrigin;
|
|
3783
|
+
let siteOrigin;
|
|
3784
|
+
try {
|
|
3785
|
+
targetOrigin = new URL(target).origin;
|
|
3786
|
+
siteOrigin = new URL(siteUrl).origin;
|
|
3787
|
+
} catch {
|
|
3788
|
+
return Response.json({ error: "Invalid url." }, { status: 400 });
|
|
3789
|
+
}
|
|
3790
|
+
if (targetOrigin !== siteOrigin) {
|
|
3791
|
+
return Response.json(
|
|
3792
|
+
{ error: "Only the configured site origin can be tested." },
|
|
3793
|
+
{ status: 403 }
|
|
3794
|
+
);
|
|
3795
|
+
}
|
|
3796
|
+
const apiKey = process.env.PAGESPEED_API_KEY || process.env.GOOGLE_PAGESPEED_API_KEY || "";
|
|
3797
|
+
const psi = new URL("https://www.googleapis.com/pagespeedonline/v5/runPagespeed");
|
|
3798
|
+
psi.searchParams.set("url", target);
|
|
3799
|
+
psi.searchParams.set("category", "performance");
|
|
3800
|
+
psi.searchParams.set("strategy", strategy);
|
|
3801
|
+
if (apiKey) psi.searchParams.set("key", apiKey);
|
|
3802
|
+
const controller = new AbortController();
|
|
3803
|
+
const timeout = setTimeout(() => controller.abort(), 3e4);
|
|
3804
|
+
let psiData;
|
|
3805
|
+
try {
|
|
3806
|
+
const resp = await fetch(psi.toString(), { signal: controller.signal });
|
|
3807
|
+
if (!resp.ok) {
|
|
3808
|
+
const detail = resp.status === 429 ? " (PSI quota exceeded \u2014 add a PAGESPEED_API_KEY)" : "";
|
|
3809
|
+
return Response.json(
|
|
3810
|
+
{ error: `PageSpeed Insights request failed: ${resp.status}${detail}` },
|
|
3811
|
+
{ status: 502 }
|
|
3812
|
+
);
|
|
3813
|
+
}
|
|
3814
|
+
psiData = await resp.json();
|
|
3815
|
+
} finally {
|
|
3816
|
+
clearTimeout(timeout);
|
|
3817
|
+
}
|
|
3818
|
+
const loadingExperience = psiData.loadingExperience || {};
|
|
3819
|
+
const metrics = loadingExperience.metrics || {};
|
|
3820
|
+
const fieldMetric = (key) => {
|
|
3821
|
+
const m = metrics[key];
|
|
3822
|
+
const p = m?.percentile;
|
|
3823
|
+
return typeof p === "number" ? p : null;
|
|
3824
|
+
};
|
|
3825
|
+
const fieldLcp = fieldMetric("LARGEST_CONTENTFUL_PAINT_MS");
|
|
3826
|
+
const fieldInp = fieldMetric("INTERACTION_TO_NEXT_PAINT");
|
|
3827
|
+
const fieldClsRaw = fieldMetric("CUMULATIVE_LAYOUT_SHIFT_SCORE");
|
|
3828
|
+
const fieldCls = fieldClsRaw !== null ? fieldClsRaw / 100 : null;
|
|
3829
|
+
const hasFieldData = fieldLcp !== null || fieldInp !== null || fieldCls !== null;
|
|
3830
|
+
const lighthouse = psiData.lighthouseResult || {};
|
|
3831
|
+
const audits = lighthouse.audits || {};
|
|
3832
|
+
const labNumeric = (id) => {
|
|
3833
|
+
const v = audits[id]?.numericValue;
|
|
3834
|
+
return typeof v === "number" ? v : null;
|
|
3835
|
+
};
|
|
3836
|
+
const labLcp = labNumeric("largest-contentful-paint");
|
|
3837
|
+
const labCls = labNumeric("cumulative-layout-shift");
|
|
3838
|
+
const labTbt = labNumeric("total-blocking-time");
|
|
3839
|
+
const lcp = fieldLcp ?? labLcp;
|
|
3840
|
+
const inp = fieldInp;
|
|
3841
|
+
const cls = fieldCls ?? labCls;
|
|
3842
|
+
return Response.json(
|
|
3843
|
+
{
|
|
3844
|
+
url: target,
|
|
3845
|
+
strategy,
|
|
3846
|
+
source: hasFieldData ? "field" : "lab",
|
|
3847
|
+
hasFieldData,
|
|
3848
|
+
metrics: {
|
|
3849
|
+
lcp: { value: lcp, unit: "ms", rating: rate(lcp, CWV_THRESHOLDS.lcp) },
|
|
3850
|
+
inp: {
|
|
3851
|
+
value: inp,
|
|
3852
|
+
unit: "ms",
|
|
3853
|
+
rating: rate(inp, CWV_THRESHOLDS.inp),
|
|
3854
|
+
note: inp === null ? "INP needs real-user (field) data; not available in lab." : void 0
|
|
3855
|
+
},
|
|
3856
|
+
cls: { value: cls, unit: "score", rating: rate(cls, CWV_THRESHOLDS.cls) },
|
|
3857
|
+
tbt: { value: labTbt, unit: "ms", source: "lab" }
|
|
3858
|
+
},
|
|
3859
|
+
thresholds: CWV_THRESHOLDS,
|
|
3860
|
+
keyConfigured: !!apiKey,
|
|
3861
|
+
note: "Informational only \u2014 Core Web Vitals are a ranking tie-breaker, not part of the on-page SEO score."
|
|
3862
|
+
},
|
|
3863
|
+
{ headers: { "Cache-Control": "no-store" } }
|
|
3864
|
+
);
|
|
3865
|
+
} catch (error) {
|
|
3866
|
+
const message = error instanceof Error ? error.message : "Internal server error";
|
|
3867
|
+
req.payload.logger.error(`[seo] core-web-vitals error: ${message}`);
|
|
3868
|
+
return Response.json({ error: message }, { status: 500 });
|
|
3869
|
+
}
|
|
3870
|
+
};
|
|
3871
|
+
}
|
|
3872
|
+
var ALGO = "aes-256-gcm";
|
|
3873
|
+
var KEY_NAMESPACE = "seo-analyzer:gsc:v1";
|
|
3874
|
+
var FORMAT_VERSION = "v1";
|
|
3875
|
+
function deriveKey(secret) {
|
|
3876
|
+
const explicit = process.env.SEO_GSC_ENCRYPTION_KEY;
|
|
3877
|
+
if (explicit) {
|
|
3878
|
+
const buf = explicit.length === 64 ? Buffer.from(explicit, "hex") : Buffer.from(explicit, "base64");
|
|
3879
|
+
if (buf.length === 32) return buf;
|
|
3880
|
+
throw new Error("SEO_GSC_ENCRYPTION_KEY must decode to exactly 32 bytes (hex64 or base64).");
|
|
3881
|
+
}
|
|
3882
|
+
if (!secret) {
|
|
3883
|
+
throw new Error("No encryption secret available (set SEO_GSC_ENCRYPTION_KEY or Payload secret).");
|
|
3884
|
+
}
|
|
3885
|
+
return crypto.scryptSync(secret, KEY_NAMESPACE, 32);
|
|
3886
|
+
}
|
|
3887
|
+
function encryptToken(plaintext, secret) {
|
|
3888
|
+
const key = deriveKey(secret);
|
|
3889
|
+
const iv = crypto.randomBytes(12);
|
|
3890
|
+
const cipher = crypto.createCipheriv(ALGO, key, iv);
|
|
3891
|
+
const enc = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
3892
|
+
const tag = cipher.getAuthTag();
|
|
3893
|
+
return [FORMAT_VERSION, iv.toString("base64"), tag.toString("base64"), enc.toString("base64")].join(":");
|
|
3894
|
+
}
|
|
3895
|
+
function decryptToken(payload, secret) {
|
|
3896
|
+
const parts = payload.split(":");
|
|
3897
|
+
if (parts.length !== 4 || parts[0] !== FORMAT_VERSION) {
|
|
3898
|
+
throw new Error("Invalid encrypted token format.");
|
|
3899
|
+
}
|
|
3900
|
+
const key = deriveKey(secret);
|
|
3901
|
+
const iv = Buffer.from(parts[1], "base64");
|
|
3902
|
+
const tag = Buffer.from(parts[2], "base64");
|
|
3903
|
+
const enc = Buffer.from(parts[3], "base64");
|
|
3904
|
+
const decipher = crypto.createDecipheriv(ALGO, key, iv);
|
|
3905
|
+
decipher.setAuthTag(tag);
|
|
3906
|
+
const dec = Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
3907
|
+
return dec.toString("utf8");
|
|
3908
|
+
}
|
|
3909
|
+
function safeEqual(a, b) {
|
|
3910
|
+
const ba = Buffer.from(a);
|
|
3911
|
+
const bb = Buffer.from(b);
|
|
3912
|
+
if (ba.length !== bb.length) return false;
|
|
3913
|
+
return crypto.timingSafeEqual(ba, bb);
|
|
3914
|
+
}
|
|
3915
|
+
|
|
3916
|
+
// src/endpoints/gscOAuth.ts
|
|
3917
|
+
var AUTH_COLLECTION = "seo-gsc-auth";
|
|
3918
|
+
var SCOPES = "https://www.googleapis.com/auth/webmasters.readonly openid email";
|
|
3919
|
+
function isAdmin5(user) {
|
|
3920
|
+
if (!user) return false;
|
|
3921
|
+
if (user.role === "admin") return true;
|
|
3922
|
+
if (Array.isArray(user.roles) && user.roles.includes("admin")) return true;
|
|
3923
|
+
return false;
|
|
3924
|
+
}
|
|
3925
|
+
function resolveSiteUrl2(seoConfig) {
|
|
3926
|
+
return (seoConfig?.siteUrl || process.env.NEXT_PUBLIC_SERVER_URL || process.env.PAYLOAD_PUBLIC_SERVER_URL || void 0)?.replace(/\/$/, "");
|
|
3927
|
+
}
|
|
3928
|
+
function getOAuthConfig(basePath, seoConfig) {
|
|
3929
|
+
const clientId = process.env.GSC_OAUTH_CLIENT_ID || "";
|
|
3930
|
+
const clientSecret = process.env.GSC_OAUTH_CLIENT_SECRET || "";
|
|
3931
|
+
const siteUrl = resolveSiteUrl2(seoConfig);
|
|
3932
|
+
if (!clientId || !clientSecret || !siteUrl) return null;
|
|
3933
|
+
return { clientId, clientSecret, siteUrl, redirectUri: `${siteUrl}/api${basePath}/gsc/callback` };
|
|
3934
|
+
}
|
|
3935
|
+
async function getOrCreateAuthDoc(payload) {
|
|
3936
|
+
const found = await payload.find({ collection: AUTH_COLLECTION, limit: 1, overrideAccess: true });
|
|
3937
|
+
if (found.docs.length > 0) return found.docs[0];
|
|
3938
|
+
return payload.create({ collection: AUTH_COLLECTION, data: {}, overrideAccess: true });
|
|
3939
|
+
}
|
|
3940
|
+
async function tokenRequest(cfg, body) {
|
|
3941
|
+
const resp = await fetch("https://oauth2.googleapis.com/token", {
|
|
3942
|
+
method: "POST",
|
|
3943
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
3944
|
+
body: new URLSearchParams({
|
|
3945
|
+
client_id: cfg.clientId,
|
|
3946
|
+
client_secret: cfg.clientSecret,
|
|
3947
|
+
...body
|
|
3948
|
+
}).toString()
|
|
3949
|
+
});
|
|
3950
|
+
const json = await resp.json();
|
|
3951
|
+
if (!resp.ok) {
|
|
3952
|
+
throw new Error(`Token endpoint error: ${resp.status} ${json.error || ""}`);
|
|
3953
|
+
}
|
|
3954
|
+
return json;
|
|
3955
|
+
}
|
|
3956
|
+
function createGscStatusHandler(basePath, seoConfig) {
|
|
3957
|
+
return async (req) => {
|
|
3958
|
+
try {
|
|
3959
|
+
if (!req.user) return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
3960
|
+
const cfg = getOAuthConfig(basePath, seoConfig);
|
|
3961
|
+
const doc = await getOrCreateAuthDoc(req.payload);
|
|
3962
|
+
return Response.json(
|
|
3963
|
+
{
|
|
3964
|
+
configured: !!cfg,
|
|
3965
|
+
connected: !!doc.refreshTokenEnc,
|
|
3966
|
+
connectedEmail: doc.connectedEmail || null,
|
|
3967
|
+
connectedAt: doc.connectedAt || null,
|
|
3968
|
+
propertyUrl: doc.propertyUrl || cfg?.siteUrl || null,
|
|
3969
|
+
redirectUri: cfg?.redirectUri || null
|
|
3970
|
+
},
|
|
3971
|
+
{ headers: { "Cache-Control": "no-store" } }
|
|
3972
|
+
);
|
|
3973
|
+
} catch (error) {
|
|
3974
|
+
const message = error instanceof Error ? error.message : "Internal server error";
|
|
3975
|
+
req.payload.logger.error(`[seo] gsc-status error: ${message}`);
|
|
3976
|
+
return Response.json({ error: message }, { status: 500 });
|
|
3977
|
+
}
|
|
3978
|
+
};
|
|
3979
|
+
}
|
|
3980
|
+
function createGscAuthStartHandler(basePath, seoConfig) {
|
|
3981
|
+
return async (req) => {
|
|
3982
|
+
try {
|
|
3983
|
+
if (!isAdmin5(req.user)) return Response.json({ error: "Forbidden" }, { status: 403 });
|
|
3984
|
+
const cfg = getOAuthConfig(basePath, seoConfig);
|
|
3985
|
+
if (!cfg) {
|
|
3986
|
+
return Response.json(
|
|
3987
|
+
{ error: "GSC OAuth not configured. Set GSC_OAUTH_CLIENT_ID, GSC_OAUTH_CLIENT_SECRET and siteUrl." },
|
|
3988
|
+
{ status: 400 }
|
|
3989
|
+
);
|
|
3990
|
+
}
|
|
3991
|
+
const state = crypto.randomBytes(24).toString("hex");
|
|
3992
|
+
const doc = await getOrCreateAuthDoc(req.payload);
|
|
3993
|
+
await req.payload.update({
|
|
3994
|
+
collection: AUTH_COLLECTION,
|
|
3995
|
+
id: doc.id,
|
|
3996
|
+
data: { pendingState: state },
|
|
3997
|
+
overrideAccess: true
|
|
3998
|
+
});
|
|
3999
|
+
const authUrl = new URL("https://accounts.google.com/o/oauth2/v2/auth");
|
|
4000
|
+
authUrl.searchParams.set("client_id", cfg.clientId);
|
|
4001
|
+
authUrl.searchParams.set("redirect_uri", cfg.redirectUri);
|
|
4002
|
+
authUrl.searchParams.set("response_type", "code");
|
|
4003
|
+
authUrl.searchParams.set("scope", SCOPES);
|
|
4004
|
+
authUrl.searchParams.set("access_type", "offline");
|
|
4005
|
+
authUrl.searchParams.set("prompt", "consent");
|
|
4006
|
+
authUrl.searchParams.set("state", state);
|
|
4007
|
+
return Response.json({ authUrl: authUrl.toString() }, { headers: { "Cache-Control": "no-store" } });
|
|
4008
|
+
} catch (error) {
|
|
4009
|
+
const message = error instanceof Error ? error.message : "Internal server error";
|
|
4010
|
+
req.payload.logger.error(`[seo] gsc-auth error: ${message}`);
|
|
4011
|
+
return Response.json({ error: message }, { status: 500 });
|
|
4012
|
+
}
|
|
4013
|
+
};
|
|
4014
|
+
}
|
|
4015
|
+
function createGscCallbackHandler(basePath, seoConfig) {
|
|
4016
|
+
return async (req) => {
|
|
4017
|
+
const htmlPage = (title, body) => new Response(
|
|
4018
|
+
`<!doctype html><html><head><meta charset="utf-8"><title>${title}</title></head><body style="font-family:system-ui;padding:2rem;max-width:40rem;margin:auto"><h1>${title}</h1><p>${body}</p><p><a href="/admin/performance">\u2190 Back to the SEO dashboard</a></p></body></html>`,
|
|
4019
|
+
{ status: 200, headers: { "content-type": "text/html; charset=utf-8" } }
|
|
4020
|
+
);
|
|
4021
|
+
try {
|
|
4022
|
+
if (!isAdmin5(req.user)) {
|
|
4023
|
+
return htmlPage("Connection failed", "You must be signed in as an admin to connect Google Search Console.");
|
|
4024
|
+
}
|
|
4025
|
+
const cfg = getOAuthConfig(basePath, seoConfig);
|
|
4026
|
+
if (!cfg) return htmlPage("Connection failed", "GSC OAuth is not configured on the server.");
|
|
4027
|
+
const url = new URL(req.url);
|
|
4028
|
+
const code = url.searchParams.get("code");
|
|
4029
|
+
const state = url.searchParams.get("state");
|
|
4030
|
+
const oauthError = url.searchParams.get("error");
|
|
4031
|
+
if (oauthError) return htmlPage("Connection cancelled", `Google returned: ${oauthError}`);
|
|
4032
|
+
if (!code || !state) return htmlPage("Connection failed", "Missing code or state.");
|
|
4033
|
+
const doc = await getOrCreateAuthDoc(req.payload);
|
|
4034
|
+
if (!doc.pendingState || !safeEqual(state, doc.pendingState)) {
|
|
4035
|
+
return htmlPage("Connection failed", "Invalid state (possible CSRF). Please restart the connection.");
|
|
4036
|
+
}
|
|
4037
|
+
const tokens = await tokenRequest(cfg, {
|
|
4038
|
+
code,
|
|
4039
|
+
redirect_uri: cfg.redirectUri,
|
|
4040
|
+
grant_type: "authorization_code"
|
|
4041
|
+
});
|
|
4042
|
+
const refreshToken = tokens.refresh_token;
|
|
4043
|
+
const accessToken = tokens.access_token;
|
|
4044
|
+
if (!refreshToken) {
|
|
4045
|
+
return htmlPage(
|
|
4046
|
+
"Connection failed",
|
|
4047
|
+
"Google did not return a refresh token. Revoke the app access in your Google account and try again (the consent screen must show)."
|
|
4048
|
+
);
|
|
4049
|
+
}
|
|
4050
|
+
let email = null;
|
|
4051
|
+
if (accessToken) {
|
|
4052
|
+
try {
|
|
4053
|
+
const ui = await fetch("https://www.googleapis.com/oauth2/v2/userinfo", {
|
|
4054
|
+
headers: { authorization: `Bearer ${accessToken}` }
|
|
4055
|
+
});
|
|
4056
|
+
if (ui.ok) email = (await ui.json()).email;
|
|
4057
|
+
} catch {
|
|
4058
|
+
}
|
|
4059
|
+
}
|
|
4060
|
+
const secret = req.payload.secret || "";
|
|
4061
|
+
const refreshTokenEnc = encryptToken(refreshToken, secret);
|
|
4062
|
+
await req.payload.update({
|
|
4063
|
+
collection: AUTH_COLLECTION,
|
|
4064
|
+
id: doc.id,
|
|
4065
|
+
data: {
|
|
4066
|
+
refreshTokenEnc,
|
|
4067
|
+
pendingState: null,
|
|
4068
|
+
connectedEmail: email,
|
|
4069
|
+
connectedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4070
|
+
scope: tokens.scope || SCOPES,
|
|
4071
|
+
propertyUrl: doc.propertyUrl || cfg.siteUrl
|
|
4072
|
+
},
|
|
4073
|
+
overrideAccess: true
|
|
4074
|
+
});
|
|
4075
|
+
return htmlPage("Google Search Console connected \u2705", "You can close this tab and return to the SEO dashboard.");
|
|
4076
|
+
} catch (error) {
|
|
4077
|
+
const message = error instanceof Error ? error.message : "Internal server error";
|
|
4078
|
+
req.payload.logger.error(`[seo] gsc-callback error: ${message}`);
|
|
4079
|
+
return htmlPage("Connection failed", "An unexpected error occurred. Check the server logs.");
|
|
4080
|
+
}
|
|
4081
|
+
};
|
|
4082
|
+
}
|
|
4083
|
+
function createGscDataHandler(basePath, seoConfig) {
|
|
4084
|
+
return async (req) => {
|
|
4085
|
+
try {
|
|
4086
|
+
if (!isAdmin5(req.user)) return Response.json({ error: "Forbidden" }, { status: 403 });
|
|
4087
|
+
const cfg = getOAuthConfig(basePath, seoConfig);
|
|
4088
|
+
if (!cfg) return Response.json({ error: "GSC OAuth not configured." }, { status: 400 });
|
|
4089
|
+
const doc = await getOrCreateAuthDoc(req.payload);
|
|
4090
|
+
if (!doc.refreshTokenEnc) {
|
|
4091
|
+
return Response.json({ error: "Not connected to Google Search Console." }, { status: 409 });
|
|
4092
|
+
}
|
|
4093
|
+
const secret = req.payload.secret || "";
|
|
4094
|
+
let refreshToken;
|
|
4095
|
+
try {
|
|
4096
|
+
refreshToken = decryptToken(doc.refreshTokenEnc, secret);
|
|
4097
|
+
} catch {
|
|
4098
|
+
return Response.json(
|
|
4099
|
+
{ error: "Stored token could not be decrypted (encryption key changed?). Reconnect GSC." },
|
|
4100
|
+
{ status: 409 }
|
|
4101
|
+
);
|
|
4102
|
+
}
|
|
4103
|
+
const tokens = await tokenRequest(cfg, { refresh_token: refreshToken, grant_type: "refresh_token" });
|
|
4104
|
+
const accessToken = tokens.access_token;
|
|
4105
|
+
if (!accessToken) return Response.json({ error: "Could not refresh access token." }, { status: 502 });
|
|
4106
|
+
const url = new URL(req.url);
|
|
4107
|
+
const today = /* @__PURE__ */ new Date();
|
|
4108
|
+
const defaultEnd = today.toISOString().slice(0, 10);
|
|
4109
|
+
const defaultStart = new Date(today.getTime() - 28 * 864e5).toISOString().slice(0, 10);
|
|
4110
|
+
const startDate = url.searchParams.get("startDate") || defaultStart;
|
|
4111
|
+
const endDate = url.searchParams.get("endDate") || defaultEnd;
|
|
4112
|
+
const dimension = url.searchParams.get("dimension") === "page" ? "page" : "query";
|
|
4113
|
+
const rowLimit = Math.min(1e3, Math.max(1, parseInt(url.searchParams.get("rowLimit") || "100", 10)));
|
|
4114
|
+
const property = doc.propertyUrl || cfg.siteUrl;
|
|
4115
|
+
const gscResp = await fetch(
|
|
4116
|
+
`https://www.googleapis.com/webmasters/v3/sites/${encodeURIComponent(property)}/searchAnalytics/query`,
|
|
4117
|
+
{
|
|
4118
|
+
method: "POST",
|
|
4119
|
+
headers: { authorization: `Bearer ${accessToken}`, "content-type": "application/json" },
|
|
4120
|
+
body: JSON.stringify({ startDate, endDate, dimensions: [dimension], rowLimit })
|
|
4121
|
+
}
|
|
4122
|
+
);
|
|
4123
|
+
const gscJson = await gscResp.json();
|
|
4124
|
+
if (!gscResp.ok) {
|
|
4125
|
+
const err = gscJson.error?.message || gscResp.status;
|
|
4126
|
+
return Response.json({ error: `GSC query failed: ${err}` }, { status: 502 });
|
|
4127
|
+
}
|
|
4128
|
+
return Response.json(
|
|
4129
|
+
{ property, startDate, endDate, dimension, rows: gscJson.rows || [] },
|
|
4130
|
+
{ headers: { "Cache-Control": "no-store" } }
|
|
4131
|
+
);
|
|
4132
|
+
} catch (error) {
|
|
4133
|
+
const message = error instanceof Error ? error.message : "Internal server error";
|
|
4134
|
+
req.payload.logger.error(`[seo] gsc-data error: ${message}`);
|
|
4135
|
+
return Response.json({ error: message }, { status: 500 });
|
|
4136
|
+
}
|
|
4137
|
+
};
|
|
4138
|
+
}
|
|
4139
|
+
function createGscDisconnectHandler() {
|
|
4140
|
+
return async (req) => {
|
|
4141
|
+
try {
|
|
4142
|
+
if (!isAdmin5(req.user)) return Response.json({ error: "Forbidden" }, { status: 403 });
|
|
4143
|
+
const doc = await getOrCreateAuthDoc(req.payload);
|
|
4144
|
+
await req.payload.update({
|
|
4145
|
+
collection: AUTH_COLLECTION,
|
|
4146
|
+
id: doc.id,
|
|
4147
|
+
data: { refreshTokenEnc: null, pendingState: null, connectedEmail: null, connectedAt: null, scope: null },
|
|
4148
|
+
overrideAccess: true
|
|
4149
|
+
});
|
|
4150
|
+
return Response.json({ disconnected: true }, { headers: { "Cache-Control": "no-store" } });
|
|
4151
|
+
} catch (error) {
|
|
4152
|
+
const message = error instanceof Error ? error.message : "Internal server error";
|
|
4153
|
+
req.payload.logger.error(`[seo] gsc-disconnect error: ${message}`);
|
|
4154
|
+
return Response.json({ error: message }, { status: 500 });
|
|
4155
|
+
}
|
|
4156
|
+
};
|
|
4157
|
+
}
|
|
4158
|
+
|
|
3603
4159
|
// src/endpoints/keywordResearch.ts
|
|
3604
4160
|
var STOP_WORDS_SET = /* @__PURE__ */ new Set();
|
|
3605
4161
|
function getStopWords2() {
|
|
@@ -4136,12 +4692,12 @@ function detectSchemaType(collection, doc) {
|
|
|
4136
4692
|
if (collection === "posts") return "Article";
|
|
4137
4693
|
const layout = doc.layout;
|
|
4138
4694
|
if (layout && Array.isArray(layout)) {
|
|
4139
|
-
const
|
|
4695
|
+
const hasFaqBlock2 = layout.some((block) => {
|
|
4140
4696
|
if (!block || typeof block !== "object") return false;
|
|
4141
4697
|
const b = block;
|
|
4142
4698
|
return b.blockType === "faq" || b.blockType === "FAQ" || b.blockType === "faqBlock";
|
|
4143
4699
|
});
|
|
4144
|
-
if (
|
|
4700
|
+
if (hasFaqBlock2) return "FAQPage";
|
|
4145
4701
|
}
|
|
4146
4702
|
if (doc.price !== void 0 || doc.sku !== void 0 || collection === "products") {
|
|
4147
4703
|
return "Product";
|
|
@@ -4292,6 +4848,75 @@ function buildOrganizationSchema(doc, siteUrl) {
|
|
|
4292
4848
|
if (doc.logo) {
|
|
4293
4849
|
schema.logo = typeof doc.logo === "string" ? doc.logo : doc.logo?.url;
|
|
4294
4850
|
}
|
|
4851
|
+
if (Array.isArray(doc.sameAs)) {
|
|
4852
|
+
const sameAs = doc.sameAs.filter((s) => typeof s === "string");
|
|
4853
|
+
if (sameAs.length > 0) schema.sameAs = sameAs;
|
|
4854
|
+
}
|
|
4855
|
+
return schema;
|
|
4856
|
+
}
|
|
4857
|
+
function buildPersonSchema(doc, siteUrl) {
|
|
4858
|
+
const meta = doc.meta || {};
|
|
4859
|
+
const schema = {
|
|
4860
|
+
"@context": "https://schema.org",
|
|
4861
|
+
"@type": "Person",
|
|
4862
|
+
name: doc.name || doc.title || meta.title || ""
|
|
4863
|
+
};
|
|
4864
|
+
if (doc.jobTitle) schema.jobTitle = doc.jobTitle;
|
|
4865
|
+
if (doc.description || meta.description) schema.description = doc.description || meta.description;
|
|
4866
|
+
schema.url = typeof doc.url === "string" && doc.url || `${siteUrl}/${doc.slug || ""}`;
|
|
4867
|
+
if (Array.isArray(doc.sameAs)) {
|
|
4868
|
+
const sameAs = doc.sameAs.filter((s) => typeof s === "string");
|
|
4869
|
+
if (sameAs.length > 0) schema.sameAs = sameAs;
|
|
4870
|
+
}
|
|
4871
|
+
return schema;
|
|
4872
|
+
}
|
|
4873
|
+
function buildEventSchema(doc, siteUrl) {
|
|
4874
|
+
const meta = doc.meta || {};
|
|
4875
|
+
const schema = {
|
|
4876
|
+
"@context": "https://schema.org",
|
|
4877
|
+
"@type": "Event",
|
|
4878
|
+
name: doc.title || meta.title || "",
|
|
4879
|
+
description: meta.description || "",
|
|
4880
|
+
startDate: doc.startDate || doc.eventStart || void 0,
|
|
4881
|
+
endDate: doc.endDate || doc.eventEnd || void 0,
|
|
4882
|
+
url: `${siteUrl}/${doc.slug || ""}`
|
|
4883
|
+
};
|
|
4884
|
+
if (doc.location) {
|
|
4885
|
+
schema.location = typeof doc.location === "string" ? { "@type": "Place", name: doc.location } : { "@type": "Place", ...doc.location };
|
|
4886
|
+
}
|
|
4887
|
+
return schema;
|
|
4888
|
+
}
|
|
4889
|
+
function buildRecipeSchema(doc, siteUrl) {
|
|
4890
|
+
const meta = doc.meta || {};
|
|
4891
|
+
const heroMedia = doc.hero?.media;
|
|
4892
|
+
const imageUrl = getImageUrl(meta.image, heroMedia, siteUrl);
|
|
4893
|
+
const schema = {
|
|
4894
|
+
"@context": "https://schema.org",
|
|
4895
|
+
"@type": "Recipe",
|
|
4896
|
+
name: doc.title || meta.title || "",
|
|
4897
|
+
description: meta.description || ""
|
|
4898
|
+
};
|
|
4899
|
+
if (imageUrl) schema.image = imageUrl;
|
|
4900
|
+
if (Array.isArray(doc.recipeIngredient)) schema.recipeIngredient = doc.recipeIngredient;
|
|
4901
|
+
else if (Array.isArray(doc.ingredients)) schema.recipeIngredient = doc.ingredients;
|
|
4902
|
+
if (doc.recipeInstructions) schema.recipeInstructions = doc.recipeInstructions;
|
|
4903
|
+
else if (doc.instructions) schema.recipeInstructions = doc.instructions;
|
|
4904
|
+
return schema;
|
|
4905
|
+
}
|
|
4906
|
+
function buildVideoSchema(doc, siteUrl) {
|
|
4907
|
+
const meta = doc.meta || {};
|
|
4908
|
+
const heroMedia = doc.hero?.media;
|
|
4909
|
+
const imageUrl = getImageUrl(meta.image, heroMedia, siteUrl);
|
|
4910
|
+
const schema = {
|
|
4911
|
+
"@context": "https://schema.org",
|
|
4912
|
+
"@type": "VideoObject",
|
|
4913
|
+
name: doc.title || meta.title || "",
|
|
4914
|
+
description: meta.description || "",
|
|
4915
|
+
uploadDate: doc.uploadDate || doc.createdAt || void 0
|
|
4916
|
+
};
|
|
4917
|
+
if (imageUrl) schema.thumbnailUrl = imageUrl;
|
|
4918
|
+
if (doc.videoUrl || doc.contentUrl) schema.contentUrl = doc.videoUrl || doc.contentUrl;
|
|
4919
|
+
if (doc.duration) schema.duration = doc.duration;
|
|
4295
4920
|
return schema;
|
|
4296
4921
|
}
|
|
4297
4922
|
function getImageUrl(metaImage, heroMedia, siteUrl) {
|
|
@@ -4330,7 +4955,7 @@ function createSchemaGeneratorHandler(targetCollections) {
|
|
|
4330
4955
|
{ status: 400 }
|
|
4331
4956
|
);
|
|
4332
4957
|
}
|
|
4333
|
-
const validTypes = ["Article", "LocalBusiness", "BreadcrumbList", "FAQPage", "Product", "Organization"];
|
|
4958
|
+
const validTypes = ["Article", "LocalBusiness", "BreadcrumbList", "FAQPage", "Product", "Organization", "Person", "Event", "Recipe", "Video"];
|
|
4334
4959
|
if (typeOverrideRaw !== null && !validTypes.includes(typeOverrideRaw)) {
|
|
4335
4960
|
return Response.json(
|
|
4336
4961
|
{ error: `Invalid schema type. Valid types: ${validTypes.join(", ")}` },
|
|
@@ -4375,6 +5000,18 @@ function createSchemaGeneratorHandler(targetCollections) {
|
|
|
4375
5000
|
case "Organization":
|
|
4376
5001
|
jsonLd = buildOrganizationSchema(doc, siteUrl);
|
|
4377
5002
|
break;
|
|
5003
|
+
case "Person":
|
|
5004
|
+
jsonLd = buildPersonSchema(doc, siteUrl);
|
|
5005
|
+
break;
|
|
5006
|
+
case "Event":
|
|
5007
|
+
jsonLd = buildEventSchema(doc, siteUrl);
|
|
5008
|
+
break;
|
|
5009
|
+
case "Recipe":
|
|
5010
|
+
jsonLd = buildRecipeSchema(doc, siteUrl);
|
|
5011
|
+
break;
|
|
5012
|
+
case "Video":
|
|
5013
|
+
jsonLd = buildVideoSchema(doc, siteUrl);
|
|
5014
|
+
break;
|
|
4378
5015
|
}
|
|
4379
5016
|
const cleaned = JSON.parse(JSON.stringify(jsonLd));
|
|
4380
5017
|
return Response.json({
|
|
@@ -4696,7 +5333,7 @@ function createAiRewriteHandler(targetCollections) {
|
|
|
4696
5333
|
}
|
|
4697
5334
|
|
|
4698
5335
|
// src/endpoints/robots.ts
|
|
4699
|
-
function
|
|
5336
|
+
function isAdmin6(user) {
|
|
4700
5337
|
if (!user) return false;
|
|
4701
5338
|
if (user.role === "admin") return true;
|
|
4702
5339
|
if (Array.isArray(user.roles) && user.roles.includes("admin")) return true;
|
|
@@ -4745,7 +5382,7 @@ function createRobotsUpdateHandler() {
|
|
|
4745
5382
|
if (!req.user) {
|
|
4746
5383
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
4747
5384
|
}
|
|
4748
|
-
if (!
|
|
5385
|
+
if (!isAdmin6(req.user)) {
|
|
4749
5386
|
return Response.json({ error: "Admin access required" }, { status: 403 });
|
|
4750
5387
|
}
|
|
4751
5388
|
const body = await parseJsonBody(req);
|
|
@@ -5481,6 +6118,55 @@ function createSeoLogsCollection() {
|
|
|
5481
6118
|
};
|
|
5482
6119
|
}
|
|
5483
6120
|
|
|
6121
|
+
// src/collections/SeoGscAuth.ts
|
|
6122
|
+
function createSeoGscAuthCollection() {
|
|
6123
|
+
return {
|
|
6124
|
+
slug: "seo-gsc-auth",
|
|
6125
|
+
admin: {
|
|
6126
|
+
hidden: true,
|
|
6127
|
+
custom: { navHidden: true }
|
|
6128
|
+
},
|
|
6129
|
+
access: {
|
|
6130
|
+
read: ({ req }) => !!req.user,
|
|
6131
|
+
update: ({ req }) => !!req.user,
|
|
6132
|
+
create: ({ req }) => !!req.user,
|
|
6133
|
+
delete: ({ req }) => !!req.user
|
|
6134
|
+
},
|
|
6135
|
+
fields: [
|
|
6136
|
+
{
|
|
6137
|
+
name: "refreshTokenEnc",
|
|
6138
|
+
type: "text",
|
|
6139
|
+
// The encrypted refresh-token blob must never leave the server.
|
|
6140
|
+
access: {
|
|
6141
|
+
read: () => false,
|
|
6142
|
+
create: () => false,
|
|
6143
|
+
update: () => false
|
|
6144
|
+
},
|
|
6145
|
+
admin: { hidden: true }
|
|
6146
|
+
},
|
|
6147
|
+
{
|
|
6148
|
+
name: "pendingState",
|
|
6149
|
+
type: "text",
|
|
6150
|
+
// CSRF state for the in-flight OAuth handshake — also server-only.
|
|
6151
|
+
access: {
|
|
6152
|
+
read: () => false,
|
|
6153
|
+
create: () => false,
|
|
6154
|
+
update: () => false
|
|
6155
|
+
},
|
|
6156
|
+
admin: { hidden: true }
|
|
6157
|
+
},
|
|
6158
|
+
{ name: "connectedEmail", type: "text", admin: { readOnly: true } },
|
|
6159
|
+
{ name: "connectedAt", type: "date", admin: { readOnly: true } },
|
|
6160
|
+
{
|
|
6161
|
+
name: "propertyUrl",
|
|
6162
|
+
type: "text",
|
|
6163
|
+
admin: { description: "GSC property (e.g. sc-domain:example.com or https://example.com/)" }
|
|
6164
|
+
},
|
|
6165
|
+
{ name: "scope", type: "text", admin: { readOnly: true } }
|
|
6166
|
+
]
|
|
6167
|
+
};
|
|
6168
|
+
}
|
|
6169
|
+
|
|
5484
6170
|
// src/rateLimiter.ts
|
|
5485
6171
|
function createRateLimiter(maxRequests, windowMs) {
|
|
5486
6172
|
const store = /* @__PURE__ */ new Map();
|
|
@@ -5528,7 +6214,7 @@ function getClientIp(req) {
|
|
|
5528
6214
|
|
|
5529
6215
|
// src/endpoints/seoLogs.ts
|
|
5530
6216
|
var VALID_LOG_TYPES = ["404", "redirect", "error"];
|
|
5531
|
-
function
|
|
6217
|
+
function isAdmin7(user) {
|
|
5532
6218
|
if (!user) return false;
|
|
5533
6219
|
if (user.role === "admin") return true;
|
|
5534
6220
|
if (Array.isArray(user.roles) && user.roles.includes("admin")) return true;
|
|
@@ -5625,7 +6311,7 @@ function createSeoLogsHandler(seoLogsSecret) {
|
|
|
5625
6311
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
5626
6312
|
}
|
|
5627
6313
|
if (method === "DELETE") {
|
|
5628
|
-
if (!
|
|
6314
|
+
if (!isAdmin7(req.user)) {
|
|
5629
6315
|
return Response.json({ error: "Admin access required" }, { status: 403 });
|
|
5630
6316
|
}
|
|
5631
6317
|
try {
|
|
@@ -7209,6 +7895,9 @@ var fr = {
|
|
|
7209
7895
|
groupTechnical: "Technique",
|
|
7210
7896
|
groupAccessibility: "Accessibilit\xE9",
|
|
7211
7897
|
groupEcommerce: "E-commerce",
|
|
7898
|
+
groupEeat: "E-E-A-T",
|
|
7899
|
+
groupGeo: "GEO (IA)",
|
|
7900
|
+
groupHreflang: "Hreflang",
|
|
7212
7901
|
levelExcellent: "Excellent",
|
|
7213
7902
|
levelGood: "Bon",
|
|
7214
7903
|
levelFair: "Acceptable",
|
|
@@ -7217,6 +7906,8 @@ var fr = {
|
|
|
7217
7906
|
categoryImportant: "Important",
|
|
7218
7907
|
categoryBonus: "Bonus",
|
|
7219
7908
|
seoScore: "Score SEO",
|
|
7909
|
+
aiReadiness: "IA",
|
|
7910
|
+
aiReadinessTooltip: "Pr\xEAt pour l'IA \u2014 qualit\xE9 de structuration pour \xEAtre cit\xE9 par les moteurs g\xE9n\xE9ratifs (AI Overviews, ChatGPT, Perplexity). Distinct du score SEO.",
|
|
7220
7911
|
outOf100: "/ 100",
|
|
7221
7912
|
cornerstoneLabel: "PILIER",
|
|
7222
7913
|
checksPassed: "crit\xE8res valid\xE9s",
|
|
@@ -7782,6 +8473,9 @@ var en = {
|
|
|
7782
8473
|
groupTechnical: "Technical",
|
|
7783
8474
|
groupAccessibility: "Accessibility",
|
|
7784
8475
|
groupEcommerce: "E-commerce",
|
|
8476
|
+
groupEeat: "E-E-A-T",
|
|
8477
|
+
groupGeo: "GEO (AI)",
|
|
8478
|
+
groupHreflang: "Hreflang",
|
|
7785
8479
|
levelExcellent: "Excellent",
|
|
7786
8480
|
levelGood: "Good",
|
|
7787
8481
|
levelFair: "Fair",
|
|
@@ -7790,6 +8484,8 @@ var en = {
|
|
|
7790
8484
|
categoryImportant: "Important",
|
|
7791
8485
|
categoryBonus: "Bonus",
|
|
7792
8486
|
seoScore: "SEO Score",
|
|
8487
|
+
aiReadiness: "AI",
|
|
8488
|
+
aiReadinessTooltip: "AI-readiness \u2014 how well the page is structured to be cited by generative engines (AI Overviews, ChatGPT, Perplexity). Separate from the SEO score.",
|
|
7793
8489
|
outOf100: "/ 100",
|
|
7794
8490
|
cornerstoneLabel: "CORNERSTONE",
|
|
7795
8491
|
checksPassed: "checks passed",
|
|
@@ -7959,6 +8655,8 @@ var seoAnalyzerPlugin = (pluginConfig = {}) => (incomingConfig) => {
|
|
|
7959
8655
|
aiFeatures: true,
|
|
7960
8656
|
duplicateContent: true,
|
|
7961
8657
|
settings: true,
|
|
8658
|
+
gscApi: false,
|
|
8659
|
+
// opt-in — requires Google Cloud OAuth setup + secrets
|
|
7962
8660
|
...pluginConfig.features
|
|
7963
8661
|
};
|
|
7964
8662
|
function hasExistingSeoMeta(fields) {
|
|
@@ -8099,6 +8797,7 @@ var seoAnalyzerPlugin = (pluginConfig = {}) => (incomingConfig) => {
|
|
|
8099
8797
|
if (features.redirects && !hasExistingRedirects) pluginCollections.push(createSeoRedirectsCollection(redirectsSlug));
|
|
8100
8798
|
if (features.performance) pluginCollections.push(createSeoPerformanceCollection());
|
|
8101
8799
|
if (features.seoLogs) pluginCollections.push(createSeoLogsCollection());
|
|
8800
|
+
if (features.gscApi) pluginCollections.push(createSeoGscAuthCollection());
|
|
8102
8801
|
config.collections = [
|
|
8103
8802
|
...config.collections || [],
|
|
8104
8803
|
...pluginCollections
|
|
@@ -8151,6 +8850,11 @@ var seoAnalyzerPlugin = (pluginConfig = {}) => (incomingConfig) => {
|
|
|
8151
8850
|
method: "get",
|
|
8152
8851
|
handler: withRateLimit(createAuditHandler(targetCollections, seoConfig, targetGlobals))
|
|
8153
8852
|
});
|
|
8853
|
+
pluginEndpoints.push({
|
|
8854
|
+
path: `${basePath}/indexation-audit`,
|
|
8855
|
+
method: "get",
|
|
8856
|
+
handler: withRateLimit(createIndexationAuditHandler(targetCollections, seoConfig, targetGlobals))
|
|
8857
|
+
});
|
|
8154
8858
|
}
|
|
8155
8859
|
if (features.scoreHistory) {
|
|
8156
8860
|
pluginEndpoints.push({
|
|
@@ -8225,7 +8929,18 @@ var seoAnalyzerPlugin = (pluginConfig = {}) => (incomingConfig) => {
|
|
|
8225
8929
|
if (features.performance) {
|
|
8226
8930
|
pluginEndpoints.push(
|
|
8227
8931
|
{ path: `${basePath}/performance`, method: "get", handler: createPerformanceHandler() },
|
|
8228
|
-
{ path: `${basePath}/performance`, method: "post", handler: createPerformanceHandler() }
|
|
8932
|
+
{ path: `${basePath}/performance`, method: "post", handler: createPerformanceHandler() },
|
|
8933
|
+
// Core Web Vitals via PageSpeed Insights — informational, on-demand, SSRF-safe
|
|
8934
|
+
{ path: `${basePath}/core-web-vitals`, method: "get", handler: withRateLimit(createCoreWebVitalsHandler(seoConfig)) }
|
|
8935
|
+
);
|
|
8936
|
+
}
|
|
8937
|
+
if (features.gscApi) {
|
|
8938
|
+
pluginEndpoints.push(
|
|
8939
|
+
{ path: `${basePath}/gsc/status`, method: "get", handler: createGscStatusHandler(basePath, seoConfig) },
|
|
8940
|
+
{ path: `${basePath}/gsc/auth`, method: "get", handler: createGscAuthStartHandler(basePath, seoConfig) },
|
|
8941
|
+
{ path: `${basePath}/gsc/callback`, method: "get", handler: createGscCallbackHandler(basePath, seoConfig) },
|
|
8942
|
+
{ path: `${basePath}/gsc/data`, method: "get", handler: withRateLimit(createGscDataHandler(basePath, seoConfig)) },
|
|
8943
|
+
{ path: `${basePath}/gsc/disconnect`, method: "post", handler: createGscDisconnectHandler() }
|
|
8229
8944
|
);
|
|
8230
8945
|
}
|
|
8231
8946
|
if (features.keywords) {
|
|
@@ -8399,8 +9114,11 @@ var rulesFr = {
|
|
|
8399
9114
|
powerWordsPass: (count, words) => `Le title contient ${count} mot(s) puissant(s) : ${words}`,
|
|
8400
9115
|
powerWordsFail: 'Le title ne contient aucun mot puissant \u2014 Ajoutez un mot comme "gratuit", "guide", "complet" pour booster le CTR.',
|
|
8401
9116
|
powerWordsTip: "Les mots puissants (gratuit, exclusif, guide, complet, essentiel...) attirent l'attention dans les resultats de recherche.",
|
|
9117
|
+
pixelWidthLabel: "Largeur du title (pixels)",
|
|
9118
|
+
pixelWidthPass: (px) => `Largeur estimee ${px}px \u2014 sous le seuil de troncature SERP (~600px).`,
|
|
9119
|
+
pixelWidthWarn: (px) => `Largeur estimee ${px}px \u2014 risque de troncature dans Google (~600px). Informatif.`,
|
|
8402
9120
|
hasNumberLabel: "Nombre dans le title",
|
|
8403
|
-
hasNumberPass: "Le title contient un nombre \u2014
|
|
9121
|
+
hasNumberPass: "Le title contient un nombre \u2014 format type liste, souvent plus engageant.",
|
|
8404
9122
|
hasNumberFail: 'Aucun nombre dans le title \u2014 Les titres avec chiffres (ex: "5 astuces", "Top 10") attirent plus de clics.',
|
|
8405
9123
|
hasNumberTip: 'Ajoutez un nombre pour creer un titre de type liste (ex: "7 conseils pour...", "Les 3 erreurs a eviter").',
|
|
8406
9124
|
isQuestionLabel: "Title interrogatif",
|
|
@@ -8484,12 +9202,12 @@ var rulesFr = {
|
|
|
8484
9202
|
keywordIntroFail: (kw) => `Ajoutez le mot-cle "${kw}" dans les premieres phrases du contenu.`,
|
|
8485
9203
|
densityLabel: "Densite du mot-cle",
|
|
8486
9204
|
densityOverstuffed: (density) => `Densite du mot-cle : ${density}% \u2014 Trop eleve (>3%), risque de suroptimisation (keyword stuffing).`,
|
|
8487
|
-
densityHigh: (density) => `Densite du mot-cle : ${density}% \u2014 Legerement elevee
|
|
8488
|
-
densityPass: (density) => `Densite du mot-cle : ${density}% \u2014
|
|
9205
|
+
densityHigh: (density) => `Densite du mot-cle : ${density}% \u2014 Legerement elevee, restez naturel pour eviter la sur-optimisation.`,
|
|
9206
|
+
densityPass: (density) => `Densite du mot-cle : ${density}% \u2014 Usage naturel, aucun bourrage detecte.`,
|
|
8489
9207
|
densityPassWordLevel: (density) => `Les composants du mot-cle sont presents dans le contenu (densite estimee : ${density}%).`,
|
|
8490
9208
|
densityLowWordLevel: (density) => `Les composants du mot-cle sont presents mais peu frequents (densite estimee : ${density}%). Renforcez leur presence.`,
|
|
8491
9209
|
densityLow: (density) => `Densite du mot-cle : ${density}% \u2014 Trop faible. Visez 0,5% a 2,5%.`,
|
|
8492
|
-
densityMissing: (kw) => `Le mot-cle "${kw}" n'apparait
|
|
9210
|
+
densityMissing: (kw) => `Le mot-cle "${kw}" n'apparait pas dans le corps \u2014 privilegiez une couverture naturelle du sujet plutot que la repetition.`,
|
|
8493
9211
|
placeholderLabel: "Contenu placeholder",
|
|
8494
9212
|
placeholderFail: "Du contenu placeholder a ete detecte (lorem ipsum, TODO, etc.) \u2014 Remplacez par du vrai contenu.",
|
|
8495
9213
|
placeholderPass: "Aucun contenu placeholder detecte.",
|
|
@@ -8575,7 +9293,7 @@ var rulesFr = {
|
|
|
8575
9293
|
cornerstone: {
|
|
8576
9294
|
wordcountLabel: "Longueur du contenu pilier",
|
|
8577
9295
|
wordcountPass: (count) => `${count} mots \u2014 Le contenu pilier est suffisamment complet.`,
|
|
8578
|
-
wordcountFail: (count) => `${count} mots \u2014
|
|
9296
|
+
wordcountFail: (count) => `${count} mots \u2014 Contenu pilier trop leger ; developpez la couverture du sujet (sans viser un nombre de mots arbitraire).`,
|
|
8579
9297
|
internalLinksLabel: "Maillage interne du contenu pilier",
|
|
8580
9298
|
internalLinksPass: (count) => `${count} liens internes \u2014 Bon maillage pour un contenu pilier.`,
|
|
8581
9299
|
internalLinksFail: (count) => `${count} lien(s) interne(s) \u2014 Un contenu pilier devrait avoir au moins 5 liens internes vers du contenu associe.`,
|
|
@@ -8629,12 +9347,23 @@ var rulesFr = {
|
|
|
8629
9347
|
yearRefWarn: (oldest, current, last) => `Le contenu mentionne l'annee ${oldest} sans reference a ${current} ou ${last} \u2014 Contenu potentiellement obsolete.`,
|
|
8630
9348
|
yearRefPass: (year) => `Le contenu fait reference a l'annee en cours (${year}).`,
|
|
8631
9349
|
thinAgingLabel: "Contenu leger et ancien",
|
|
8632
|
-
thinAgingFail: (words, days) => `Seulement ${words} mots et non mis a jour depuis ${days} jours \u2014 Un contenu leger ancien perd rapidement en pertinence
|
|
9350
|
+
thinAgingFail: (words, days) => `Seulement ${words} mots et non mis a jour depuis ${days} jours \u2014 Un contenu leger ancien perd rapidement en pertinence.`,
|
|
9351
|
+
fakeRefreshLabel: "Faux rafraichissement",
|
|
9352
|
+
fakeRefreshWarn: (displayedDays, updatedDays) => `La date affichee (il y a ${displayedDays} j) est plus recente que la derniere modification reelle (il y a ${updatedDays} j) \u2014 evitez de rajeunir la date sans vraie mise a jour du contenu.`,
|
|
9353
|
+
fakeRefreshTip: "Google detecte la vraie date de modification. Mettez a jour le fond du contenu, pas seulement la date affichee."
|
|
8633
9354
|
},
|
|
8634
9355
|
schema: {
|
|
8635
9356
|
readinessLabel: "Donnees structurees",
|
|
8636
9357
|
readinessPass: "La page a suffisamment de metadonnees pour generer du JSON-LD (title, description, image).",
|
|
8637
|
-
readinessFail: "Completez le title, la description et ajoutez une image pour exploiter pleinement les donnees structurees."
|
|
9358
|
+
readinessFail: "Completez le title, la description et ajoutez une image pour exploiter pleinement les donnees structurees.",
|
|
9359
|
+
coverageLabel: "Couverture des donnees structurees",
|
|
9360
|
+
coverageOptional: "Les donnees structurees sont optionnelles pour ce type de page.",
|
|
9361
|
+
coveragePass: (type) => `Donnees CMS suffisantes pour generer un schema ${type} valide.`,
|
|
9362
|
+
coverageMissing: (type, fields) => `Schema ${type} attendu pour cette page \u2014 champ(s) requis manquant(s) dans le CMS : ${fields}.`,
|
|
9363
|
+
coverageMissingTip: "Completez ces champs, ou assurez-vous que le JSON-LD correspondant est injecte au rendu (frontend).",
|
|
9364
|
+
coverageRemind: (type, fields) => `Schema ${type} : champs CMS requis presents. Verifiez aussi ces champs requis non detectables automatiquement : ${fields}.`,
|
|
9365
|
+
faqNoRichResultLabel: "FAQ / donnees structurees",
|
|
9366
|
+
faqNoRichResult: "FAQPage detecte \u2014 markup valide et toujours lu par les moteurs et l'IA, mais Google ne genere plus de rich result FAQ (2026). Conservez le markup, n'attendez pas d'extrait enrichi en SERP."
|
|
8638
9367
|
},
|
|
8639
9368
|
technical: {
|
|
8640
9369
|
canonicalMissingLabel: "URL canonique",
|
|
@@ -8643,6 +9372,8 @@ var rulesFr = {
|
|
|
8643
9372
|
canonicalInvalidMessage: (url) => `URL canonique "${url}" invalide \u2014 Utilisez une URL absolue (https://...).`,
|
|
8644
9373
|
canonicalExternalLabel: "URL canonique",
|
|
8645
9374
|
canonicalExternalMessage: "URL canonique pointe vers un domaine externe \u2014 Verifiez que c'est intentionnel.",
|
|
9375
|
+
canonicalCrossLabel: "URL canonique",
|
|
9376
|
+
canonicalCrossMessage: (target) => `URL canonique pointe vers une AUTRE page (${target}) \u2014 cette page se desindexe au profit de cette URL. Verifiez que c'est intentionnel.`,
|
|
8646
9377
|
canonicalOkLabel: "URL canonique",
|
|
8647
9378
|
canonicalOkMessage: "URL canonique correctement definie.",
|
|
8648
9379
|
robotsNoindexLabel: "Robots noindex",
|
|
@@ -8767,8 +9498,11 @@ var rulesEn = {
|
|
|
8767
9498
|
powerWordsPass: (count, words) => `The title contains ${count} power word(s): ${words}`,
|
|
8768
9499
|
powerWordsFail: 'The title contains no power words \u2014 Add a word like "free", "guide", "ultimate" to boost CTR.',
|
|
8769
9500
|
powerWordsTip: "Power words (free, exclusive, guide, ultimate, essential...) attract attention in search results.",
|
|
9501
|
+
pixelWidthLabel: "Title pixel width",
|
|
9502
|
+
pixelWidthPass: (px) => `Estimated width ${px}px \u2014 under the SERP truncation threshold (~600px).`,
|
|
9503
|
+
pixelWidthWarn: (px) => `Estimated width ${px}px \u2014 may be truncated in Google (~600px). Informational.`,
|
|
8770
9504
|
hasNumberLabel: "Number in title",
|
|
8771
|
-
hasNumberPass: "The title contains a number \u2014
|
|
9505
|
+
hasNumberPass: "The title contains a number \u2014 list-style format, often more engaging.",
|
|
8772
9506
|
hasNumberFail: 'No number in the title \u2014 Titles with numbers (e.g. "5 tips", "Top 10") attract more clicks.',
|
|
8773
9507
|
hasNumberTip: 'Add a number to create a list-type title (e.g. "7 tips for...", "The 3 mistakes to avoid").',
|
|
8774
9508
|
isQuestionLabel: "Question title",
|
|
@@ -8852,12 +9586,12 @@ var rulesEn = {
|
|
|
8852
9586
|
keywordIntroFail: (kw) => `Add the keyword "${kw}" in the first sentences of the content.`,
|
|
8853
9587
|
densityLabel: "Keyword density",
|
|
8854
9588
|
densityOverstuffed: (density) => `Keyword density: ${density}% \u2014 Too high (>3%), risk of keyword stuffing.`,
|
|
8855
|
-
densityHigh: (density) => `Keyword density: ${density}% \u2014 Slightly high
|
|
8856
|
-
densityPass: (density) => `Keyword density: ${density}% \u2014
|
|
9589
|
+
densityHigh: (density) => `Keyword density: ${density}% \u2014 Slightly high; keep it natural to avoid over-optimisation.`,
|
|
9590
|
+
densityPass: (density) => `Keyword density: ${density}% \u2014 Natural usage, no stuffing detected.`,
|
|
8857
9591
|
densityPassWordLevel: (density) => `Keyword components are present in the content (estimated density: ${density}%).`,
|
|
8858
9592
|
densityLowWordLevel: (density) => `Keyword components are present but infrequent (estimated density: ${density}%). Strengthen their presence.`,
|
|
8859
9593
|
densityLow: (density) => `Keyword density: ${density}% \u2014 Too low. Aim for 0.5% to 2.5%.`,
|
|
8860
|
-
densityMissing: (kw) => `The keyword "${kw}"
|
|
9594
|
+
densityMissing: (kw) => `The keyword "${kw}" does not appear in the body \u2014 focus on covering the topic naturally rather than repeating it.`,
|
|
8861
9595
|
placeholderLabel: "Placeholder content",
|
|
8862
9596
|
placeholderFail: "Placeholder content detected (lorem ipsum, TODO, etc.) \u2014 Replace with real content.",
|
|
8863
9597
|
placeholderPass: "No placeholder content detected.",
|
|
@@ -8943,7 +9677,7 @@ var rulesEn = {
|
|
|
8943
9677
|
cornerstone: {
|
|
8944
9678
|
wordcountLabel: "Pillar content length",
|
|
8945
9679
|
wordcountPass: (count) => `${count} words \u2014 The pillar content is comprehensive enough.`,
|
|
8946
|
-
wordcountFail: (count) => `${count} words \u2014 Pillar content
|
|
9680
|
+
wordcountFail: (count) => `${count} words \u2014 Pillar content seems thin; expand topical coverage (without targeting an arbitrary word count).`,
|
|
8947
9681
|
internalLinksLabel: "Pillar content internal linking",
|
|
8948
9682
|
internalLinksPass: (count) => `${count} internal links \u2014 Good linking for pillar content.`,
|
|
8949
9683
|
internalLinksFail: (count) => `${count} internal link(s) \u2014 Pillar content should have at least 5 internal links to related content.`,
|
|
@@ -8997,12 +9731,23 @@ var rulesEn = {
|
|
|
8997
9731
|
yearRefWarn: (oldest, current, last) => `The content mentions year ${oldest} without reference to ${current} or ${last} \u2014 Potentially outdated.`,
|
|
8998
9732
|
yearRefPass: (year) => `The content references the current year (${year}).`,
|
|
8999
9733
|
thinAgingLabel: "Thin and old content",
|
|
9000
|
-
thinAgingFail: (words, days) => `Only ${words} words and not updated for ${days} days \u2014 Thin old content loses relevance quickly
|
|
9734
|
+
thinAgingFail: (words, days) => `Only ${words} words and not updated for ${days} days \u2014 Thin old content loses relevance quickly.`,
|
|
9735
|
+
fakeRefreshLabel: "Fake refresh",
|
|
9736
|
+
fakeRefreshWarn: (displayedDays, updatedDays) => `The displayed date (${displayedDays} days ago) is newer than the last real modification (${updatedDays} days ago) \u2014 avoid bumping the date without a real content update.`,
|
|
9737
|
+
fakeRefreshTip: "Google detects the real modification date. Update the actual content, not just the displayed date."
|
|
9001
9738
|
},
|
|
9002
9739
|
schema: {
|
|
9003
9740
|
readinessLabel: "Structured data",
|
|
9004
9741
|
readinessPass: "The page has sufficient metadata to generate JSON-LD (title, description, image).",
|
|
9005
|
-
readinessFail: "Complete the title, description and add an image to fully leverage structured data."
|
|
9742
|
+
readinessFail: "Complete the title, description and add an image to fully leverage structured data.",
|
|
9743
|
+
coverageLabel: "Structured data coverage",
|
|
9744
|
+
coverageOptional: "Structured data is optional for this page type.",
|
|
9745
|
+
coveragePass: (type) => `Enough CMS data to generate a valid ${type} schema.`,
|
|
9746
|
+
coverageMissing: (type, fields) => `${type} schema expected for this page \u2014 required field(s) missing in the CMS: ${fields}.`,
|
|
9747
|
+
coverageMissingTip: "Complete these fields, or make sure the matching JSON-LD is injected at render time (frontend).",
|
|
9748
|
+
coverageRemind: (type, fields) => `${type} schema: required CMS fields are present. Also confirm these required fields the analyzer cannot detect: ${fields}.`,
|
|
9749
|
+
faqNoRichResultLabel: "FAQ / structured data",
|
|
9750
|
+
faqNoRichResult: "FAQPage detected \u2014 markup is valid and still read by search/AI engines, but Google no longer renders FAQ rich results (2026). Keep the markup; do not expect an enhanced SERP snippet."
|
|
9006
9751
|
},
|
|
9007
9752
|
technical: {
|
|
9008
9753
|
canonicalMissingLabel: "Canonical URL",
|
|
@@ -9011,6 +9756,8 @@ var rulesEn = {
|
|
|
9011
9756
|
canonicalInvalidMessage: (url) => `Canonical URL "${url}" is invalid \u2014 Use an absolute URL (https://...).`,
|
|
9012
9757
|
canonicalExternalLabel: "Canonical URL",
|
|
9013
9758
|
canonicalExternalMessage: "Canonical URL points to an external domain \u2014 Verify this is intentional.",
|
|
9759
|
+
canonicalCrossLabel: "Canonical URL",
|
|
9760
|
+
canonicalCrossMessage: (target) => `Canonical URL points to a DIFFERENT page (${target}) \u2014 this page de-indexes itself in favor of that URL. Verify this is intentional.`,
|
|
9014
9761
|
canonicalOkLabel: "Canonical URL",
|
|
9015
9762
|
canonicalOkMessage: "Canonical URL is correctly defined.",
|
|
9016
9763
|
robotsNoindexLabel: "Robots noindex",
|
|
@@ -9363,6 +10110,21 @@ function getTranslations(locale) {
|
|
|
9363
10110
|
}
|
|
9364
10111
|
|
|
9365
10112
|
// src/rules/title.ts
|
|
10113
|
+
var TITLE_PIXEL_MAX = 600;
|
|
10114
|
+
var NARROW_CHARS = new Set("iIl.,:;|!'`jft()[]{}/\\".split(""));
|
|
10115
|
+
var WIDE_CHARS = new Set("mwMW@%".split(""));
|
|
10116
|
+
function estimateTitlePixelWidth(title) {
|
|
10117
|
+
let px = 0;
|
|
10118
|
+
for (const ch of title) {
|
|
10119
|
+
if (ch === " ") px += 5;
|
|
10120
|
+
else if (NARROW_CHARS.has(ch)) px += 5;
|
|
10121
|
+
else if (WIDE_CHARS.has(ch)) px += 15;
|
|
10122
|
+
else if (ch >= "A" && ch <= "Z") px += 12;
|
|
10123
|
+
else if (ch >= "0" && ch <= "9") px += 10;
|
|
10124
|
+
else px += 9;
|
|
10125
|
+
}
|
|
10126
|
+
return Math.round(px);
|
|
10127
|
+
}
|
|
9366
10128
|
function checkTitle(input, ctx) {
|
|
9367
10129
|
const checks = [];
|
|
9368
10130
|
const r = getTranslations(ctx.locale).rules.title;
|
|
@@ -9388,8 +10150,10 @@ function checkTitle(input, ctx) {
|
|
|
9388
10150
|
label: r.lengthLabel,
|
|
9389
10151
|
status: "warning",
|
|
9390
10152
|
message: r.lengthShort(titleLen),
|
|
9391
|
-
|
|
9392
|
-
weight
|
|
10153
|
+
// SEO desintox: title length is a SERP-display hint, NOT a ranking factor
|
|
10154
|
+
// (Google rewrites 60%+ of titles). Informational weight, never critical.
|
|
10155
|
+
category: "bonus",
|
|
10156
|
+
weight: 1,
|
|
9393
10157
|
group: "title",
|
|
9394
10158
|
tip: r.lengthShortTip
|
|
9395
10159
|
});
|
|
@@ -9399,8 +10163,8 @@ function checkTitle(input, ctx) {
|
|
|
9399
10163
|
label: r.lengthLabel,
|
|
9400
10164
|
status: "warning",
|
|
9401
10165
|
message: r.lengthLong(titleLen),
|
|
9402
|
-
category: "
|
|
9403
|
-
weight:
|
|
10166
|
+
category: "bonus",
|
|
10167
|
+
weight: 1,
|
|
9404
10168
|
group: "title",
|
|
9405
10169
|
tip: r.lengthLongTip
|
|
9406
10170
|
});
|
|
@@ -9410,11 +10174,21 @@ function checkTitle(input, ctx) {
|
|
|
9410
10174
|
label: r.lengthLabel,
|
|
9411
10175
|
status: "pass",
|
|
9412
10176
|
message: r.lengthPass(titleLen),
|
|
9413
|
-
category: "
|
|
9414
|
-
weight:
|
|
10177
|
+
category: "bonus",
|
|
10178
|
+
weight: 1,
|
|
9415
10179
|
group: "title"
|
|
9416
10180
|
});
|
|
9417
10181
|
}
|
|
10182
|
+
const titlePx = estimateTitlePixelWidth(title);
|
|
10183
|
+
checks.push({
|
|
10184
|
+
id: "title-pixel-width",
|
|
10185
|
+
label: r.pixelWidthLabel,
|
|
10186
|
+
status: titlePx > TITLE_PIXEL_MAX ? "warning" : "pass",
|
|
10187
|
+
message: titlePx > TITLE_PIXEL_MAX ? r.pixelWidthWarn(titlePx) : r.pixelWidthPass(titlePx),
|
|
10188
|
+
category: "bonus",
|
|
10189
|
+
weight: 0,
|
|
10190
|
+
group: "title"
|
|
10191
|
+
});
|
|
9418
10192
|
if (kw) {
|
|
9419
10193
|
const titleNorm = normalizeForComparison(title);
|
|
9420
10194
|
const kwPresent = keywordMatchesText(kw, titleNorm);
|
|
@@ -9950,44 +10724,15 @@ function checkContent(input, ctx) {
|
|
|
9950
10724
|
weight: 2,
|
|
9951
10725
|
group: "content"
|
|
9952
10726
|
});
|
|
9953
|
-
} else if (density >= KEYWORD_DENSITY_MIN) {
|
|
9954
|
-
checks.push({
|
|
9955
|
-
id: "content-keyword-density",
|
|
9956
|
-
label: r.densityLabel,
|
|
9957
|
-
status: "pass",
|
|
9958
|
-
message: exactCount > 0 ? r.densityPass(density.toFixed(1)) : r.densityPassWordLevel(density.toFixed(1)),
|
|
9959
|
-
category: "important",
|
|
9960
|
-
weight: 2,
|
|
9961
|
-
group: "content"
|
|
9962
|
-
});
|
|
9963
|
-
} else if (wordLevelMatch) {
|
|
9964
|
-
checks.push({
|
|
9965
|
-
id: "content-keyword-density",
|
|
9966
|
-
label: r.densityLabel,
|
|
9967
|
-
status: "warning",
|
|
9968
|
-
message: r.densityLowWordLevel(density.toFixed(1)),
|
|
9969
|
-
category: "important",
|
|
9970
|
-
weight: 2,
|
|
9971
|
-
group: "content"
|
|
9972
|
-
});
|
|
9973
|
-
} else if (exactCount > 0) {
|
|
9974
|
-
checks.push({
|
|
9975
|
-
id: "content-keyword-density",
|
|
9976
|
-
label: r.densityLabel,
|
|
9977
|
-
status: "warning",
|
|
9978
|
-
message: r.densityLow(density.toFixed(1)),
|
|
9979
|
-
category: "important",
|
|
9980
|
-
weight: 2,
|
|
9981
|
-
group: "content"
|
|
9982
|
-
});
|
|
9983
10727
|
} else {
|
|
10728
|
+
const present = exactCount > 0 || wordLevelMatch;
|
|
9984
10729
|
checks.push({
|
|
9985
10730
|
id: "content-keyword-density",
|
|
9986
10731
|
label: r.densityLabel,
|
|
9987
|
-
status: "
|
|
9988
|
-
message: r.densityMissing(input.focusKeyword || normalizedKeyword),
|
|
9989
|
-
category: "
|
|
9990
|
-
weight:
|
|
10732
|
+
status: "pass",
|
|
10733
|
+
message: present ? r.densityPass(density.toFixed(1)) : r.densityMissing(input.focusKeyword || normalizedKeyword),
|
|
10734
|
+
category: "bonus",
|
|
10735
|
+
weight: 0,
|
|
9991
10736
|
group: "content"
|
|
9992
10737
|
});
|
|
9993
10738
|
}
|
|
@@ -10034,39 +10779,17 @@ function checkContent(input, ctx) {
|
|
|
10034
10779
|
const tiersWithKw = [tier1, tier2, tier3].filter(
|
|
10035
10780
|
(t) => keywordMatchesText(normalizedKeyword, t)
|
|
10036
10781
|
).length;
|
|
10037
|
-
|
|
10038
|
-
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10042
|
-
|
|
10043
|
-
|
|
10044
|
-
|
|
10045
|
-
|
|
10046
|
-
}
|
|
10047
|
-
}
|
|
10048
|
-
checks.push({
|
|
10049
|
-
id: "content-keyword-distribution",
|
|
10050
|
-
label: r.distributionLabel,
|
|
10051
|
-
status: "warning",
|
|
10052
|
-
message: r.distributionWarn,
|
|
10053
|
-
category: "important",
|
|
10054
|
-
weight: 2,
|
|
10055
|
-
group: "content",
|
|
10056
|
-
tip: r.distributionWarnTip
|
|
10057
|
-
});
|
|
10058
|
-
} else {
|
|
10059
|
-
checks.push({
|
|
10060
|
-
id: "content-keyword-distribution",
|
|
10061
|
-
label: r.distributionLabel,
|
|
10062
|
-
status: "fail",
|
|
10063
|
-
message: r.distributionFail,
|
|
10064
|
-
category: "important",
|
|
10065
|
-
weight: 2,
|
|
10066
|
-
group: "content",
|
|
10067
|
-
tip: r.distributionFailTip
|
|
10068
|
-
});
|
|
10069
|
-
}
|
|
10782
|
+
const wellDistributed = tiersWithKw >= 2;
|
|
10783
|
+
checks.push({
|
|
10784
|
+
id: "content-keyword-distribution",
|
|
10785
|
+
label: r.distributionLabel,
|
|
10786
|
+
status: wellDistributed ? "pass" : "warning",
|
|
10787
|
+
message: wellDistributed ? r.distributionPass(tiersWithKw) : r.distributionWarn,
|
|
10788
|
+
category: "bonus",
|
|
10789
|
+
weight: 0,
|
|
10790
|
+
group: "content",
|
|
10791
|
+
...wellDistributed ? {} : { tip: r.distributionWarnTip }
|
|
10792
|
+
});
|
|
10070
10793
|
}
|
|
10071
10794
|
if (wordCount > 500) {
|
|
10072
10795
|
const allLists = [];
|
|
@@ -10558,23 +11281,161 @@ function checkSocial(input, ctx) {
|
|
|
10558
11281
|
return checks;
|
|
10559
11282
|
}
|
|
10560
11283
|
|
|
11284
|
+
// src/rules/schema-requirements.ts
|
|
11285
|
+
var SCHEMA_REQUIREMENTS = {
|
|
11286
|
+
Article: {
|
|
11287
|
+
required: ["headline", "image"],
|
|
11288
|
+
recommended: ["author", "datePublished", "dateModified", "publisher"],
|
|
11289
|
+
richResult: true
|
|
11290
|
+
},
|
|
11291
|
+
Product: {
|
|
11292
|
+
// Google needs name + at least one of offers / review / aggregateRating
|
|
11293
|
+
required: ["name", "offers"],
|
|
11294
|
+
recommended: ["image", "brand", "aggregateRating", "review", "sku"],
|
|
11295
|
+
richResult: true
|
|
11296
|
+
},
|
|
11297
|
+
LocalBusiness: {
|
|
11298
|
+
required: ["name", "address"],
|
|
11299
|
+
recommended: ["telephone", "openingHours", "geo", "priceRange"],
|
|
11300
|
+
richResult: true
|
|
11301
|
+
},
|
|
11302
|
+
BreadcrumbList: {
|
|
11303
|
+
required: ["itemListElement"],
|
|
11304
|
+
recommended: [],
|
|
11305
|
+
richResult: true
|
|
11306
|
+
},
|
|
11307
|
+
Organization: {
|
|
11308
|
+
required: ["name", "url"],
|
|
11309
|
+
recommended: ["logo", "sameAs"],
|
|
11310
|
+
richResult: false
|
|
11311
|
+
},
|
|
11312
|
+
Person: {
|
|
11313
|
+
required: ["name"],
|
|
11314
|
+
recommended: ["sameAs", "jobTitle", "image", "url"],
|
|
11315
|
+
richResult: false
|
|
11316
|
+
},
|
|
11317
|
+
FAQPage: {
|
|
11318
|
+
required: ["mainEntity"],
|
|
11319
|
+
recommended: [],
|
|
11320
|
+
// FAQ rich results removed by Google (May 2026). Markup still useful for AI/search understanding.
|
|
11321
|
+
richResult: false
|
|
11322
|
+
},
|
|
11323
|
+
Event: {
|
|
11324
|
+
required: ["name", "startDate", "location"],
|
|
11325
|
+
recommended: ["endDate", "offers", "image", "performer"],
|
|
11326
|
+
richResult: true
|
|
11327
|
+
},
|
|
11328
|
+
Recipe: {
|
|
11329
|
+
required: ["name", "image", "recipeIngredient", "recipeInstructions"],
|
|
11330
|
+
recommended: ["nutrition", "aggregateRating", "totalTime", "recipeYield"],
|
|
11331
|
+
richResult: true
|
|
11332
|
+
},
|
|
11333
|
+
Video: {
|
|
11334
|
+
required: ["name", "thumbnailUrl", "uploadDate"],
|
|
11335
|
+
recommended: ["duration", "contentUrl", "description"],
|
|
11336
|
+
richResult: true
|
|
11337
|
+
}
|
|
11338
|
+
};
|
|
11339
|
+
var CMS_VERIFIABLE_SCHEMA_FIELDS = /* @__PURE__ */ new Set([
|
|
11340
|
+
"headline",
|
|
11341
|
+
"name",
|
|
11342
|
+
"image",
|
|
11343
|
+
"url",
|
|
11344
|
+
"itemListElement",
|
|
11345
|
+
"mainEntity"
|
|
11346
|
+
]);
|
|
11347
|
+
|
|
10561
11348
|
// src/rules/schema.ts
|
|
11349
|
+
var FAQ_BLOCK_TYPES = /* @__PURE__ */ new Set(["faq", "FAQ", "faqBlock", "faqs"]);
|
|
11350
|
+
function hasFaqBlock(blocks) {
|
|
11351
|
+
if (!Array.isArray(blocks)) return false;
|
|
11352
|
+
return blocks.some((block) => {
|
|
11353
|
+
if (!block || typeof block !== "object") return false;
|
|
11354
|
+
const t = block.blockType;
|
|
11355
|
+
return typeof t === "string" && FAQ_BLOCK_TYPES.has(t);
|
|
11356
|
+
});
|
|
11357
|
+
}
|
|
11358
|
+
function detectExpectedSchemaType(input, ctx) {
|
|
11359
|
+
if (input.isProduct) return "Product";
|
|
11360
|
+
if (input.isPost || ctx.pageType === "blog") return "Article";
|
|
11361
|
+
if (ctx.pageType === "local-seo") return "LocalBusiness";
|
|
11362
|
+
if (ctx.pageType === "agency") return "Organization";
|
|
11363
|
+
if (ctx.pageType === "legal" || ctx.pageType === "contact" || ctx.pageType === "form") return null;
|
|
11364
|
+
return "Article";
|
|
11365
|
+
}
|
|
10562
11366
|
function checkSchema(input, ctx) {
|
|
10563
11367
|
const checks = [];
|
|
10564
11368
|
const r = getTranslations(ctx.locale).rules.schema;
|
|
10565
|
-
const
|
|
10566
|
-
const
|
|
10567
|
-
|
|
10568
|
-
|
|
10569
|
-
|
|
10570
|
-
|
|
10571
|
-
|
|
10572
|
-
|
|
10573
|
-
|
|
10574
|
-
|
|
10575
|
-
|
|
10576
|
-
|
|
10577
|
-
|
|
11369
|
+
const faqPresent = hasFaqBlock(input.blocks);
|
|
11370
|
+
const present = {
|
|
11371
|
+
headline: !!(input.metaTitle || input.heroTitle) || ctx.allHeadings.some((h) => h.tag === "h1"),
|
|
11372
|
+
name: !!(input.metaTitle || input.heroTitle),
|
|
11373
|
+
image: ctx.imageStats.total > 0 || !!input.metaImage,
|
|
11374
|
+
url: true,
|
|
11375
|
+
itemListElement: !!input.slug,
|
|
11376
|
+
mainEntity: faqPresent
|
|
11377
|
+
};
|
|
11378
|
+
const expected = detectExpectedSchemaType(input, ctx);
|
|
11379
|
+
if (expected === null) {
|
|
11380
|
+
checks.push({
|
|
11381
|
+
id: "schema-coverage",
|
|
11382
|
+
label: r.coverageLabel,
|
|
11383
|
+
status: "pass",
|
|
11384
|
+
message: r.coverageOptional,
|
|
11385
|
+
category: "bonus",
|
|
11386
|
+
weight: 0,
|
|
11387
|
+
group: "schema"
|
|
11388
|
+
});
|
|
11389
|
+
} else {
|
|
11390
|
+
const reqDef = SCHEMA_REQUIREMENTS[expected];
|
|
11391
|
+
const knownMissing = reqDef.required.filter(
|
|
11392
|
+
(f) => CMS_VERIFIABLE_SCHEMA_FIELDS.has(f) && !present[f]
|
|
11393
|
+
);
|
|
11394
|
+
const unverifiable = reqDef.required.filter((f) => !CMS_VERIFIABLE_SCHEMA_FIELDS.has(f));
|
|
11395
|
+
if (knownMissing.length > 0) {
|
|
11396
|
+
checks.push({
|
|
11397
|
+
id: "schema-coverage",
|
|
11398
|
+
label: r.coverageLabel,
|
|
11399
|
+
status: "warning",
|
|
11400
|
+
message: r.coverageMissing(expected, knownMissing.join(", ")),
|
|
11401
|
+
category: "bonus",
|
|
11402
|
+
weight: 1,
|
|
11403
|
+
group: "schema",
|
|
11404
|
+
tip: r.coverageMissingTip
|
|
11405
|
+
});
|
|
11406
|
+
} else if (unverifiable.length > 0) {
|
|
11407
|
+
checks.push({
|
|
11408
|
+
id: "schema-coverage",
|
|
11409
|
+
label: r.coverageLabel,
|
|
11410
|
+
status: "pass",
|
|
11411
|
+
message: r.coverageRemind(expected, unverifiable.join(", ")),
|
|
11412
|
+
category: "bonus",
|
|
11413
|
+
weight: 0,
|
|
11414
|
+
group: "schema"
|
|
11415
|
+
});
|
|
11416
|
+
} else {
|
|
11417
|
+
checks.push({
|
|
11418
|
+
id: "schema-coverage",
|
|
11419
|
+
label: r.coverageLabel,
|
|
11420
|
+
status: "pass",
|
|
11421
|
+
message: r.coveragePass(expected),
|
|
11422
|
+
category: "bonus",
|
|
11423
|
+
weight: 1,
|
|
11424
|
+
group: "schema"
|
|
11425
|
+
});
|
|
11426
|
+
}
|
|
11427
|
+
}
|
|
11428
|
+
if (faqPresent && true) {
|
|
11429
|
+
checks.push({
|
|
11430
|
+
id: "schema-faq-no-rich-result",
|
|
11431
|
+
label: r.faqNoRichResultLabel,
|
|
11432
|
+
status: "pass",
|
|
11433
|
+
message: r.faqNoRichResult,
|
|
11434
|
+
category: "bonus",
|
|
11435
|
+
weight: 0,
|
|
11436
|
+
group: "schema"
|
|
11437
|
+
});
|
|
11438
|
+
}
|
|
10578
11439
|
return checks;
|
|
10579
11440
|
}
|
|
10580
11441
|
|
|
@@ -10696,8 +11557,8 @@ function checkReadability(input, ctx) {
|
|
|
10696
11557
|
label: r.passiveLabelFail,
|
|
10697
11558
|
status: "warning",
|
|
10698
11559
|
message: r.passiveFail(passiveSentences.length, sentences.length, Math.round(passiveRatio * 100)),
|
|
10699
|
-
category: "
|
|
10700
|
-
weight:
|
|
11560
|
+
category: "bonus",
|
|
11561
|
+
weight: 0,
|
|
10701
11562
|
group: "readability"
|
|
10702
11563
|
});
|
|
10703
11564
|
} else {
|
|
@@ -10706,8 +11567,8 @@ function checkReadability(input, ctx) {
|
|
|
10706
11567
|
label: r.passiveLabelPass,
|
|
10707
11568
|
status: "pass",
|
|
10708
11569
|
message: r.passivePass(Math.round(passiveRatio * 100)),
|
|
10709
|
-
category: "
|
|
10710
|
-
weight:
|
|
11570
|
+
category: "bonus",
|
|
11571
|
+
weight: 0,
|
|
10711
11572
|
group: "readability"
|
|
10712
11573
|
});
|
|
10713
11574
|
}
|
|
@@ -10722,7 +11583,7 @@ function checkReadability(input, ctx) {
|
|
|
10722
11583
|
status: "warning",
|
|
10723
11584
|
message: r.transitionsFail(Math.round(transitionRatio * 100)),
|
|
10724
11585
|
category: "bonus",
|
|
10725
|
-
weight:
|
|
11586
|
+
weight: 0,
|
|
10726
11587
|
group: "readability"
|
|
10727
11588
|
});
|
|
10728
11589
|
} else {
|
|
@@ -10732,7 +11593,7 @@ function checkReadability(input, ctx) {
|
|
|
10732
11593
|
status: "pass",
|
|
10733
11594
|
message: r.transitionsPass(Math.round(transitionRatio * 100)),
|
|
10734
11595
|
category: "bonus",
|
|
10735
|
-
weight:
|
|
11596
|
+
weight: 0,
|
|
10736
11597
|
group: "readability"
|
|
10737
11598
|
});
|
|
10738
11599
|
}
|
|
@@ -11180,10 +12041,34 @@ function checkFreshness(input, ctx) {
|
|
|
11180
12041
|
group: "freshness"
|
|
11181
12042
|
});
|
|
11182
12043
|
}
|
|
12044
|
+
if (input.displayedDate && input.updatedAt) {
|
|
12045
|
+
const displayedDays = daysSince(input.displayedDate);
|
|
12046
|
+
const updatedDays = daysSince(input.updatedAt);
|
|
12047
|
+
if (displayedDays !== Infinity && updatedDays !== Infinity && updatedDays - displayedDays > 60) {
|
|
12048
|
+
checks.push({
|
|
12049
|
+
id: "freshness-fake-refresh",
|
|
12050
|
+
label: r.fakeRefreshLabel,
|
|
12051
|
+
status: "warning",
|
|
12052
|
+
message: r.fakeRefreshWarn(displayedDays, updatedDays),
|
|
12053
|
+
category: "bonus",
|
|
12054
|
+
weight: 0,
|
|
12055
|
+
group: "freshness",
|
|
12056
|
+
tip: r.fakeRefreshTip
|
|
12057
|
+
});
|
|
12058
|
+
}
|
|
12059
|
+
}
|
|
11183
12060
|
return checks;
|
|
11184
12061
|
}
|
|
11185
12062
|
|
|
11186
12063
|
// src/rules/technical.ts
|
|
12064
|
+
function isCrossCanonical(canonical, siteUrl, slug) {
|
|
12065
|
+
const norm = (p) => p.replace(/[?#].*$/, "").replace(/^\/+/, "").replace(/\/+$/, "").toLowerCase();
|
|
12066
|
+
const canonicalPath = norm(canonical.slice(siteUrl.length));
|
|
12067
|
+
const selfPath = norm(slug);
|
|
12068
|
+
const selfIsHome = selfPath === "" || selfPath === "home";
|
|
12069
|
+
if (selfIsHome) return canonicalPath !== "" && canonicalPath !== "home";
|
|
12070
|
+
return canonicalPath !== selfPath;
|
|
12071
|
+
}
|
|
11187
12072
|
function checkTechnical(input, ctx) {
|
|
11188
12073
|
const checks = [];
|
|
11189
12074
|
const r = getTranslations(ctx.locale).rules.technical;
|
|
@@ -11221,6 +12106,16 @@ function checkTechnical(input, ctx) {
|
|
|
11221
12106
|
weight: 2,
|
|
11222
12107
|
group: "technical"
|
|
11223
12108
|
});
|
|
12109
|
+
} else if (siteUrl && input.slug && !input.isGlobal && isCrossCanonical(canonical, siteUrl, input.slug)) {
|
|
12110
|
+
checks.push({
|
|
12111
|
+
id: "canonical-cross",
|
|
12112
|
+
label: r.canonicalCrossLabel,
|
|
12113
|
+
status: "warning",
|
|
12114
|
+
message: r.canonicalCrossMessage(canonical),
|
|
12115
|
+
category: "important",
|
|
12116
|
+
weight: 2,
|
|
12117
|
+
group: "technical"
|
|
12118
|
+
});
|
|
11224
12119
|
} else {
|
|
11225
12120
|
checks.push({
|
|
11226
12121
|
id: "canonical-ok",
|
|
@@ -11513,6 +12408,336 @@ function checkEcommerce(input, ctx) {
|
|
|
11513
12408
|
return checks;
|
|
11514
12409
|
}
|
|
11515
12410
|
|
|
12411
|
+
// src/rules/eeat.ts
|
|
12412
|
+
var STRINGS = {
|
|
12413
|
+
fr: {
|
|
12414
|
+
authorLabel: "Auteur attribu\xE9 (E-E-A-T)",
|
|
12415
|
+
authorPass: "Un auteur est attribu\xE9 \u2014 bon signal de transparence E-E-A-T.",
|
|
12416
|
+
authorFail: "Aucun auteur identifi\xE9 \u2014 attribuez un auteur r\xE9el pour renforcer la confiance (E-E-A-T).",
|
|
12417
|
+
authorTip: "Ajoutez un auteur avec une courte bio et un lien vers son profil (Person schema + sameAs).",
|
|
12418
|
+
authorEntityLabel: "Entit\xE9 auteur (profil / sameAs)",
|
|
12419
|
+
authorEntityPass: "L'auteur a un lien de profil \u2014 renforce l'entit\xE9 (sameAs) pour les moteurs et l'IA.",
|
|
12420
|
+
authorEntityFail: "L'auteur n'a pas de lien de profil \u2014 ajoutez une URL (LinkedIn, page auteur) comme sameAs.",
|
|
12421
|
+
datesLabel: "Dates de publication / mise \xE0 jour",
|
|
12422
|
+
datesPass: "Dates de publication et de mise \xE0 jour disponibles \u2014 bon pour la fra\xEEcheur et la confiance.",
|
|
12423
|
+
datesFail: "Date de publication ou de mise \xE0 jour manquante \u2014 exposez datePublished et dateModified.",
|
|
12424
|
+
sourcesLabel: "Sources externes cit\xE9es",
|
|
12425
|
+
sourcesPass: (n) => `${n} lien(s) vers des sources externes \u2014 renforce la cr\xE9dibilit\xE9 et l'E-E-A-T.`,
|
|
12426
|
+
sourcesFail: "Aucune source externe cit\xE9e \u2014 liez des sources fiables pour appuyer vos affirmations.",
|
|
12427
|
+
sourcesTip: "Citez des \xE9tudes, donn\xE9es officielles ou r\xE9f\xE9rences sectorielles avec des liens sortants.",
|
|
12428
|
+
dataLabel: "Donn\xE9es originales / chiffr\xE9es",
|
|
12429
|
+
dataPass: "Le contenu pr\xE9sente des donn\xE9es chiffr\xE9es \u2014 signal d'expertise et de contenu original.",
|
|
12430
|
+
dataFail: "Peu de donn\xE9es chiffr\xE9es d\xE9tect\xE9es \u2014 ajoutez des chiffres, statistiques ou r\xE9sultats concrets.",
|
|
12431
|
+
dataTip: "Le contenu d\xE9montrant une exp\xE9rience de premi\xE8re main (donn\xE9es, chiffres, exemples v\xE9cus) est le levier de mont\xE9e n\xB01 en 2026."
|
|
12432
|
+
},
|
|
12433
|
+
en: {
|
|
12434
|
+
authorLabel: "Attributed author (E-E-A-T)",
|
|
12435
|
+
authorPass: "An author is attributed \u2014 good E-E-A-T transparency signal.",
|
|
12436
|
+
authorFail: "No identified author \u2014 attribute a real author to strengthen trust (E-E-A-T).",
|
|
12437
|
+
authorTip: "Add an author with a short bio and a link to their profile (Person schema + sameAs).",
|
|
12438
|
+
authorEntityLabel: "Author entity (profile / sameAs)",
|
|
12439
|
+
authorEntityPass: "The author has a profile link \u2014 strengthens the entity (sameAs) for search and AI.",
|
|
12440
|
+
authorEntityFail: "The author has no profile link \u2014 add a URL (LinkedIn, author page) as sameAs.",
|
|
12441
|
+
datesLabel: "Published / updated dates",
|
|
12442
|
+
datesPass: "Published and modified dates available \u2014 good for freshness and trust.",
|
|
12443
|
+
datesFail: "Published or modified date missing \u2014 expose datePublished and dateModified.",
|
|
12444
|
+
sourcesLabel: "External sources cited",
|
|
12445
|
+
sourcesPass: (n) => `${n} link(s) to external sources \u2014 strengthens credibility and E-E-A-T.`,
|
|
12446
|
+
sourcesFail: "No external source cited \u2014 link reliable sources to back your claims.",
|
|
12447
|
+
sourcesTip: "Cite studies, official data or industry references with outbound links.",
|
|
12448
|
+
dataLabel: "Original / quantitative data",
|
|
12449
|
+
dataPass: "The content includes quantitative data \u2014 a signal of expertise and original content.",
|
|
12450
|
+
dataFail: "Little quantitative data detected \u2014 add figures, statistics or concrete results.",
|
|
12451
|
+
dataTip: "First-hand-experience content (data, figures, lived examples) is the #1 visibility lever in 2026."
|
|
12452
|
+
}
|
|
12453
|
+
};
|
|
12454
|
+
var EEAT_SKIP_PAGE_TYPES = /* @__PURE__ */ new Set(["legal", "contact", "form", "home"]);
|
|
12455
|
+
function checkEeat(input, ctx) {
|
|
12456
|
+
const checks = [];
|
|
12457
|
+
if (EEAT_SKIP_PAGE_TYPES.has(ctx.pageType) || ctx.wordCount < 100) return checks;
|
|
12458
|
+
const s = STRINGS[ctx.locale] ?? STRINGS.fr;
|
|
12459
|
+
const hasAuthor = !!(input.author && input.author.trim());
|
|
12460
|
+
checks.push({
|
|
12461
|
+
id: "eeat-author",
|
|
12462
|
+
label: s.authorLabel,
|
|
12463
|
+
status: hasAuthor ? "pass" : "warning",
|
|
12464
|
+
message: hasAuthor ? s.authorPass : s.authorFail,
|
|
12465
|
+
category: "important",
|
|
12466
|
+
weight: 0,
|
|
12467
|
+
group: "eeat",
|
|
12468
|
+
...hasAuthor ? {} : { tip: s.authorTip }
|
|
12469
|
+
});
|
|
12470
|
+
if (hasAuthor) {
|
|
12471
|
+
const hasLink = !!(input.authorUrl && input.authorUrl.trim());
|
|
12472
|
+
checks.push({
|
|
12473
|
+
id: "eeat-author-entity",
|
|
12474
|
+
label: s.authorEntityLabel,
|
|
12475
|
+
status: hasLink ? "pass" : "warning",
|
|
12476
|
+
message: hasLink ? s.authorEntityPass : s.authorEntityFail,
|
|
12477
|
+
category: "bonus",
|
|
12478
|
+
weight: 0,
|
|
12479
|
+
group: "eeat"
|
|
12480
|
+
});
|
|
12481
|
+
}
|
|
12482
|
+
const datesOk = !!input.publishedAt && !!input.updatedAt;
|
|
12483
|
+
checks.push({
|
|
12484
|
+
id: "eeat-dates",
|
|
12485
|
+
label: s.datesLabel,
|
|
12486
|
+
status: datesOk ? "pass" : "warning",
|
|
12487
|
+
message: datesOk ? s.datesPass : s.datesFail,
|
|
12488
|
+
category: "bonus",
|
|
12489
|
+
weight: 0,
|
|
12490
|
+
group: "eeat"
|
|
12491
|
+
});
|
|
12492
|
+
const externalLinks = ctx.allLinks.filter((l) => /^https?:\/\//i.test(l.url));
|
|
12493
|
+
const hasSources = externalLinks.length > 0;
|
|
12494
|
+
checks.push({
|
|
12495
|
+
id: "eeat-sources",
|
|
12496
|
+
label: s.sourcesLabel,
|
|
12497
|
+
status: hasSources ? "pass" : "warning",
|
|
12498
|
+
message: hasSources ? s.sourcesPass(externalLinks.length) : s.sourcesFail,
|
|
12499
|
+
category: "bonus",
|
|
12500
|
+
weight: 0,
|
|
12501
|
+
group: "eeat",
|
|
12502
|
+
...hasSources ? {} : { tip: s.sourcesTip }
|
|
12503
|
+
});
|
|
12504
|
+
const hasPercent = /\d+([.,]\d+)?\s?%/.test(ctx.fullText);
|
|
12505
|
+
const numberCount = (ctx.fullText.match(/\b\d{2,}\b/g) || []).length;
|
|
12506
|
+
const hasData = hasPercent || numberCount >= 3;
|
|
12507
|
+
checks.push({
|
|
12508
|
+
id: "eeat-original-data",
|
|
12509
|
+
label: s.dataLabel,
|
|
12510
|
+
status: hasData ? "pass" : "warning",
|
|
12511
|
+
message: hasData ? s.dataPass : s.dataFail,
|
|
12512
|
+
category: "bonus",
|
|
12513
|
+
weight: 0,
|
|
12514
|
+
group: "eeat",
|
|
12515
|
+
...hasData ? {} : { tip: s.dataTip }
|
|
12516
|
+
});
|
|
12517
|
+
return checks;
|
|
12518
|
+
}
|
|
12519
|
+
|
|
12520
|
+
// src/rules/geo.ts
|
|
12521
|
+
var QUESTION_WORDS = {
|
|
12522
|
+
fr: ["comment", "pourquoi", "quand", "quel", "quelle", "quels", "quelles", "combien", "ou", "o\xF9", "qui", "que", "quoi", "est-ce"],
|
|
12523
|
+
en: ["how", "why", "when", "what", "which", "where", "who", "can", "do", "does", "is", "are", "should"]
|
|
12524
|
+
};
|
|
12525
|
+
var STRINGS2 = {
|
|
12526
|
+
fr: {
|
|
12527
|
+
answerLabel: "R\xE9ponse en t\xEAte (answer-first)",
|
|
12528
|
+
answerPass: "Le contenu d\xE9marre par une accroche concise \u2014 favorise l'extraction par l'IA.",
|
|
12529
|
+
answerFail: "Le contenu ne d\xE9marre pas par une r\xE9ponse concise \u2014 placez une r\xE9ponse directe en t\xEAte de page/section.",
|
|
12530
|
+
answerTip: "Format BLUF (Bottom Line Up Front) : r\xE9pondez \xE0 l'intention en 1-2 phrases avant de d\xE9velopper.",
|
|
12531
|
+
questionsLabel: "Titres en question",
|
|
12532
|
+
questionsPass: (n) => `${n} sous-titre(s) formul\xE9(s) en question \u2014 structure Q\u2192R id\xE9ale pour l'IA.`,
|
|
12533
|
+
questionsFail: "Aucun titre en question \u2014 formulez certains H2/H3 en questions (les moteurs IA citent les paires question/r\xE9ponse).",
|
|
12534
|
+
structureLabel: "Contenu extractible (listes / tableaux)",
|
|
12535
|
+
structurePass: "Listes ou tableaux d\xE9tect\xE9s \u2014 unit\xE9s facilement extraites et cit\xE9es par l'IA.",
|
|
12536
|
+
structureFail: "Aucune liste ni tableau \u2014 structurez les \xE9num\xE9rations et comparaisons en listes/tableaux.",
|
|
12537
|
+
chunkLabel: "Contenu d\xE9coup\xE9 (scannable)",
|
|
12538
|
+
chunkPass: "Contenu bien d\xE9coup\xE9 en sections \u2014 facilite l'extraction de passages.",
|
|
12539
|
+
chunkFail: "Contenu peu d\xE9coup\xE9 \u2014 ajoutez des sous-titres pour cr\xE9er des passages auto-suffisants."
|
|
12540
|
+
},
|
|
12541
|
+
en: {
|
|
12542
|
+
answerLabel: "Answer-first lead",
|
|
12543
|
+
answerPass: "Content opens with a concise lead \u2014 helps AI extraction.",
|
|
12544
|
+
answerFail: "Content does not open with a concise answer \u2014 put a direct answer at the top of the page/section.",
|
|
12545
|
+
answerTip: "BLUF (Bottom Line Up Front): answer the intent in 1-2 sentences before expanding.",
|
|
12546
|
+
questionsLabel: "Question-style headings",
|
|
12547
|
+
questionsPass: (n) => `${n} heading(s) phrased as questions \u2014 ideal Q\u2192A structure for AI.`,
|
|
12548
|
+
questionsFail: "No question headings \u2014 phrase some H2/H3 as questions (AI engines cite question/answer pairs).",
|
|
12549
|
+
structureLabel: "Extractable content (lists / tables)",
|
|
12550
|
+
structurePass: "Lists or tables detected \u2014 units easily extracted and cited by AI.",
|
|
12551
|
+
structureFail: "No list or table \u2014 structure enumerations and comparisons as lists/tables.",
|
|
12552
|
+
chunkLabel: "Chunked content (scannable)",
|
|
12553
|
+
chunkPass: "Content is well chunked into sections \u2014 helps passage extraction.",
|
|
12554
|
+
chunkFail: "Content is barely chunked \u2014 add subheadings to create self-contained passages."
|
|
12555
|
+
}
|
|
12556
|
+
};
|
|
12557
|
+
var GEO_SKIP_PAGE_TYPES = /* @__PURE__ */ new Set(["legal", "contact", "form", "home"]);
|
|
12558
|
+
function isQuestionHeading(text, locale) {
|
|
12559
|
+
const t = text.trim().toLowerCase();
|
|
12560
|
+
if (t.endsWith("?")) return true;
|
|
12561
|
+
const words = QUESTION_WORDS[locale] ?? QUESTION_WORDS.fr;
|
|
12562
|
+
return words.some((w) => t.startsWith(w + " ") || t.startsWith(w + "-"));
|
|
12563
|
+
}
|
|
12564
|
+
function collectLexicalSources(input) {
|
|
12565
|
+
const sources = [];
|
|
12566
|
+
if (input.heroRichText) sources.push(input.heroRichText);
|
|
12567
|
+
if (input.content) sources.push(input.content);
|
|
12568
|
+
if (Array.isArray(input.blocks)) {
|
|
12569
|
+
for (const b of input.blocks) {
|
|
12570
|
+
if (!b || typeof b !== "object") continue;
|
|
12571
|
+
const blk = b;
|
|
12572
|
+
if (blk.richText) sources.push(blk.richText);
|
|
12573
|
+
if (Array.isArray(blk.columns)) {
|
|
12574
|
+
for (const c of blk.columns) {
|
|
12575
|
+
if (c && typeof c === "object" && c.richText) {
|
|
12576
|
+
sources.push(c.richText);
|
|
12577
|
+
}
|
|
12578
|
+
}
|
|
12579
|
+
}
|
|
12580
|
+
}
|
|
12581
|
+
}
|
|
12582
|
+
return sources;
|
|
12583
|
+
}
|
|
12584
|
+
function containsLexicalType(node, type, depth = 0) {
|
|
12585
|
+
if (depth > 50 || !node || typeof node !== "object") return false;
|
|
12586
|
+
const n = node;
|
|
12587
|
+
if (n.type === type) return true;
|
|
12588
|
+
const root = n.root || n;
|
|
12589
|
+
const children = root.children || n.children;
|
|
12590
|
+
if (Array.isArray(children)) {
|
|
12591
|
+
for (const c of children) {
|
|
12592
|
+
if (containsLexicalType(c, type, depth + 1)) return true;
|
|
12593
|
+
}
|
|
12594
|
+
}
|
|
12595
|
+
return false;
|
|
12596
|
+
}
|
|
12597
|
+
function checkGeo(input, ctx) {
|
|
12598
|
+
const checks = [];
|
|
12599
|
+
if (GEO_SKIP_PAGE_TYPES.has(ctx.pageType) || ctx.wordCount < 150) return checks;
|
|
12600
|
+
const s = STRINGS2[ctx.locale] ?? STRINGS2.fr;
|
|
12601
|
+
const locale = ctx.locale;
|
|
12602
|
+
const firstSentence = (ctx.sentences[0] || "").trim();
|
|
12603
|
+
const firstSentenceWords = firstSentence ? firstSentence.split(/\s+/).length : 0;
|
|
12604
|
+
const answerFirst = firstSentenceWords > 0 && firstSentenceWords <= 30;
|
|
12605
|
+
checks.push({
|
|
12606
|
+
id: "geo-answer-first",
|
|
12607
|
+
label: s.answerLabel,
|
|
12608
|
+
status: answerFirst ? "pass" : "warning",
|
|
12609
|
+
message: answerFirst ? s.answerPass : s.answerFail,
|
|
12610
|
+
category: "bonus",
|
|
12611
|
+
weight: 0,
|
|
12612
|
+
group: "geo",
|
|
12613
|
+
...answerFirst ? {} : { tip: s.answerTip }
|
|
12614
|
+
});
|
|
12615
|
+
const questionHeadings = ctx.allHeadings.filter(
|
|
12616
|
+
(h) => h.tag !== "h1" && isQuestionHeading(h.text, locale)
|
|
12617
|
+
).length;
|
|
12618
|
+
checks.push({
|
|
12619
|
+
id: "geo-question-headings",
|
|
12620
|
+
label: s.questionsLabel,
|
|
12621
|
+
status: questionHeadings > 0 ? "pass" : "warning",
|
|
12622
|
+
message: questionHeadings > 0 ? s.questionsPass(questionHeadings) : s.questionsFail,
|
|
12623
|
+
category: "bonus",
|
|
12624
|
+
weight: 0,
|
|
12625
|
+
group: "geo"
|
|
12626
|
+
});
|
|
12627
|
+
const sources = collectLexicalSources(input);
|
|
12628
|
+
const hasList = sources.some((src) => extractListsFromLexical(src).length > 0);
|
|
12629
|
+
const hasTable = sources.some((src) => containsLexicalType(src, "table"));
|
|
12630
|
+
const structured = hasList || hasTable;
|
|
12631
|
+
checks.push({
|
|
12632
|
+
id: "geo-extractable-structure",
|
|
12633
|
+
label: s.structureLabel,
|
|
12634
|
+
status: structured ? "pass" : "warning",
|
|
12635
|
+
message: structured ? s.structurePass : s.structureFail,
|
|
12636
|
+
category: "bonus",
|
|
12637
|
+
weight: 0,
|
|
12638
|
+
group: "geo"
|
|
12639
|
+
});
|
|
12640
|
+
const subheadings = ctx.allHeadings.filter((h) => h.tag !== "h1").length;
|
|
12641
|
+
const expected = Math.max(1, Math.floor(ctx.wordCount / 300));
|
|
12642
|
+
const chunked = subheadings >= expected;
|
|
12643
|
+
checks.push({
|
|
12644
|
+
id: "geo-chunked",
|
|
12645
|
+
label: s.chunkLabel,
|
|
12646
|
+
status: chunked ? "pass" : "warning",
|
|
12647
|
+
message: chunked ? s.chunkPass : s.chunkFail,
|
|
12648
|
+
category: "bonus",
|
|
12649
|
+
weight: 0,
|
|
12650
|
+
group: "geo"
|
|
12651
|
+
});
|
|
12652
|
+
return checks;
|
|
12653
|
+
}
|
|
12654
|
+
|
|
12655
|
+
// src/rules/hreflang.ts
|
|
12656
|
+
var HREFLANG_RE = /^[a-z]{2,3}(-[a-z]{2,4})?$/i;
|
|
12657
|
+
var STRINGS3 = {
|
|
12658
|
+
fr: {
|
|
12659
|
+
codesLabel: "Codes hreflang valides",
|
|
12660
|
+
codesPass: "Tous les codes hreflang sont au format valide (langue ISO 639-1, r\xE9gion ISO 3166-1 optionnelle).",
|
|
12661
|
+
codesFail: (bad) => `Code(s) hreflang invalide(s) : ${bad} \u2014 un seul code erron\xE9 fait ignorer tout le cluster par Google.`,
|
|
12662
|
+
dupLabel: "Doublons hreflang",
|
|
12663
|
+
dupPass: "Aucun doublon de code hreflang.",
|
|
12664
|
+
dupFail: (dup) => `Code(s) hreflang en double : ${dup} \u2014 chaque locale doit \xEAtre d\xE9clar\xE9e une seule fois.`,
|
|
12665
|
+
absLabel: "URLs hreflang absolues",
|
|
12666
|
+
absPass: "Toutes les URLs hreflang sont absolues.",
|
|
12667
|
+
absFail: "Certaines URLs hreflang ne sont pas absolues \u2014 utilisez des URLs compl\xE8tes (https://...).",
|
|
12668
|
+
xdefLabel: "hreflang x-default",
|
|
12669
|
+
xdefPass: "Un x-default est d\xE9fini \u2014 bonne pratique pour les visiteurs hors locales cibl\xE9es.",
|
|
12670
|
+
xdefFail: 'Aucun x-default \u2014 ajoutez un hreflang="x-default" pour les locales non couvertes.'
|
|
12671
|
+
},
|
|
12672
|
+
en: {
|
|
12673
|
+
codesLabel: "Valid hreflang codes",
|
|
12674
|
+
codesPass: "All hreflang codes are well-formed (ISO 639-1 language, optional ISO 3166-1 region).",
|
|
12675
|
+
codesFail: (bad) => `Invalid hreflang code(s): ${bad} \u2014 a single bad code makes Google ignore the whole cluster.`,
|
|
12676
|
+
dupLabel: "Duplicate hreflang",
|
|
12677
|
+
dupPass: "No duplicate hreflang code.",
|
|
12678
|
+
dupFail: (dup) => `Duplicate hreflang code(s): ${dup} \u2014 each locale must be declared once.`,
|
|
12679
|
+
absLabel: "Absolute hreflang URLs",
|
|
12680
|
+
absPass: "All hreflang URLs are absolute.",
|
|
12681
|
+
absFail: "Some hreflang URLs are not absolute \u2014 use full URLs (https://...).",
|
|
12682
|
+
xdefLabel: "hreflang x-default",
|
|
12683
|
+
xdefPass: "An x-default is defined \u2014 good practice for visitors outside targeted locales.",
|
|
12684
|
+
xdefFail: 'No x-default \u2014 add hreflang="x-default" for locales you do not cover.'
|
|
12685
|
+
}
|
|
12686
|
+
};
|
|
12687
|
+
function checkHreflang(input, ctx) {
|
|
12688
|
+
const alts = input.localeAlternates;
|
|
12689
|
+
if (!Array.isArray(alts) || alts.length === 0) return [];
|
|
12690
|
+
const s = STRINGS3[ctx.locale] ?? STRINGS3.fr;
|
|
12691
|
+
const checks = [];
|
|
12692
|
+
const codes = alts.map((a) => (a.hreflang || "").trim()).filter(Boolean);
|
|
12693
|
+
const invalid = codes.filter((c) => c.toLowerCase() !== "x-default" && !HREFLANG_RE.test(c));
|
|
12694
|
+
checks.push({
|
|
12695
|
+
id: "hreflang-codes",
|
|
12696
|
+
label: s.codesLabel,
|
|
12697
|
+
status: invalid.length === 0 ? "pass" : "fail",
|
|
12698
|
+
message: invalid.length === 0 ? s.codesPass : s.codesFail(invalid.join(", ")),
|
|
12699
|
+
category: "important",
|
|
12700
|
+
weight: 2,
|
|
12701
|
+
group: "hreflang"
|
|
12702
|
+
});
|
|
12703
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12704
|
+
const dups = /* @__PURE__ */ new Set();
|
|
12705
|
+
for (const c of codes.map((c2) => c2.toLowerCase())) {
|
|
12706
|
+
if (seen.has(c)) dups.add(c);
|
|
12707
|
+
seen.add(c);
|
|
12708
|
+
}
|
|
12709
|
+
checks.push({
|
|
12710
|
+
id: "hreflang-duplicates",
|
|
12711
|
+
label: s.dupLabel,
|
|
12712
|
+
status: dups.size === 0 ? "pass" : "warning",
|
|
12713
|
+
message: dups.size === 0 ? s.dupPass : s.dupFail([...dups].join(", ")),
|
|
12714
|
+
category: "important",
|
|
12715
|
+
weight: 1,
|
|
12716
|
+
group: "hreflang"
|
|
12717
|
+
});
|
|
12718
|
+
const allAbsolute = alts.every((a) => /^https?:\/\//i.test((a.href || "").trim()));
|
|
12719
|
+
checks.push({
|
|
12720
|
+
id: "hreflang-absolute",
|
|
12721
|
+
label: s.absLabel,
|
|
12722
|
+
status: allAbsolute ? "pass" : "warning",
|
|
12723
|
+
message: allAbsolute ? s.absPass : s.absFail,
|
|
12724
|
+
category: "important",
|
|
12725
|
+
weight: 1,
|
|
12726
|
+
group: "hreflang"
|
|
12727
|
+
});
|
|
12728
|
+
const hasXDefault = codes.some((c) => c.toLowerCase() === "x-default");
|
|
12729
|
+
checks.push({
|
|
12730
|
+
id: "hreflang-x-default",
|
|
12731
|
+
label: s.xdefLabel,
|
|
12732
|
+
status: hasXDefault ? "pass" : "warning",
|
|
12733
|
+
message: hasXDefault ? s.xdefPass : s.xdefFail,
|
|
12734
|
+
category: "bonus",
|
|
12735
|
+
weight: 1,
|
|
12736
|
+
group: "hreflang"
|
|
12737
|
+
});
|
|
12738
|
+
return checks;
|
|
12739
|
+
}
|
|
12740
|
+
|
|
11516
12741
|
// src/index.ts
|
|
11517
12742
|
function buildContext(data, config) {
|
|
11518
12743
|
const {
|
|
@@ -11717,6 +12942,9 @@ function analyzeSeo(data, config) {
|
|
|
11717
12942
|
{ group: "freshness", fn: checkFreshness },
|
|
11718
12943
|
{ group: "technical", fn: checkTechnical },
|
|
11719
12944
|
{ group: "accessibility", fn: checkAccessibility },
|
|
12945
|
+
{ group: "eeat", fn: checkEeat },
|
|
12946
|
+
{ group: "geo", fn: checkGeo },
|
|
12947
|
+
{ group: "hreflang", fn: checkHreflang },
|
|
11720
12948
|
// E-commerce rules only run for product pages
|
|
11721
12949
|
...data.isProduct ? [{ group: "ecommerce", fn: checkEcommerce }] : []
|
|
11722
12950
|
];
|
|
@@ -11748,7 +12976,24 @@ function analyzeSeo(data, config) {
|
|
|
11748
12976
|
if (score >= SCORE_EXCELLENT) level = "excellent";
|
|
11749
12977
|
else if (score >= SCORE_GOOD) level = "good";
|
|
11750
12978
|
else if (score >= SCORE_OK) level = "ok";
|
|
11751
|
-
|
|
12979
|
+
const aiChecks = checks.filter(
|
|
12980
|
+
(c) => c.group === "geo" || c.group === "eeat" || c.id === "schema-coverage"
|
|
12981
|
+
);
|
|
12982
|
+
let aiReadiness;
|
|
12983
|
+
if (aiChecks.length > 0) {
|
|
12984
|
+
let aiEarned = 0;
|
|
12985
|
+
for (const c of aiChecks) {
|
|
12986
|
+
if (c.status === "pass") aiEarned += 1;
|
|
12987
|
+
else if (c.status === "warning") aiEarned += WARNING_MULTIPLIER;
|
|
12988
|
+
}
|
|
12989
|
+
const aiScore = Math.round(aiEarned / aiChecks.length * 100);
|
|
12990
|
+
let aiLevel = "poor";
|
|
12991
|
+
if (aiScore >= SCORE_EXCELLENT) aiLevel = "excellent";
|
|
12992
|
+
else if (aiScore >= SCORE_GOOD) aiLevel = "good";
|
|
12993
|
+
else if (aiScore >= SCORE_OK) aiLevel = "ok";
|
|
12994
|
+
aiReadiness = { score: aiScore, level: aiLevel, checkCount: aiChecks.length };
|
|
12995
|
+
}
|
|
12996
|
+
return { score, level, checks, ...aiReadiness ? { aiReadiness } : {} };
|
|
11752
12997
|
}
|
|
11753
12998
|
|
|
11754
12999
|
exports.ACTION_VERBS = ACTION_VERBS;
|