@terrafirmagreg-team/kit 1.2.11 → 1.2.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terrafirmagreg-team/kit",
3
- "version": "1.2.11",
3
+ "version": "1.2.12",
4
4
  "type": "module",
5
5
  "description": "Fumadocs content engine",
6
6
  "license": "LGPL-3.0-only",
@@ -25,10 +25,10 @@
25
25
  "@base-ui/react": "^1.9.0",
26
26
  "@icons-pack/react-simple-icons": "13.15.1",
27
27
  "@terrafirmagreg-team/data": "^1.2.3",
28
- "@terrafirmagreg-team/mdx": "^1.2.5",
28
+ "@terrafirmagreg-team/mdx": "^1.2.6",
29
29
  "@terrafirmagreg-team/sites": "^1.2.2",
30
- "@terrafirmagreg-team/translate": "^1.2.7",
31
- "@terrafirmagreg-team/ui": "^1.2.8",
30
+ "@terrafirmagreg-team/translate": "^1.2.8",
31
+ "@terrafirmagreg-team/ui": "^1.2.9",
32
32
  "fumadocs-core": "16.17.10",
33
33
  "lucide-react": "^1.63.0",
34
34
  "server-only": "^0.0.1",
@@ -20,10 +20,6 @@ import { ItemRow } from '@terrafirmagreg-team/ui/components/blocks/list/row';
20
20
  import { useUntranslated } from '@terrafirmagreg-team/ui/hooks/use-lang';
21
21
  import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
22
22
  import { useCopyButton } from '@terrafirmagreg-team/ui/hooks/use-copy-button';
23
- import {
24
- openPageMarkdown,
25
- pageMarkdown,
26
- } from '@terrafirmagreg-team/mdx/lib/markdown';
27
23
  import type { TranslationState } from '@terrafirmagreg-team/translate/server';
28
24
 
29
25
  function ActionButton({
@@ -70,12 +66,10 @@ export function MarkdownCopyButton({
70
66
  );
71
67
  }
72
68
 
73
- export function CopyPageMarkdown({ title }: { title: string }) {
69
+ export function CopyPageMarkdown({ mdUrl }: { mdUrl: string }) {
74
70
  return (
75
71
  <MarkdownCopyButton
76
- getMarkdown={() =>
77
- pageMarkdown(document.querySelector('[data-md-root]'), title)
78
- }
72
+ getMarkdown={() => fetch(mdUrl).then((res) => res.text())}
79
73
  />
80
74
  );
81
75
  }
@@ -107,12 +101,10 @@ export function UntranslatedActions({
107
101
 
108
102
  export function ViewOptionsPopover({
109
103
  githubUrl,
110
- title,
111
104
  mdUrl,
112
105
  ...props
113
106
  }: ComponentProps<typeof PopoverTrigger> & {
114
107
  githubUrl?: string;
115
- title?: string;
116
108
  mdUrl?: string;
117
109
  }) {
118
110
  const t = useTranslations();
@@ -122,17 +114,9 @@ export function ViewOptionsPopover({
122
114
  href: githubUrl,
123
115
  icon: <SiGithub color="currentColor" className="size-4" />,
124
116
  },
125
- (mdUrl || title !== undefined) && {
117
+ mdUrl && {
126
118
  title: t('View as Markdown', { note: 'ui.view_markdown' }),
127
- ...(mdUrl
128
- ? { href: mdUrl }
129
- : {
130
- onClick: () =>
131
- void openPageMarkdown(
132
- document.querySelector('[data-md-root]'),
133
- title!,
134
- ),
135
- }),
119
+ href: mdUrl,
136
120
  icon: <TextIcon className="size-4" />,
137
121
  },
138
122
  ].filter((v) => !!v);
@@ -163,9 +147,9 @@ export function ViewOptionsPopover({
163
147
  {items.map((item) => (
164
148
  <ItemRow
165
149
  key={item.title}
166
- {...('href' in item
167
- ? { href: item.href, target: '_blank', rel: 'noreferrer noopener' }
168
- : { onClick: item.onClick })}
150
+ href={item.href}
151
+ target="_blank"
152
+ rel="noreferrer noopener"
169
153
  media={item.icon}
170
154
  title={item.title}
171
155
  trailing={
@@ -181,20 +165,18 @@ export function ViewOptionsPopover({
181
165
  export function PageActions({
182
166
  copied,
183
167
  crowdinUrl,
184
- title,
185
168
  mdUrl,
186
169
  githubUrl,
187
170
  }: {
188
171
  copied?: TranslationState;
189
172
  crowdinUrl?: string;
190
- title: string;
191
173
  mdUrl?: string;
192
174
  githubUrl?: string;
193
175
  }) {
194
176
  return (
195
177
  <>
196
- <CopyPageMarkdown title={title} />
197
- <ViewOptionsPopover title={title} mdUrl={mdUrl} githubUrl={githubUrl} />
178
+ {mdUrl ? <CopyPageMarkdown mdUrl={mdUrl} /> : null}
179
+ <ViewOptionsPopover mdUrl={mdUrl} githubUrl={githubUrl} />
198
180
  <UntranslatedActions copied={copied} crowdinUrl={crowdinUrl} />
199
181
  </>
200
182
  );
@@ -3,13 +3,11 @@ import { notFound } from 'next/navigation';
3
3
  import type { Metadata } from 'next';
4
4
  import { LangContentSwitch } from '@terrafirmagreg-team/ui/components/blocks/lang/content';
5
5
  import {
6
+ datasetLandingMetadata,
6
7
  generateDatasetLandingParams,
7
- getDatasetLanding,
8
8
  resolveDatasetLanding,
9
9
  } from '@terrafirmagreg-team/kit/lib/landing';
10
10
  import { sectionDatasets } from '@terrafirmagreg-team/kit/lib/datasets';
11
- import { sectionUrl } from '@terrafirmagreg-team/sites/location';
12
- import { canonicalUrl } from '@terrafirmagreg-team/kit/lib/urls';
13
11
  import type { DatasetLanding, SectionKey } from '@terrafirmagreg-team/kit/types';
14
12
  import {
15
13
  localeLoader,
@@ -58,22 +56,11 @@ export function createDatasetLandingPage<S extends SectionKey>(
58
56
  params,
59
57
  }: DatasetPageParams): Promise<Metadata> {
60
58
  const { slug } = await params;
61
- const page = getDatasetLanding(
59
+ return datasetLandingMetadata(
62
60
  section,
63
61
  slug,
64
- 'en_us',
65
62
  await sectionDatasets(section),
66
63
  );
67
- if (!page) notFound();
68
- return {
69
- title: page.title,
70
- description: page.description,
71
- alternates: {
72
- canonical: canonicalUrl(
73
- `${sectionUrl(section)}/${(slug ?? []).join('/')}`,
74
- ),
75
- },
76
- };
77
64
  }
78
65
 
79
66
  return { Page, generateStaticParams, generateMetadata };
@@ -20,6 +20,7 @@ import {
20
20
  sectionDatasets,
21
21
  } from '@terrafirmagreg-team/kit/lib/datasets';
22
22
  import {
23
+ datasetLandingMetadata,
23
24
  generateDatasetLandingParams,
24
25
  getDatasetLanding,
25
26
  } from '@terrafirmagreg-team/kit/lib/landing';
@@ -33,7 +34,6 @@ import {
33
34
  localeLoader,
34
35
  registerLocaleRenderer,
35
36
  } from '@terrafirmagreg-team/kit/lib/locale/renderer';
36
- import { canonicalUrl } from '@terrafirmagreg-team/kit/lib/urls';
37
37
  import { sectionUrl } from '@terrafirmagreg-team/sites/location';
38
38
  import { langContent, loadLocaleRegistry } from '@terrafirmagreg-team/translate/server';
39
39
  import type {
@@ -170,6 +170,7 @@ export function createSectionRoutes<
170
170
  }
171
171
  if (!PageView) return null;
172
172
  return renderSectionWorkspace({
173
+ section,
173
174
  source: src as SectionSource,
174
175
  slug,
175
176
  contentDir: source.contentDir ?? `content/${section}`,
@@ -275,22 +276,12 @@ export function createSectionRoutes<
275
276
 
276
277
  async function generateMetadata({ params }: RouteParams): Promise<Metadata> {
277
278
  const { slug } = await params;
278
- if (slug?.length === 1 && landing) {
279
- const page = getDatasetLanding(
279
+ if (slug?.length === 1 && landing)
280
+ return datasetLandingMetadata(
280
281
  section,
281
282
  slug,
282
- 'en_us',
283
283
  await sectionDatasets(section),
284
284
  );
285
- if (!page) notFound();
286
- return {
287
- title: page.title,
288
- description: page.description,
289
- alternates: {
290
- canonical: canonicalUrl(`${sectionUrl(section)}/${slug.join('/')}`),
291
- },
292
- };
293
- }
294
285
  if (!PageView) return {};
295
286
  const src = (await source.getSource()) as SectionSource | undefined;
296
287
  if (src) {
@@ -10,11 +10,13 @@ import {
10
10
  import { loadLocaleRegistry } from '@terrafirmagreg-team/translate/server';
11
11
  import { readPageSource, translationState } from '@terrafirmagreg-team/translate/server';
12
12
  import { resolvePage, type SectionSource } from '@terrafirmagreg-team/kit/lib/page';
13
+ import { pageJsonLd } from '@terrafirmagreg-team/kit/lib/jsonld';
13
14
  import { findNeighbour } from 'fumadocs-core/page-tree';
14
15
  import { stripLangFromUrl } from '@terrafirmagreg-team/translate/lib/slug';
15
16
  import { sectionConfig } from '@terrafirmagreg-team/kit/lib/config';
16
17
  import type {
17
18
  DatasetCatalog,
19
+ SectionKey,
18
20
  SectionPage,
19
21
  SectionTrees,
20
22
  } from '@terrafirmagreg-team/kit/types';
@@ -53,6 +55,7 @@ export type SectionPageViewFn = (
53
55
  ) => SectionPageView | Promise<SectionPageView>;
54
56
 
55
57
  export async function renderSectionWorkspace({
58
+ section,
56
59
  source,
57
60
  slug,
58
61
  contentDir,
@@ -64,6 +67,7 @@ export async function renderSectionWorkspace({
64
67
  page,
65
68
  lang,
66
69
  }: {
70
+ section: SectionKey;
67
71
  source: SectionSource;
68
72
  slug: string[] | undefined;
69
73
  contentDir: string;
@@ -117,6 +121,18 @@ export async function renderSectionWorkspace({
117
121
  history,
118
122
  features,
119
123
  });
120
- return renderSectionView(view);
124
+ const jsonLd = JSON.stringify(pageJsonLd({ section, page, crumbs, lang }));
125
+ return renderSectionView({
126
+ ...view,
127
+ node: (
128
+ <>
129
+ <script
130
+ type="application/ld+json"
131
+ dangerouslySetInnerHTML={{ __html: jsonLd }}
132
+ />
133
+ {view.node}
134
+ </>
135
+ ),
136
+ });
121
137
  }
122
138
 
@@ -0,0 +1,46 @@
1
+ import 'server-only';
2
+ import { stripLangFromUrl } from '@terrafirmagreg-team/translate/lib/slug';
3
+ import { sectionConfig } from './config';
4
+ import { canonicalUrl } from './urls';
5
+ import type { SectionCrumb } from './breadcrumb';
6
+ import type { SectionKey, SectionPage } from '@terrafirmagreg-team/kit/types';
7
+ import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
8
+
9
+ export function pageJsonLd({
10
+ section,
11
+ page,
12
+ crumbs,
13
+ lang,
14
+ }: {
15
+ section: SectionKey;
16
+ page: SectionPage;
17
+ crumbs: readonly SectionCrumb[];
18
+ lang: Lang;
19
+ }): Record<string, unknown>[] {
20
+ const languages = [...sectionConfig().knownLanguages];
21
+ const url = canonicalUrl(stripLangFromUrl(page.url, languages));
22
+ const items = crumbs.length ? crumbs : [{ name: page.data.title }];
23
+ return [
24
+ {
25
+ '@context': 'https://schema.org',
26
+ '@type': 'Article',
27
+ headline: page.data.title,
28
+ description: page.data.description,
29
+ url,
30
+ inLanguage: lang.replace('_', '-'),
31
+ isPartOf: { '@type': 'WebSite', url: canonicalUrl(`/${section}`) },
32
+ },
33
+ {
34
+ '@context': 'https://schema.org',
35
+ '@type': 'BreadcrumbList',
36
+ itemListElement: items.map((crumb, index) => ({
37
+ '@type': 'ListItem',
38
+ position: index + 1,
39
+ name: crumb.name,
40
+ item: crumb.url
41
+ ? canonicalUrl(stripLangFromUrl(crumb.url, languages))
42
+ : url,
43
+ })),
44
+ },
45
+ ];
46
+ }
@@ -1,5 +1,9 @@
1
1
  import 'server-only';
2
+ import type { Metadata } from 'next';
3
+ import { notFound } from 'next/navigation';
2
4
  import { loadLocaleRegistry } from '@terrafirmagreg-team/translate/server';
5
+ import { sectionUrl } from '@terrafirmagreg-team/sites/location';
6
+ import { canonicalUrl, getDatasetImageUrl } from './urls';
3
7
  import { datasetSlugs, findDataset } from './datasets';
4
8
  import type {
5
9
  DatasetLanding,
@@ -30,6 +34,36 @@ export function getDatasetLanding(
30
34
  };
31
35
  }
32
36
 
37
+ export function datasetLandingMetadata(
38
+ section: SectionKey,
39
+ slug: string[] | undefined,
40
+ datasets: readonly SectionDataset[],
41
+ ): Metadata {
42
+ const page = getDatasetLanding(section, slug, 'en_us', datasets);
43
+ if (!page) notFound();
44
+ const meta = findDataset(datasets, { id: slug?.[0] ?? '' });
45
+ const description = page.description ?? meta?.description;
46
+ const title = page.datasetTitle ?? page.title;
47
+ const url = canonicalUrl(`${sectionUrl(section)}/${(slug ?? []).join('/')}`);
48
+ return {
49
+ title,
50
+ description,
51
+ alternates: { canonical: url },
52
+ openGraph: {
53
+ type: 'website',
54
+ url,
55
+ title,
56
+ description,
57
+ images: getDatasetImageUrl(section, slug?.[0] ?? '').url,
58
+ },
59
+ twitter: {
60
+ card: 'summary_large_image',
61
+ title,
62
+ description,
63
+ },
64
+ };
65
+ }
66
+
33
67
  export function resolveDatasetLanding(
34
68
  section: SectionKey,
35
69
  slug: string[] | undefined,
package/src/lib/page.ts CHANGED
@@ -1,30 +1,16 @@
1
1
  import type { Metadata } from 'next';
2
2
  import { notFound } from 'next/navigation';
3
- import { createGetUrl } from 'fumadocs-core/source';
4
3
  import { firstLocalizedPage } from '@terrafirmagreg-team/translate/server';
5
4
  import { loadLocaleRegistry } from '@terrafirmagreg-team/translate/server';
6
5
  import { stripLangFromUrl, toInternalSlugs, toPublicSlug } from '@terrafirmagreg-team/translate/lib/slug';
7
6
  import { sectionConfig } from './config';
8
7
  import { sectionDatasets } from './datasets';
8
+ import { canonicalUrl, getPageImageUrl } from './urls';
9
9
  import type { SectionKey, SectionPage, SectionSource } from '@terrafirmagreg-team/kit/types';
10
10
  import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
11
11
 
12
12
  export type { SectionSource } from '@terrafirmagreg-team/kit/types';
13
-
14
- const canonicalUrl = (pathname: string): string =>
15
- new URL(
16
- pathname.startsWith('/') ? pathname : `/${pathname}`,
17
- sectionConfig().siteUrl,
18
- ).toString();
19
-
20
- let imageUrl: ReturnType<typeof createGetUrl> | undefined;
21
- const getImageUrl = () =>
22
- (imageUrl ??= createGetUrl(sectionConfig().previewRoute));
23
-
24
- function getDatasetImageUrl(section: string, dataset: string) {
25
- const segments = [section, dataset, 'image.png'];
26
- return { segments, url: getImageUrl()(segments) };
27
- }
13
+ export { getDatasetImageUrl } from './urls';
28
14
 
29
15
  export function getPage<S extends SectionSource>(
30
16
  source: S,
@@ -97,7 +83,7 @@ export async function sectionMetadata(
97
83
  url,
98
84
  title: doc.data.title,
99
85
  description: doc.data.description,
100
- images: getDatasetImageUrl(section, doc.slugs[0]).url,
86
+ images: getPageImageUrl(section, doc.slugs).url,
101
87
  },
102
88
  twitter: {
103
89
  card: 'summary_large_image',
package/src/lib/urls.ts CHANGED
@@ -15,6 +15,15 @@ export function getDatasetImageUrl(section: string, dataset: string) {
15
15
  };
16
16
  }
17
17
 
18
+ export function getPageImageUrl(section: string, slugs: string[]) {
19
+ const segments = [section, ...slugs, 'image.png'];
20
+
21
+ return {
22
+ segments,
23
+ url: createGetUrl(sectionConfig().previewRoute)(segments),
24
+ };
25
+ }
26
+
18
27
  export function createGitFileUrl(git: {
19
28
  user: string;
20
29
  repo: string;