Skip to content

Commit 2b8f435

Browse files
committed
fix: build glossary
1 parent 7931033 commit 2b8f435

File tree

6 files changed

+69
-28
lines changed

6 files changed

+69
-28
lines changed

app/_actions/patterns.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export async function getPatternCategories(locale: string): Promise<PatternCateg
5959
return {
6060
name: category.name,
6161
path: category.path,
62+
description: category.description || '',
6263
patterns: pages.map(page => {
6364
const iconName = page.frontMatter?.icon
6465
const status = (page.frontMatter?.status as PatternStatus) || 'coming-soon'

app/_components/glossary/term-card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface TermCardProps {
1212
export function TermCard({ title, description, category, slug }: TermCardProps) {
1313
return (
1414
<Link
15-
href={`./glossary/${slug}`}
15+
href={`/glossary/${slug}`}
1616
className="block p-6 rounded-lg border border-gray-200 hover:border-primary transition-colors duration-200 dark:border-gray-700"
1717
>
1818
<div className="flex flex-col gap-2">
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { getGlossaryTerms } from "@app/_utils/get-glossary-terms";
2+
import { Suspense } from 'react';
3+
import { TermsList } from "./terms-list";
4+
5+
function LoadingTerms() {
6+
return <div>Loading glossary terms...</div>;
7+
}
8+
9+
export function TermsListContainer() {
10+
return (
11+
<Suspense fallback={<LoadingTerms />}>
12+
<TermsListContent />
13+
</Suspense>
14+
);
15+
}
16+
17+
async function TermsListContent() {
18+
const terms = await getGlossaryTerms();
19+
20+
if (!terms || terms.length === 0) {
21+
return <p>No glossary terms found.</p>;
22+
}
23+
24+
return <TermsList terms={terms} />;
25+
}

app/_utils/get-glossary-terms.ts

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,51 @@
1+
import { existsSync } from 'fs'
12
import { readdir, readFile } from 'fs/promises'
23
import matter from 'gray-matter'
34
import { join } from 'path'
45

5-
interface GlossaryTerm {
6+
export interface GlossaryTerm {
67
title: string
78
description: string
89
category: string[]
910
slug: string
1011
}
1112

1213
export async function getGlossaryTerms(): Promise<GlossaryTerm[]> {
13-
const glossaryPath = join(process.cwd(), 'content/en/glossary')
14-
const files = await readdir(glossaryPath)
14+
try {
15+
const glossaryPath = join(process.cwd(), 'content/en/glossary')
1516

16-
const terms = await Promise.all(
17-
files
18-
.filter((file) => file.endsWith('.mdx') && file !== 'index.mdx')
19-
.map(async (file) => {
20-
const filePath = join(glossaryPath, file)
21-
const content = await readFile(filePath, 'utf-8')
22-
const { data } = matter(content)
17+
if (!existsSync(glossaryPath)) {
18+
console.warn('Glossary directory not found:', glossaryPath)
19+
return []
20+
}
2321

24-
return {
25-
title: data.title,
26-
description: data.description,
27-
category: data.category,
28-
slug: file.replace('.mdx', '')
29-
}
30-
})
31-
)
22+
const files = await readdir(glossaryPath)
3223

33-
return terms
24+
const terms = await Promise.all(
25+
files
26+
.filter((file) => file.endsWith('.mdx') && file !== 'index.mdx')
27+
.map(async (file) => {
28+
try {
29+
const filePath = join(glossaryPath, file)
30+
const content = await readFile(filePath, 'utf-8')
31+
const { data } = matter(content)
32+
33+
return {
34+
title: data.title || '',
35+
description: data.description || '',
36+
category: Array.isArray(data.category) ? data.category : [],
37+
slug: file.replace('.mdx', '')
38+
}
39+
} catch (error) {
40+
console.error(`Error processing file ${file}:`, error)
41+
return null
42+
}
43+
})
44+
)
45+
46+
return terms.filter((term): term is GlossaryTerm => term !== null)
47+
} catch (error) {
48+
console.error('Error fetching glossary terms:', error)
49+
return []
50+
}
3451
}

content/en/glossary/_meta.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export default {
2-
'index': '',
32
'pagination': '',
3+
'aria-attributes': '',
4+
'semantic-html': '',
5+
'progressive-loading': '',
46
}

content/en/glossary/index.mdx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
---
22
title: UX Patterns Glossary
3-
description: A comprehensive glossary of UX patterns, design principles, and web development terminology to help you better understand and implement user experience best practices.
3+
description: A comprehensive glossary of UX patterns, design principles, and web development terminology.
44
---
55

66
import { AlphabetNav } from "@app/_components/glossary/alphabet-nav";
7-
import { TermsList } from "@app/_components/glossary/terms-list";
8-
import { getGlossaryTerms } from "@app/_utils/get-glossary-terms";
9-
10-
export const terms = await getGlossaryTerms();
7+
import { TermsListContainer } from "@app/_components/glossary/terms-list-container";
118

129
# UX Patterns Glossary
1310

@@ -16,5 +13,4 @@ Welcome to our comprehensive glossary of UX patterns and web development termino
1613
## Navigation
1714

1815
<AlphabetNav />
19-
20-
<TermsList terms={terms} />
16+
<TermsListContainer />

0 commit comments

Comments
 (0)