@terrafirmagreg-team/kit 1.2.10 → 1.2.11
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/package.json +6 -6
- package/src/components/layouts/layout.tsx +8 -5
- package/src/components/page-features.tsx +30 -0
- package/src/components/views/not-found.tsx +74 -8
- package/src/components/views/unavailable.tsx +13 -4
- package/src/lib/config.ts +1 -0
- package/src/lib/datasets.ts +68 -31
- package/src/lib/urls.ts +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrafirmagreg-team/kit",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Fumadocs content engine",
|
|
6
6
|
"license": "LGPL-3.0-only",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@base-ui/react": "^1.9.0",
|
|
26
26
|
"@icons-pack/react-simple-icons": "13.15.1",
|
|
27
|
-
"@terrafirmagreg-team/data": "^1.2.
|
|
28
|
-
"@terrafirmagreg-team/mdx": "^1.2.
|
|
29
|
-
"@terrafirmagreg-team/sites": "^1.2.
|
|
30
|
-
"@terrafirmagreg-team/translate": "^1.2.
|
|
31
|
-
"@terrafirmagreg-team/ui": "^1.2.
|
|
27
|
+
"@terrafirmagreg-team/data": "^1.2.3",
|
|
28
|
+
"@terrafirmagreg-team/mdx": "^1.2.5",
|
|
29
|
+
"@terrafirmagreg-team/sites": "^1.2.2",
|
|
30
|
+
"@terrafirmagreg-team/translate": "^1.2.7",
|
|
31
|
+
"@terrafirmagreg-team/ui": "^1.2.8",
|
|
32
32
|
"fumadocs-core": "16.17.10",
|
|
33
33
|
"lucide-react": "^1.63.0",
|
|
34
34
|
"server-only": "^0.0.1",
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
} from '@terrafirmagreg-team/ui/components/blocks/nav/site-menu';
|
|
22
22
|
import { buttonVariants } from '@terrafirmagreg-team/ui/components/ui/button';
|
|
23
23
|
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
24
|
+
import { skeletonTree } from '@terrafirmagreg-team/ui/lib/tree';
|
|
24
25
|
import { Globe } from 'lucide-react';
|
|
25
26
|
import {
|
|
26
27
|
SiCurseforge,
|
|
@@ -92,7 +93,7 @@ export function Layout({
|
|
|
92
93
|
const pinned = current ? current.version : undefined;
|
|
93
94
|
const meta = sectionDatasets.find((item) => item.id === baseId);
|
|
94
95
|
const failedDatasets = useFailedDatasets();
|
|
95
|
-
const
|
|
96
|
+
const datasetFailed = baseId !== undefined && failedDatasets.includes(baseId);
|
|
96
97
|
useDatasetAccent(meta?.accent);
|
|
97
98
|
const nav = useNavOptions({ section, catalog });
|
|
98
99
|
const pathname = usePathname();
|
|
@@ -110,12 +111,14 @@ export function Layout({
|
|
|
110
111
|
$id: `${section}:empty`,
|
|
111
112
|
};
|
|
112
113
|
const tree = useTree(serverTree);
|
|
114
|
+
const effectiveTree =
|
|
115
|
+
datasetFailed && !tree.children.length ? skeletonTree() : tree;
|
|
113
116
|
const pinnedTree = useMemo(
|
|
114
117
|
() =>
|
|
115
118
|
pinned && baseId
|
|
116
|
-
? pinTreeDataset(
|
|
117
|
-
:
|
|
118
|
-
[
|
|
119
|
+
? pinTreeDataset(effectiveTree, section, baseId, pinned)
|
|
120
|
+
: effectiveTree,
|
|
121
|
+
[effectiveTree, section, baseId, pinned],
|
|
119
122
|
);
|
|
120
123
|
const locales = meta?.languages ? localeItems(meta.languages) : undefined;
|
|
121
124
|
const links = baseId
|
|
@@ -177,7 +180,7 @@ export function Layout({
|
|
|
177
180
|
<LeftSidebarSearch />
|
|
178
181
|
<Switcher {...nav.section} />
|
|
179
182
|
<Switcher {...nav.dataset} />
|
|
180
|
-
{Feature
|
|
183
|
+
{Feature ? (
|
|
181
184
|
<>
|
|
182
185
|
<LeftSidebarSeparator />
|
|
183
186
|
<Feature />
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SectionFeatures,
|
|
3
|
+
SectionPageContext,
|
|
4
|
+
} from '../types/features.ts';
|
|
5
|
+
import type { ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
export function pageFeatureNodes(
|
|
8
|
+
ctx: SectionPageContext,
|
|
9
|
+
features: SectionFeatures,
|
|
10
|
+
body: ReactNode,
|
|
11
|
+
): {
|
|
12
|
+
actionsRight: ReactNode;
|
|
13
|
+
body: ReactNode;
|
|
14
|
+
footer: ReactNode;
|
|
15
|
+
comments: ReactNode;
|
|
16
|
+
} {
|
|
17
|
+
const wrapped = features.wrapBody ? (
|
|
18
|
+
features.wrapBody(body, ctx)
|
|
19
|
+
) : (
|
|
20
|
+
<div data-md-root className="contents">
|
|
21
|
+
{body}
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
return {
|
|
25
|
+
actionsRight: features.actionsRight?.(ctx),
|
|
26
|
+
body: wrapped,
|
|
27
|
+
footer: features.footer?.(ctx),
|
|
28
|
+
comments: features.comments?.(ctx),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useEffect, useRef } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { sectionUrl } from '@terrafirmagreg-team/sites/location';
|
|
3
|
+
import { usePathname, useRouter } from 'next/navigation';
|
|
4
|
+
import { isSectionKey, sectionUrl } from '@terrafirmagreg-team/sites/location';
|
|
6
5
|
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
7
6
|
import { LangLink } from '@terrafirmagreg-team/ui/components/blocks/lang/link';
|
|
8
7
|
import { EmptyState } from '@terrafirmagreg-team/ui/components/blocks/page/empty-state';
|
|
@@ -10,6 +9,7 @@ import { buttonVariants } from '@terrafirmagreg-team/ui/components/ui/button';
|
|
|
10
9
|
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
11
10
|
import { requestDumpRetry } from '@terrafirmagreg-team/data/lib/dump-status';
|
|
12
11
|
import { useDumpStatus } from '@terrafirmagreg-team/kit/hooks/use-dump-status';
|
|
12
|
+
import { useSectionCatalog } from '@terrafirmagreg-team/kit/hooks/use-catalog';
|
|
13
13
|
import type { SectionDataset, SectionKey } from '@terrafirmagreg-team/kit/types';
|
|
14
14
|
|
|
15
15
|
export function SectionNotFound({
|
|
@@ -39,7 +39,7 @@ export function SectionNotFound({
|
|
|
39
39
|
|
|
40
40
|
if (!datasets.length)
|
|
41
41
|
return (
|
|
42
|
-
<div className="flex flex-col items-center gap-3
|
|
42
|
+
<div className="mx-2 flex min-w-0 flex-1 flex-col items-center justify-center gap-3 bg-background [grid-area:main] md:my-2 md:overflow-clip md:rounded-2xl md:border md:shadow-sm">
|
|
43
43
|
<EmptyState variant="missing">
|
|
44
44
|
{t('Section data is temporarily unavailable. Try again later.', {
|
|
45
45
|
note: 'kit.section_unavailable',
|
|
@@ -55,13 +55,27 @@ export function SectionNotFound({
|
|
|
55
55
|
</div>
|
|
56
56
|
);
|
|
57
57
|
return (
|
|
58
|
-
<div className="flex flex-col items-center gap-
|
|
59
|
-
<
|
|
60
|
-
|
|
58
|
+
<div className="mx-2 flex min-w-0 flex-1 flex-col items-center justify-center gap-6 bg-background [grid-area:main] md:my-2 md:overflow-clip md:rounded-2xl md:border md:shadow-sm">
|
|
59
|
+
<div className="flex flex-col items-center gap-2 text-center">
|
|
60
|
+
<span
|
|
61
|
+
aria-hidden
|
|
62
|
+
className="select-none text-6xl leading-none font-semibold tracking-tighter text-muted-foreground/25"
|
|
63
|
+
>
|
|
64
|
+
404
|
|
65
|
+
</span>
|
|
66
|
+
<p className="font-medium text-foreground">
|
|
67
|
+
{t('Page not found', { note: 'ui.not_found' })}
|
|
68
|
+
</p>
|
|
69
|
+
<p className="max-w-sm text-sm text-balance text-muted-foreground">
|
|
70
|
+
{t("The page you're looking for doesn't exist or was moved.", {
|
|
71
|
+
note: 'ui.not_found_description',
|
|
72
|
+
})}
|
|
73
|
+
</p>
|
|
74
|
+
</div>
|
|
61
75
|
<LangLink
|
|
62
76
|
href={sectionUrl(section, datasets[0].id)}
|
|
63
77
|
className={cn(
|
|
64
|
-
buttonVariants({ variant: 'outline', size: '
|
|
78
|
+
buttonVariants({ variant: 'outline', size: 'sm' }),
|
|
65
79
|
'no-underline',
|
|
66
80
|
)}
|
|
67
81
|
>
|
|
@@ -70,3 +84,55 @@ export function SectionNotFound({
|
|
|
70
84
|
</div>
|
|
71
85
|
);
|
|
72
86
|
}
|
|
87
|
+
|
|
88
|
+
export function RootNotFound() {
|
|
89
|
+
const pathname = usePathname();
|
|
90
|
+
const catalog = useSectionCatalog();
|
|
91
|
+
const t = useTranslations();
|
|
92
|
+
const parts = pathname.split('/').filter(Boolean);
|
|
93
|
+
const section = isSectionKey(parts[0]) ? parts[0] : undefined;
|
|
94
|
+
const datasets = section ? catalog[section] : undefined;
|
|
95
|
+
const known = datasets?.some((dataset) => dataset.id === parts[1]);
|
|
96
|
+
const href =
|
|
97
|
+
section && datasets?.length
|
|
98
|
+
? `/${section}/${known ? parts[1] : datasets[0].id}`
|
|
99
|
+
: '/';
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<main className="flex min-h-dvh flex-col items-center justify-center gap-8 p-8">
|
|
103
|
+
<div className="flex flex-col items-center gap-3 text-center">
|
|
104
|
+
<span
|
|
105
|
+
aria-hidden
|
|
106
|
+
className="select-none bg-gradient-to-b from-muted-foreground/40 to-muted-foreground/10 bg-clip-text text-[8rem] leading-none font-semibold tracking-tighter text-transparent"
|
|
107
|
+
>
|
|
108
|
+
404
|
|
109
|
+
</span>
|
|
110
|
+
<h1 className="text-xl font-semibold text-foreground">
|
|
111
|
+
{t('Page not found', { note: 'ui.not_found' })}
|
|
112
|
+
</h1>
|
|
113
|
+
<p className="max-w-sm text-sm text-balance text-muted-foreground">
|
|
114
|
+
{t("The page you're looking for doesn't exist or was moved.", {
|
|
115
|
+
note: 'ui.not_found_description',
|
|
116
|
+
})}
|
|
117
|
+
</p>
|
|
118
|
+
</div>
|
|
119
|
+
<div className="flex items-center gap-2">
|
|
120
|
+
<LangLink
|
|
121
|
+
href={href}
|
|
122
|
+
className={cn(buttonVariants({ size: 'sm' }), 'no-underline')}
|
|
123
|
+
>
|
|
124
|
+
{t('Back', { note: 'ui.back' })}
|
|
125
|
+
</LangLink>
|
|
126
|
+
<LangLink
|
|
127
|
+
href="/"
|
|
128
|
+
className={cn(
|
|
129
|
+
buttonVariants({ variant: 'ghost', size: 'sm' }),
|
|
130
|
+
'no-underline',
|
|
131
|
+
)}
|
|
132
|
+
>
|
|
133
|
+
{t('Go home', { note: 'ui.go_home' })}
|
|
134
|
+
</LangLink>
|
|
135
|
+
</div>
|
|
136
|
+
</main>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import type { ReactNode } from 'react';
|
|
4
|
+
import { CloudOff } from 'lucide-react';
|
|
4
5
|
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
5
6
|
import { requestDumpRetry } from '@terrafirmagreg-team/data/lib/dump-status';
|
|
6
|
-
import { EmptyState } from '@terrafirmagreg-team/ui/components/blocks/page/empty-state';
|
|
7
7
|
import { buttonVariants } from '@terrafirmagreg-team/ui/components/ui/button';
|
|
8
8
|
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
9
9
|
|
|
10
10
|
export function DumpUnavailable({ children }: { children?: ReactNode }) {
|
|
11
11
|
const t = useTranslations();
|
|
12
12
|
return (
|
|
13
|
-
<div className="flex flex-col items-center gap-
|
|
14
|
-
<
|
|
13
|
+
<div className="pointer-events-auto flex max-w-xs flex-col items-center gap-2.5 rounded-lg border border-border bg-popover px-5 py-4 text-center shadow-lg">
|
|
14
|
+
<CloudOff className="size-5 text-muted-foreground" />
|
|
15
|
+
<p className="text-sm text-muted-foreground">
|
|
15
16
|
{children ??
|
|
16
17
|
t('Section data is temporarily unavailable. Try again later.', {
|
|
17
18
|
note: 'kit.section_unavailable',
|
|
18
19
|
})}
|
|
19
|
-
</
|
|
20
|
+
</p>
|
|
20
21
|
<button
|
|
21
22
|
type="button"
|
|
22
23
|
onClick={requestDumpRetry}
|
|
@@ -27,3 +28,11 @@ export function DumpUnavailable({ children }: { children?: ReactNode }) {
|
|
|
27
28
|
</div>
|
|
28
29
|
);
|
|
29
30
|
}
|
|
31
|
+
|
|
32
|
+
export function DumpUnavailableOverlay({ children }: { children?: ReactNode }) {
|
|
33
|
+
return (
|
|
34
|
+
<div className="pointer-events-none absolute inset-0 z-20 flex items-center justify-center p-6">
|
|
35
|
+
{children ?? <DumpUnavailable />}
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
}
|
package/src/lib/config.ts
CHANGED
package/src/lib/datasets.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { sectionConfig } from './config';
|
|
|
4
4
|
import { sections } from './sources';
|
|
5
5
|
import { datasetId } from './tree';
|
|
6
6
|
import { createAsyncCache } from '@terrafirmagreg-team/data/lib/async-cache';
|
|
7
|
+
import { dumpStatusSnapshot } from '@terrafirmagreg-team/data/lib/dump-status';
|
|
7
8
|
import { loadLocaleRegistry, sortLangCodes } from '@terrafirmagreg-team/translate/server';
|
|
8
9
|
import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
9
10
|
import { sectionTabs } from '@terrafirmagreg-team/sites/sections';
|
|
@@ -79,6 +80,30 @@ async function datasetMeta(
|
|
|
79
80
|
return meta ? metaFields(meta) : {};
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
async function sectionDatasetMeta(
|
|
84
|
+
section: SectionKey,
|
|
85
|
+
id: string,
|
|
86
|
+
): Promise<Omit<SectionDataset, 'id' | 'languages'>> {
|
|
87
|
+
const meta = await datasetMeta(section, id);
|
|
88
|
+
return Object.values(meta).some((value) => value !== undefined)
|
|
89
|
+
? meta
|
|
90
|
+
: datasetMeta('docs', id);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const lastGoodDatasets = new Map<SectionKey, Map<string, SectionDataset>>();
|
|
94
|
+
|
|
95
|
+
function rememberDataset(section: SectionKey, row: SectionDataset) {
|
|
96
|
+
let good = lastGoodDatasets.get(section);
|
|
97
|
+
if (!good) lastGoodDatasets.set(section, (good = new Map()));
|
|
98
|
+
good.set(row.id, row);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function datasetMembership(section: SectionKey, id: string): boolean {
|
|
102
|
+
const declared = sectionConfig().datasetConfig[id]?.sections;
|
|
103
|
+
if (declared) return declared.includes(section);
|
|
104
|
+
return lastGoodDatasets.get(section)?.has(id) === true;
|
|
105
|
+
}
|
|
106
|
+
|
|
82
107
|
function metaFields(
|
|
83
108
|
meta: Record<string, unknown>,
|
|
84
109
|
): Omit<SectionDataset, 'id' | 'languages'> {
|
|
@@ -144,47 +169,59 @@ async function dumpDatasets(
|
|
|
144
169
|
): Promise<SectionDataset[]> {
|
|
145
170
|
const dump = sectionConfig().dump;
|
|
146
171
|
if (!dump) return [];
|
|
147
|
-
const refs = await dump.discoverDatasets();
|
|
172
|
+
const refs = await dump.discoverDatasets().catch(() => [] as DatasetRef[]);
|
|
148
173
|
const versions = new Map<string, string[]>();
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
174
|
+
const ids: string[] = [];
|
|
175
|
+
if (refs.length) {
|
|
176
|
+
for (const ref of refs) {
|
|
177
|
+
const { id, version } = ref;
|
|
178
|
+
if (version) {
|
|
179
|
+
const list = versions.get(id) ?? [];
|
|
180
|
+
list.push(version);
|
|
181
|
+
versions.set(id, list);
|
|
182
|
+
} else {
|
|
183
|
+
ids.push(id);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
for (const id of Object.keys(sectionConfig().datasetConfig)) {
|
|
188
|
+
if (datasetMembership(section, id)) ids.push(id);
|
|
155
189
|
}
|
|
156
190
|
}
|
|
157
|
-
const ids = refs.filter((ref) => !ref.version);
|
|
158
|
-
const usable = await Promise.all(
|
|
159
|
-
ids.map(async (ref) => {
|
|
160
|
-
const { id } = ref;
|
|
161
|
-
const index = await dump.loadDataset(ref).catch(() => null);
|
|
162
|
-
if (!index || !hasContent(index)) return null;
|
|
163
|
-
return {
|
|
164
|
-
id,
|
|
165
|
-
languages: datasetLanguages(index.manifest.languages ?? []),
|
|
166
|
-
};
|
|
167
|
-
}),
|
|
168
|
-
);
|
|
169
191
|
return (
|
|
170
192
|
await Promise.all(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
193
|
+
ids.map(async (id): Promise<SectionDataset | null> => {
|
|
194
|
+
const index = await dump.loadDataset({ id }).catch(() => null);
|
|
195
|
+
if (!index) {
|
|
196
|
+
if (dumpStatusSnapshot().statuses[id]?.status !== 'failed')
|
|
197
|
+
return null;
|
|
198
|
+
const good = lastGoodDatasets.get(section)?.get(id);
|
|
199
|
+
if (good) return good;
|
|
200
|
+
if (!datasetMembership(section, id)) return null;
|
|
201
|
+
return {
|
|
202
|
+
id,
|
|
203
|
+
languages: datasetLanguages([]),
|
|
204
|
+
...(await sectionDatasetMeta(section, id)),
|
|
205
|
+
...datasetAppearance(id),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
if (!hasContent(index)) return null;
|
|
209
|
+
const row: SectionDataset = {
|
|
174
210
|
id,
|
|
175
|
-
languages,
|
|
211
|
+
languages: datasetLanguages(index.manifest.languages ?? []),
|
|
176
212
|
...(versions.get(id)?.length
|
|
177
213
|
? { versions: versions.get(id)!.sort(compareVersions).reverse() }
|
|
178
214
|
: {}),
|
|
179
|
-
...(await
|
|
180
|
-
Object.values(meta).some((value) => value !== undefined)
|
|
181
|
-
? meta
|
|
182
|
-
: datasetMeta('docs', id),
|
|
183
|
-
)),
|
|
215
|
+
...(await sectionDatasetMeta(section, id)),
|
|
184
216
|
...datasetAppearance(id),
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
217
|
+
};
|
|
218
|
+
rememberDataset(section, row);
|
|
219
|
+
return row;
|
|
220
|
+
}),
|
|
221
|
+
)
|
|
222
|
+
)
|
|
223
|
+
.filter((row): row is SectionDataset => row !== null)
|
|
224
|
+
.sort(datasetOrder);
|
|
188
225
|
}
|
|
189
226
|
|
|
190
227
|
export function sectionDatasets(
|
package/src/lib/urls.ts
CHANGED
|
@@ -15,3 +15,12 @@ export function getDatasetImageUrl(section: string, dataset: string) {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
export function createGitFileUrl(git: {
|
|
19
|
+
user: string;
|
|
20
|
+
repo: string;
|
|
21
|
+
branch: string;
|
|
22
|
+
}) {
|
|
23
|
+
return (filePath: string) =>
|
|
24
|
+
`https://github.com/${git.user}/${git.repo}/blob/${git.branch}/${filePath}`;
|
|
25
|
+
}
|
|
26
|
+
|