Skip to content

Commit 53c80f9

Browse files
committed
fix
1 parent 098893e commit 53c80f9

File tree

1 file changed

+55
-66
lines changed

1 file changed

+55
-66
lines changed

src/pages/code.tsx

Lines changed: 55 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,107 +6,111 @@ import Marked from "../components/Marked"
66
import Seo from "../components/Seo"
77
import { toSlug } from "../utils/slug"
88

9-
interface Library {
9+
interface ILibrary {
1010
description: string
1111
github?: string
1212
npm?: string
1313
howto: string
1414
name: string
1515
sourcePath: string
1616
url: string
17+
gem?: string
18+
lastRelease?: string
19+
formattedLastRelease?: string
20+
stars?: number
21+
formattedStars?: string
22+
license?: string
1723
}
1824

1925
interface Language {
2026
name: string
2127
totalStars: number
2228
categoryMap: {
23-
Client: Library[]
24-
Server: Library[]
29+
Client: ILibrary[]
30+
Server: ILibrary[]
2531
}
2632
}
2733

2834
interface PageContext {
2935
languageList: Language[]
3036
otherLibraries: {
31-
Services: Library[]
32-
Tools: Library[]
37+
Services: ILibrary[]
38+
Tools: ILibrary[]
3339
}
3440
sourcePath: string
3541
}
3642

37-
export function buildLibraryContent(
38-
library: any,
39-
pageContext: Queries.TagPageQueryVariables
40-
) {
43+
export function Library({ data }: { data: ILibrary }) {
4144
const [overflown, setOverflown] = useState(false)
4245
const [expanded, setExpanded] = useState(false)
4346
return (
4447
<div className="library-info">
4548
<div className="library-details">
4649
<a
4750
className="library-name"
48-
href={library.url}
51+
href={data.url}
4952
target="_blank"
5053
rel="noreferrer"
5154
>
52-
<p>{library.name}</p>
55+
<p>{data.name}</p>
5356
</a>
54-
{library.github && (
57+
{data.github && (
5558
<div className="library-detail">
5659
<b>GitHub</b>
5760
<a
58-
href={`https://github.com/${library.github}`}
61+
href={`https://github.com/${data.github}`}
5962
target="_blank"
6063
rel="noreferrer"
6164
>
62-
{library.github}
65+
{data.github}
6366
</a>
6467
</div>
6568
)}
66-
{library.npm && (
69+
{data.npm && (
6770
<div className="library-detail">
6871
<b>npm</b>
6972
<a
70-
href={`https://www.npmjs.com/package/${library.npm}`}
73+
href={`https://www.npmjs.com/package/${data.npm}`}
7174
target="_blank"
75+
rel="noreferrer"
7276
>
73-
{library.npm}
77+
{data.npm}
7478
</a>
7579
</div>
7680
)}
77-
{library.gem && (
81+
{data.gem && (
7882
<div className="library-detail">
7983
<b>gem</b>
8084
<a
81-
href={`https://rubygems.org/gems/${library.gem}`}
85+
href={`https://rubygems.org/gems/${data.gem}`}
8286
target="_blank"
8387
rel="noreferrer"
8488
>
85-
{library.gem}
89+
{data.gem}
8690
</a>
8791
</div>
8892
)}
89-
{library.lastRelease && (
93+
{data.lastRelease && (
9094
<div className="library-detail">
9195
<b>Last Release</b>
92-
<span>{library.formattedLastRelease}</span>
96+
<span>{data.formattedLastRelease}</span>
9397
</div>
9498
)}
95-
{library.stars && (
99+
{data.stars && (
96100
<div className="library-detail">
97101
<b>Stars</b>
98-
<span>{library.formattedStars}</span>
102+
<span>{data.formattedStars}</span>
99103
</div>
100104
)}
101-
{library.license && (
105+
{data.license && (
102106
<div className="library-detail">
103107
<b>License</b>
104-
<span>{library.license}</span>
108+
<span>{data.license}</span>
105109
</div>
106110
)}
107-
{library.howto ? (
111+
{data.howto ? (
108112
<div className="library-description">
109-
<Marked pageContext={pageContext}>{library.description}</Marked>
113+
<Marked>{data.description}</Marked>
110114
</div>
111115
) : (
112116
<br />
@@ -123,9 +127,7 @@ export function buildLibraryContent(
123127
}
124128
}}
125129
>
126-
<Marked pageContext={pageContext}>
127-
{library.howto || library.description}
128-
</Marked>
130+
<Marked>{data.howto || data.description}</Marked>
129131
</div>
130132
{overflown && (
131133
<div
@@ -145,34 +147,16 @@ export function buildLibraryContent(
145147
)
146148
}
147149

148-
export function buildLibraryList(
149-
libraries: Library[],
150-
pageContext: any
151-
) {
150+
export function LibraryList({ data }: { data: ILibrary[] }) {
152151
return (
153152
<div className="library-list">
154-
{libraries.map(library => buildLibraryContent(library, pageContext))}
153+
{data.map(library => (
154+
<Library data={library} />
155+
))}
155156
</div>
156157
)
157158
}
158159

159-
export function buildLibraryCategoryContent(
160-
libraryCategories: { Client: Library[]; Server: Library[] },
161-
libraryCategoryName: 'Client' | 'Server',
162-
slug: string,
163-
pageContext: any
164-
) {
165-
if (libraryCategoryName in libraryCategories) {
166-
const libraries = libraryCategories[libraryCategoryName]
167-
return (
168-
<div id={slug} className="library-category">
169-
<h3 className="library-category-title">{libraryCategoryName}</h3>
170-
{buildLibraryList(libraries, pageContext)}
171-
</div>
172-
)
173-
}
174-
}
175-
176160
const categorySlugMap = [
177161
["Server", toSlug("Server")],
178162
["Client", toSlug("Client")],
@@ -271,11 +255,22 @@ export default ({ pageContext }: PageProps<{}, PageContext>) => {
271255
<div className="library-categories">
272256
{filteredCategorySlugMap.map(
273257
([categoryName, categorySlug]) =>
274-
buildLibraryCategoryContent(
275-
libraryCategories,
276-
categoryName,
277-
`${languageSlug}-${categorySlug}`,
278-
pageContext
258+
categoryName in libraryCategories && (
259+
<div
260+
id={`${languageSlug}-${categorySlug}`}
261+
className="library-category"
262+
>
263+
<h3 className="library-category-title">
264+
{categoryName}
265+
</h3>
266+
<LibraryList
267+
data={
268+
libraryCategories[
269+
categoryName as "Client" | "Server"
270+
]
271+
}
272+
/>
273+
</div>
279274
)
280275
)}
281276
</div>
@@ -290,21 +285,15 @@ export default ({ pageContext }: PageProps<{}, PageContext>) => {
290285
#
291286
</AnchorLink>
292287
</h2>
293-
{buildLibraryList(
294-
pageContext.otherLibraries?.Tools ?? [],
295-
pageContext
296-
)}
288+
<LibraryList data={pageContext.otherLibraries?.Tools ?? []} />
297289
<h2>
298290
<a className="anchor" id="services"></a>
299291
Services
300292
<AnchorLink className="hash-link" to="#services">
301293
#
302294
</AnchorLink>
303295
</h2>
304-
{buildLibraryList(
305-
pageContext.otherLibraries?.Services ?? [],
306-
pageContext
307-
)}
296+
<LibraryList data={pageContext.otherLibraries?.Services ?? []} />
308297
</div>
309298
</div>
310299
<p>

0 commit comments

Comments
 (0)