Skip to content

Commit ce4583d

Browse files
committed
Fix issue with fs on cloudflare for the /icons endpoint.
1 parent 9c287db commit ce4583d

6 files changed

Lines changed: 38 additions & 39 deletions

File tree

src/pages/api/[version]/icons/[setId].json.ts renamed to src/pages/api/[version]/icons/[iconSet].ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ import { getIconSvgsForSet } from '../../../../utils/icons/reactIcons'
66
/**
77
* Prerender at build time so this doesn't run in the Cloudflare Worker.
88
* getIconSvgsForSet() reads from @patternfly/react-icons/dist/static (Node fs).
9-
* Serves JSON of all icon SVGs for a set (e.g. /api/v5/icons/pf.json).
9+
* Serves JSON of all icon SVGs for a set (e.g. /api/v6/icons/pf).
1010
*/
1111
export const prerender = true
1212

1313
export const getStaticPaths: GetStaticPaths = async () => {
1414
const versions = await getVersionsFromIndexFile()
1515
return versions.flatMap((version) => [
16-
{ params: { version, setId: 'pf' } },
16+
{ params: { version, iconSet: 'pf' } },
1717
])
1818
}
1919

2020
export const GET: APIRoute = async ({ params }) => {
21-
const { version, setId } = params
21+
const { version, iconSet } = params
2222
if (!version) {
2323
return createJsonResponse(
2424
{ error: 'Version parameter is required' },
2525
400,
2626
)
2727
}
28-
if (!setId) {
29-
return createJsonResponse({ error: 'Set ID is required' }, 400)
28+
if (!iconSet) {
29+
return createJsonResponse({ error: 'Icon set is required' }, 400)
3030
}
3131

3232
try {
33-
const svgs = await getIconSvgsForSet(setId)
33+
const svgs = await getIconSvgsForSet(iconSet)
3434
return createJsonResponse(svgs)
3535
} catch (error) {
3636
const details = error instanceof Error ? error.message : String(error)

src/pages/api/[version]/icons/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,28 @@ import type { APIRoute } from 'astro'
22
import { createJsonResponse } from '../../../../utils/apiHelpers'
33
import { fetchApiIndex } from '../../../../utils/apiIndex/fetch'
44
import { fetchIconsIndex } from '../../../../utils/icons/fetch'
5-
import { filterIcons } from '../../../../utils/icons/reactIcons'
5+
import { IconMetadata } from '../../../../utils/icons/icons'
66

77
export const prerender = false
88

9+
/**
10+
* Filter icons by search term (case-insensitive match on name or reactName)
11+
*/
12+
export function filterIcons(
13+
icons: IconMetadata[],
14+
filter: string,
15+
): IconMetadata[] {
16+
if (!filter || !filter.trim()) {
17+
return icons
18+
}
19+
const term = filter.toLowerCase().trim()
20+
return icons.filter(
21+
(icon) =>
22+
icon.name.toLowerCase().includes(term) ||
23+
icon.reactName.toLowerCase().includes(term),
24+
)
25+
}
26+
927
/**
1028
* GET /api/{version}/icons
1129
* Returns list of all available icons with metadata.

src/utils/icons/fetch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { IconMetadata } from './reactIcons'
1+
import type { IconMetadata } from './icons'
22

33
export interface IconsIndex {
44
icons: IconMetadata[]
@@ -41,7 +41,7 @@ export async function fetchIconSvgs(
4141
version: string,
4242
setId: string,
4343
): Promise<Record<string, string> | null> {
44-
const iconsSvgsUrl = new URL(`/api/${version}/icons/${setId}.json`, url.origin)
44+
const iconsSvgsUrl = new URL(`/api/${version}/icons/${setId}`, url.origin)
4545
const response = assetsFetch
4646
? await assetsFetch(new Request(iconsSvgsUrl))
4747
: await fetch(iconsSvgsUrl)

src/utils/icons/icons.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface IconMetadata {
2+
name: string
3+
reactName: string
4+
usage: string
5+
}
6+
7+
export const PF_ICONS_SET_ID = 'pf'

src/utils/icons/reactIcons.ts

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@
22
* Utilities for working with @patternfly/react-icons.
33
* Icons are loaded from @patternfly/react-icons/dist/static (SVG files).
44
*/
5-
import fs from 'fs'
6-
import path from 'path'
7-
8-
export interface IconMetadata {
9-
name: string
10-
reactName: string
11-
usage: string
12-
}
13-
14-
const PF_ICONS_SET_ID = 'pf'
15-
5+
import fs from 'node:fs'
6+
import path from 'node:path'
7+
import { IconMetadata, PF_ICONS_SET_ID } from './icons'
168
/** Resolve path to @patternfly/react-icons/dist/static. Uses cwd so it works in dev and build. */
179
function getStaticIconsDir(): string {
1810
return path.join(
@@ -70,24 +62,6 @@ export async function getAllIcons(): Promise<IconMetadata[]> {
7062
return icons
7163
}
7264

73-
/**
74-
* Filter icons by search term (case-insensitive match on name or reactName)
75-
*/
76-
export function filterIcons(
77-
icons: IconMetadata[],
78-
filter: string,
79-
): IconMetadata[] {
80-
if (!filter || !filter.trim()) {
81-
return icons
82-
}
83-
const term = filter.toLowerCase().trim()
84-
return icons.filter(
85-
(icon) =>
86-
icon.name.toLowerCase().includes(term) ||
87-
icon.reactName.toLowerCase().includes(term),
88-
)
89-
}
90-
9165
/**
9266
* Get SVG markup for all PatternFly icons (single set).
9367
* Used at build time for prerendering.

wrangler.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "node_modules/wrangler/config-schema.json",
33
"name": "patternfly-docs-core",
4-
"compatibility_date": "2025-06-17",
4+
"compatibility_date": "2026-02-18",
55
"compatibility_flags": ["nodejs_compat"],
66
"observability": {
77
"enabled": true

0 commit comments

Comments
 (0)