@nocode-factory/sanity-kit 2.42.0 → 2.43.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/bin/ncf-kit.mjs +15 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +101 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/tools/pages/PagesTool.tsx +3 -0
- package/src/ui/UrlCheckNotice.tsx +92 -0
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {UrlCheckNotice} from '../../ui/UrlCheckNotice'
|
|
1
2
|
import {useCallback, useMemo, useState} from 'react'
|
|
2
3
|
import {Box, Card, Flex, Select, Spinner, Stack, Text} from '@sanity/ui'
|
|
3
4
|
import {useRouter} from 'sanity/router'
|
|
@@ -168,6 +169,8 @@ export function PagesTool() {
|
|
|
168
169
|
|
|
169
170
|
return (
|
|
170
171
|
<Stack gap={4}>
|
|
172
|
+
{/* Règle d'or : pages de la sitemap en 301 / 404, redirections à corriger. */}
|
|
173
|
+
<UrlCheckNotice previewUrl={config.previewUrl} />
|
|
171
174
|
<Flex align="flex-end" justify="space-between" gap={4} wrap="wrap">
|
|
172
175
|
<ViewTabs view={view} onChange={setView} />
|
|
173
176
|
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {useCallback, useEffect, useState} from 'react'
|
|
2
|
+
import {Box, Button, Card, Flex, Stack, Text} from '@sanity/ui'
|
|
3
|
+
|
|
4
|
+
type Problem = {url: string; status: number | string; location?: string; issue: string}
|
|
5
|
+
type Report = {checkedAt: string; sitemap: {total: number; problems: Problem[]}; redirects: {total: number; problems: Problem[]}}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* RÈGLE D'OR : URL finales. Le site (starter : /api/url-check) appelle chaque URL de
|
|
9
|
+
* sa sitemap et chaque redirection du Studio ; ce bandeau prévient l'équipe quand
|
|
10
|
+
* une page de la sitemap répond 301 / 308 / 404, ou qu'une redirection fait deux
|
|
11
|
+
* sauts / mène à une 404 (contenu publié, renommé ou supprimé depuis le dernier
|
|
12
|
+
* déploiement). Rien n'est affiché si tout est bon ou si le site n'a pas ce contrôle.
|
|
13
|
+
*/
|
|
14
|
+
export function UrlCheckNotice({previewUrl}: {previewUrl: string | null}) {
|
|
15
|
+
const [report, setReport] = useState<Report | null>(null)
|
|
16
|
+
const [busy, setBusy] = useState(false)
|
|
17
|
+
const [open, setOpen] = useState(false)
|
|
18
|
+
|
|
19
|
+
const load = useCallback(
|
|
20
|
+
async (fresh: boolean) => {
|
|
21
|
+
if (!previewUrl) return
|
|
22
|
+
setBusy(true)
|
|
23
|
+
try {
|
|
24
|
+
const res = await fetch(`${previewUrl.replace(/\/$/, '')}/api/url-check${fresh ? '?fresh' : ''}`)
|
|
25
|
+
if (res.ok) setReport((await res.json()) as Report)
|
|
26
|
+
} catch {
|
|
27
|
+
/* site sans contrôle ou injoignable : rien à afficher */
|
|
28
|
+
} finally {
|
|
29
|
+
setBusy(false)
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
[previewUrl],
|
|
33
|
+
)
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
void load(false)
|
|
36
|
+
}, [load])
|
|
37
|
+
|
|
38
|
+
const sitemap = report?.sitemap.problems ?? []
|
|
39
|
+
const redirects = report?.redirects.problems ?? []
|
|
40
|
+
if (!report || (!sitemap.length && !redirects.length)) return null
|
|
41
|
+
|
|
42
|
+
const line = (p: Problem) => `${p.url} : ${p.issue}${p.location && !p.issue.includes(p.location) ? ` → ${p.location}` : ''}`
|
|
43
|
+
const summary = [
|
|
44
|
+
sitemap.length ? `${sitemap.length} sitemap page${sitemap.length > 1 ? 's' : ''} not final (301 / 404)` : '',
|
|
45
|
+
redirects.length ? `${redirects.length} redirect${redirects.length > 1 ? 's' : ''} to fix` : '',
|
|
46
|
+
]
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.join(' · ')
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Card tone={sitemap.length ? 'critical' : 'caution'} padding={3} radius={2} border>
|
|
52
|
+
<Stack gap={3}>
|
|
53
|
+
<Flex align="center" gap={3} wrap="wrap">
|
|
54
|
+
<Box flex={1}>
|
|
55
|
+
<Text size={1} weight="semibold">
|
|
56
|
+
URLs: {summary}
|
|
57
|
+
</Text>
|
|
58
|
+
</Box>
|
|
59
|
+
<Button mode="ghost" fontSize={1} padding={2} text={open ? 'Hide' : 'Details'} onClick={() => setOpen(!open)} />
|
|
60
|
+
<Button mode="ghost" fontSize={1} padding={2} text={busy ? 'Checking…' : 'Check again'} disabled={busy} onClick={() => void load(true)} />
|
|
61
|
+
</Flex>
|
|
62
|
+
{open && (
|
|
63
|
+
<Stack gap={2}>
|
|
64
|
+
{sitemap.length > 0 && (
|
|
65
|
+
<Text size={1} muted>
|
|
66
|
+
Google only indexes final URLs: each sitemap page must answer 200, without redirect.
|
|
67
|
+
</Text>
|
|
68
|
+
)}
|
|
69
|
+
{sitemap.slice(0, 20).map((p) => (
|
|
70
|
+
<Text key={`s-${p.url}`} size={1} style={{fontFamily: 'monospace'}}>
|
|
71
|
+
{line(p)}
|
|
72
|
+
</Text>
|
|
73
|
+
))}
|
|
74
|
+
{redirects.length > 0 && (
|
|
75
|
+
<Text size={1} muted>
|
|
76
|
+
Redirects (Redirects in the Studio): each one must lead in ONE step to a live page.
|
|
77
|
+
</Text>
|
|
78
|
+
)}
|
|
79
|
+
{redirects.slice(0, 20).map((p) => (
|
|
80
|
+
<Text key={`r-${p.url}`} size={1} style={{fontFamily: 'monospace'}}>
|
|
81
|
+
{line(p)}
|
|
82
|
+
</Text>
|
|
83
|
+
))}
|
|
84
|
+
<Text size={0} muted>
|
|
85
|
+
Checked {new Date(report.checkedAt).toLocaleString()}.
|
|
86
|
+
</Text>
|
|
87
|
+
</Stack>
|
|
88
|
+
)}
|
|
89
|
+
</Stack>
|
|
90
|
+
</Card>
|
|
91
|
+
)
|
|
92
|
+
}
|
package/src/version.ts
CHANGED