@nocode-factory/sanity-kit 2.42.1 → 2.44.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 +1 -0
- package/bin/ncf-kit.mjs +21 -1
- package/dist/{fixCrossLanguageReferences-j1qDJWic.d.ts → fixCrossLanguageReferences-CFZax-Nb.d.ts} +39 -2
- package/dist/{fixCrossLanguageReferences-DbkdPSMH.js → fixCrossLanguageReferences-DQ6bDuSZ.js} +81 -2
- package/dist/fixCrossLanguageReferences-DQ6bDuSZ.js.map +1 -0
- package/dist/index.d.ts +3 -40
- package/dist/index.js +102 -82
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +69 -2
- package/dist/schema.js +103 -2
- package/dist/schema.js.map +1 -1
- package/package.json +1 -1
- package/src/schema/index.ts +12 -0
- package/src/schema/redirects.ts +205 -0
- package/src/tools/pages/PagesTool.tsx +3 -0
- package/src/ui/UrlCheckNotice.tsx +92 -0
- package/src/version.ts +1 -1
- package/dist/fixCrossLanguageReferences-DbkdPSMH.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { A as DEFAULT_PAGE_BUILDER_FIELD, C as toUrl, D as DEFAULT_COMPONENT_PREVIEW, E as DEFAULT_BOARD_TAGS, M as DEFAULT_TITLE_FIELD, O as DEFAULT_I18N, S as toPath, T as resolveConfig, _ as redirectMapOf, a as componentDefaultsMainDocument, b as parentPath, c as defineComponentDefaults, d as syncTranslationRedirects, f as translationRedirectId, i as DEFAULT_COMPONENT_DEFAULTS_TYPE, j as DEFAULT_SLUG_FIELD, k as DEFAULT_INTERNAL_FIELDS, l as requiredUnlessDefault, m as finalPath, n as withSameLanguageReferences, o as componentDefaultsMainDocuments, p as translationRedirectOptions, r as pageTypesFromSiteRoutes, s as defaultsFieldName, t as fixCrossLanguageReferences, u as requiredUnlessDefaultFor, v as depth, w as normalizePath, x as segments, y as pageTypeFor } from "./fixCrossLanguageReferences-DQ6bDuSZ.js";
|
|
2
2
|
import { createContext, createElement, forwardRef, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
3
3
|
import { ToolLink, defineField, definePlugin, defineType, pathToString, set, unset, useClient, useCurrentUser, useFormValue, usePerspective, useSchema, useSetPerspective, useUser, useWorkspace } from "sanity";
|
|
4
4
|
import { ClockIcon } from "@sanity/icons/Clock";
|
|
@@ -1260,7 +1260,7 @@ function explainGrantError(error) {
|
|
|
1260
1260
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1261
1261
|
* le vérifie.
|
|
1262
1262
|
*/
|
|
1263
|
-
const KIT_VERSION = "2.
|
|
1263
|
+
const KIT_VERSION = "2.44.0";
|
|
1264
1264
|
/**
|
|
1265
1265
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1266
1266
|
*
|
|
@@ -1603,7 +1603,7 @@ function useKitUpdate() {
|
|
|
1603
1603
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1604
1604
|
}).catch(() => {}), () => controller.abort();
|
|
1605
1605
|
}, []);
|
|
1606
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1606
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.44.0") > 0);
|
|
1607
1607
|
return {
|
|
1608
1608
|
current: KIT_VERSION,
|
|
1609
1609
|
latest,
|
|
@@ -1975,6 +1975,104 @@ function createPreviewLauncher(config, issues) {
|
|
|
1975
1975
|
};
|
|
1976
1976
|
}
|
|
1977
1977
|
/**
|
|
1978
|
+
* RÈGLE D'OR : URL finales. Le site (starter : /api/url-check) appelle chaque URL de
|
|
1979
|
+
* sa sitemap et chaque redirection du Studio ; ce bandeau prévient l'équipe quand
|
|
1980
|
+
* une page de la sitemap répond 301 / 308 / 404, ou qu'une redirection fait deux
|
|
1981
|
+
* sauts / mène à une 404 (contenu publié, renommé ou supprimé depuis le dernier
|
|
1982
|
+
* déploiement). Rien n'est affiché si tout est bon ou si le site n'a pas ce contrôle.
|
|
1983
|
+
*/
|
|
1984
|
+
function UrlCheckNotice({ previewUrl }) {
|
|
1985
|
+
let [report, setReport] = useState(null), [busy, setBusy] = useState(!1), [open, setOpen] = useState(!1), load = useCallback(async (fresh) => {
|
|
1986
|
+
if (previewUrl) {
|
|
1987
|
+
setBusy(!0);
|
|
1988
|
+
try {
|
|
1989
|
+
let res = await fetch(`${previewUrl.replace(/\/$/, "")}/api/url-check${fresh ? "?fresh" : ""}`);
|
|
1990
|
+
res.ok && setReport(await res.json());
|
|
1991
|
+
} catch {} finally {
|
|
1992
|
+
setBusy(!1);
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
}, [previewUrl]);
|
|
1996
|
+
useEffect(() => {
|
|
1997
|
+
load(!1);
|
|
1998
|
+
}, [load]);
|
|
1999
|
+
let sitemap = report?.sitemap.problems ?? [], redirects = report?.redirects.problems ?? [];
|
|
2000
|
+
if (!report || !sitemap.length && !redirects.length) return null;
|
|
2001
|
+
let line = (p) => `${p.url} : ${p.issue}${p.location && !p.issue.includes(p.location) ? ` → ${p.location}` : ""}`, summary = [sitemap.length ? `${sitemap.length} sitemap page${sitemap.length > 1 ? "s" : ""} not final (301 / 404)` : "", redirects.length ? `${redirects.length} redirect${redirects.length > 1 ? "s" : ""} to fix` : ""].filter(Boolean).join(" · ");
|
|
2002
|
+
return /* @__PURE__ */ jsx(Card, {
|
|
2003
|
+
tone: sitemap.length ? "critical" : "caution",
|
|
2004
|
+
padding: 3,
|
|
2005
|
+
radius: 2,
|
|
2006
|
+
border: !0,
|
|
2007
|
+
children: /* @__PURE__ */ jsxs(Stack, {
|
|
2008
|
+
gap: 3,
|
|
2009
|
+
children: [/* @__PURE__ */ jsxs(Flex, {
|
|
2010
|
+
align: "center",
|
|
2011
|
+
gap: 3,
|
|
2012
|
+
wrap: "wrap",
|
|
2013
|
+
children: [
|
|
2014
|
+
/* @__PURE__ */ jsx(Box, {
|
|
2015
|
+
flex: 1,
|
|
2016
|
+
children: /* @__PURE__ */ jsxs(Text, {
|
|
2017
|
+
size: 1,
|
|
2018
|
+
weight: "semibold",
|
|
2019
|
+
children: ["URLs: ", summary]
|
|
2020
|
+
})
|
|
2021
|
+
}),
|
|
2022
|
+
/* @__PURE__ */ jsx(Button, {
|
|
2023
|
+
mode: "ghost",
|
|
2024
|
+
fontSize: 1,
|
|
2025
|
+
padding: 2,
|
|
2026
|
+
text: open ? "Hide" : "Details",
|
|
2027
|
+
onClick: () => setOpen(!open)
|
|
2028
|
+
}),
|
|
2029
|
+
/* @__PURE__ */ jsx(Button, {
|
|
2030
|
+
mode: "ghost",
|
|
2031
|
+
fontSize: 1,
|
|
2032
|
+
padding: 2,
|
|
2033
|
+
text: busy ? "Checking…" : "Check again",
|
|
2034
|
+
disabled: busy,
|
|
2035
|
+
onClick: () => void load(!0)
|
|
2036
|
+
})
|
|
2037
|
+
]
|
|
2038
|
+
}), open && /* @__PURE__ */ jsxs(Stack, {
|
|
2039
|
+
gap: 2,
|
|
2040
|
+
children: [
|
|
2041
|
+
sitemap.length > 0 && /* @__PURE__ */ jsx(Text, {
|
|
2042
|
+
size: 1,
|
|
2043
|
+
muted: !0,
|
|
2044
|
+
children: "Google only indexes final URLs: each sitemap page must answer 200, without redirect."
|
|
2045
|
+
}),
|
|
2046
|
+
sitemap.slice(0, 20).map((p) => /* @__PURE__ */ jsx(Text, {
|
|
2047
|
+
size: 1,
|
|
2048
|
+
style: { fontFamily: "monospace" },
|
|
2049
|
+
children: line(p)
|
|
2050
|
+
}, `s-${p.url}`)),
|
|
2051
|
+
redirects.length > 0 && /* @__PURE__ */ jsx(Text, {
|
|
2052
|
+
size: 1,
|
|
2053
|
+
muted: !0,
|
|
2054
|
+
children: "Redirects (Redirects in the Studio): each one must lead in ONE step to a live page."
|
|
2055
|
+
}),
|
|
2056
|
+
redirects.slice(0, 20).map((p) => /* @__PURE__ */ jsx(Text, {
|
|
2057
|
+
size: 1,
|
|
2058
|
+
style: { fontFamily: "monospace" },
|
|
2059
|
+
children: line(p)
|
|
2060
|
+
}, `r-${p.url}`)),
|
|
2061
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
2062
|
+
size: 0,
|
|
2063
|
+
muted: !0,
|
|
2064
|
+
children: [
|
|
2065
|
+
"Checked ",
|
|
2066
|
+
new Date(report.checkedAt).toLocaleString(),
|
|
2067
|
+
"."
|
|
2068
|
+
]
|
|
2069
|
+
})
|
|
2070
|
+
]
|
|
2071
|
+
})]
|
|
2072
|
+
})
|
|
2073
|
+
});
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
1978
2076
|
* Colonnes de gestion interne effectives.
|
|
1979
2077
|
*
|
|
1980
2078
|
* Tant que personne n'y a touché, la configuration fournit le jeu de départ.
|
|
@@ -2048,51 +2146,6 @@ function buildContentsQuery(config, limit) {
|
|
|
2048
2146
|
"}"
|
|
2049
2147
|
].join("\n");
|
|
2050
2148
|
}
|
|
2051
|
-
/** Clé de comparaison des redirections (comme le site) : minuscules, sans « / » final, sans ? ni #. */
|
|
2052
|
-
const redirectKey = (path) => {
|
|
2053
|
-
let clean = (path.trim().split(/[?#]/)[0] ?? "").toLowerCase();
|
|
2054
|
-
return clean.length > 1 ? clean.replace(/\/+$/, "") : clean;
|
|
2055
|
-
};
|
|
2056
|
-
function redirectMapOf(rows) {
|
|
2057
|
-
let map = /* @__PURE__ */ new Map();
|
|
2058
|
-
for (let r of rows) {
|
|
2059
|
-
if (!r.from?.startsWith("/") || !r.to) continue;
|
|
2060
|
-
let key = redirectKey(r.from);
|
|
2061
|
-
key !== redirectKey(r.to) && !map.has(key) && map.set(key, r.to.trim());
|
|
2062
|
-
}
|
|
2063
|
-
return map;
|
|
2064
|
-
}
|
|
2065
|
-
/** Destination finale d'une adresse (chaîne de redirections suivie, boucles ignorées). */
|
|
2066
|
-
function followRedirects(path, redirects) {
|
|
2067
|
-
if (!redirects?.size) return path;
|
|
2068
|
-
let current = path, seen = /* @__PURE__ */ new Set();
|
|
2069
|
-
for (let hop = 0; hop < 5; hop++) {
|
|
2070
|
-
let next = redirects.get(redirectKey(current));
|
|
2071
|
-
if (!next || seen.has(next)) break;
|
|
2072
|
-
seen.add(next), current = next;
|
|
2073
|
-
}
|
|
2074
|
-
return current;
|
|
2075
|
-
}
|
|
2076
|
-
/**
|
|
2077
|
-
* URL FINALE d'une page (celle qui répond 200, sans redirection) : adresse réelle
|
|
2078
|
-
* d'une page codée (registre `siteRoutes`, dossier de la langue), sinon dossier et
|
|
2079
|
-
* slug de la langue ; puis destination si l'adresse est le départ d'une redirection
|
|
2080
|
-
* du Studio. Affichée partout dans le kit (onglet Pages, board, Presentation, slug).
|
|
2081
|
-
*/
|
|
2082
|
-
function finalPath(input, pageType, config, redirects) {
|
|
2083
|
-
if (!pageType) return null;
|
|
2084
|
-
let coded = !pageType.path && !pageType.pathPrefix && !pageType.localizedPrefixes && input.slug ? config.codedPages.find((c) => c.pageSlug === input.slug) : void 0, path = toPath(coded ? {
|
|
2085
|
-
path: input.locale && coded.localized?.[input.locale] || coded.path,
|
|
2086
|
-
locale: input.locale
|
|
2087
|
-
} : {
|
|
2088
|
-
slug: input.slug,
|
|
2089
|
-
path: pageType.path,
|
|
2090
|
-
pathPrefix: pageType.pathPrefix,
|
|
2091
|
-
localizedPrefixes: pageType.localizedPrefixes,
|
|
2092
|
-
locale: input.locale
|
|
2093
|
-
}, config.i18n);
|
|
2094
|
-
return path === null ? null : followRedirects(path, redirects);
|
|
2095
|
-
}
|
|
2096
2149
|
/**
|
|
2097
2150
|
* Met une valeur du document en forme pour une cellule.
|
|
2098
2151
|
*
|
|
@@ -6115,6 +6168,7 @@ function PagesTool() {
|
|
|
6115
6168
|
return /* @__PURE__ */ jsxs(Stack, {
|
|
6116
6169
|
gap: 4,
|
|
6117
6170
|
children: [
|
|
6171
|
+
/* @__PURE__ */ jsx(UrlCheckNotice, { previewUrl: config.previewUrl }),
|
|
6118
6172
|
/* @__PURE__ */ jsxs(Flex, {
|
|
6119
6173
|
align: "flex-end",
|
|
6120
6174
|
justify: "space-between",
|
|
@@ -9501,40 +9555,6 @@ function withTranslationRedirects(Publish, config) {
|
|
|
9501
9555
|
};
|
|
9502
9556
|
return Wrapped;
|
|
9503
9557
|
}
|
|
9504
|
-
/**
|
|
9505
|
-
* `pageTypes` déduits du registre du starter, pour ne pas redire au kit ce que
|
|
9506
|
-
* le site sait déjà : l'accueil (chemin fixe `/`) et chaque collection avec
|
|
9507
|
-
* son préfixe d'URL (`/blog`, `/produits`, ou la racine).
|
|
9508
|
-
*
|
|
9509
|
-
* ```ts
|
|
9510
|
-
* import routes from '../web/app/lib/site-routes.json'
|
|
9511
|
-
* ncfKit({pageTypes: pageTypesFromSiteRoutes(routes)})
|
|
9512
|
-
* ```
|
|
9513
|
-
*
|
|
9514
|
-
* `homePageType` : nom du type de l'accueil dans le schéma (le registre ne le
|
|
9515
|
-
* porte pas). Les pages codées du registre (`pageSlug`) ne sont pas des types :
|
|
9516
|
-
* elles n'apparaissent pas ici.
|
|
9517
|
-
*/
|
|
9518
|
-
function pageTypesFromSiteRoutes(routes, options = {}) {
|
|
9519
|
-
let homePageType = options.homePageType === void 0 ? "homePage" : options.homePageType, out = [];
|
|
9520
|
-
homePageType && routes.fixed?.some((r) => r.homePage) && out.push({
|
|
9521
|
-
type: homePageType,
|
|
9522
|
-
path: "/"
|
|
9523
|
-
});
|
|
9524
|
-
for (let collection of routes.collections ?? []) {
|
|
9525
|
-
if (!collection.type) continue;
|
|
9526
|
-
let prefix = (collection.pathPrefix ?? "").trim(), localized = collection.localized && Object.keys(collection.localized).length ? { localizedPrefixes: collection.localized } : {};
|
|
9527
|
-
out.push(prefix ? {
|
|
9528
|
-
type: collection.type,
|
|
9529
|
-
pathPrefix: prefix,
|
|
9530
|
-
...localized
|
|
9531
|
-
} : {
|
|
9532
|
-
type: collection.type,
|
|
9533
|
-
...localized
|
|
9534
|
-
});
|
|
9535
|
-
}
|
|
9536
|
-
return out;
|
|
9537
|
-
}
|
|
9538
9558
|
/** Nom de l'onglet « Plus » dans la barre du Studio. */
|
|
9539
9559
|
const NCF_MORE_TOOL = "ncf-more", DEFAULT_MORE_TOOLS = ["vision", "releases"];
|
|
9540
9560
|
/**
|