Skip to content

Commit ace719c

Browse files
committed
final tweaks
1 parent 174608a commit ace719c

1 file changed

Lines changed: 24 additions & 38 deletions

File tree

src/pages/[...path].md.ts

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -53,43 +53,13 @@ export const GET: APIRoute = async ({ params, request }) => {
5353
const title = fmTitle || path.basename(mdxAbsPath, path.extname(mdxAbsPath))
5454
const lastModified = getIsoStringOrUndefined(fmLastModified)
5555

56-
const isFeedsPage = cleanPath.includes("data-feeds/price-feeds/addresses")
57-
const isStreamsPage = cleanPath.includes("data-streams")
58-
5956
const headerLines = [
6057
`# ${title}`,
6158
`Source: ${sourceUrl}`,
6259
...(lastModified ? [`Last Updated: ${lastModified}`] : []),
6360
"",
6461
LLMS_DIRECTIVE,
6562
"",
66-
...(isFeedsPage
67-
? [
68-
"## Full datasets",
69-
"",
70-
"Use the network index to retrieve feed addresses:",
71-
"",
72-
"/data-feeds/feed-addresses/default.txt",
73-
"",
74-
"Each network has its own dataset.",
75-
"Do not load multiple networks unless required.",
76-
"",
77-
]
78-
: []),
79-
...(isStreamsPage
80-
? [
81-
"## Full datasets",
82-
"",
83-
"Use structured datasets for stream IDs and network metadata:",
84-
"",
85-
"/data-streams/stream-ids/crypto.txt",
86-
"/data-streams/networks.txt",
87-
"",
88-
"Stream IDs are universal.",
89-
"Networks provide verifier proxy addresses.",
90-
"",
91-
]
92-
: []),
9363
]
9464

9565
return new Response([...headerLines, transformed.trim()].join("\n"), {
@@ -107,7 +77,13 @@ async function transformPageBodyToMarkdown(
10777
targetLanguage?: string
10878
}
10979
): Promise<string> {
110-
const chainCache = await getServerSideChainMetadata(CHAINS)
80+
let chainCache: Record<string, any> = {}
81+
82+
try {
83+
chainCache = await getServerSideChainMetadata(CHAINS)
84+
} catch (e) {
85+
console.error("Failed to load chain metadata:", e)
86+
}
11187

11288
// -----------------------
11389
// FEEDS INJECTION
@@ -121,6 +97,14 @@ async function transformPageBodyToMarkdown(
12197
{ networkType: "mainnet" }
12298
)
12399

100+
const hasExample = exampleMarkdown && !exampleMarkdown.includes("No feeds found")
101+
102+
const fallbackExample = `
103+
| Feed Name | Proxy Address | Deviation | Heartbeat |
104+
|-----------|--------------|-----------|-----------|
105+
| ETH / USD | \`0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419\` | 0.5% | 1h |
106+
`
107+
124108
const replacement = `
125109
## Full datasets
126110
@@ -135,7 +119,7 @@ Do not load multiple networks unless required.
135119
136120
## Example (Ethereum Mainnet)
137121
138-
${exampleMarkdown}
122+
${hasExample ? exampleMarkdown : fallbackExample}
139123
`
140124

141125
body = body.replace(/<FeedPage[\s\S]*?\/>/g, replacement)
@@ -147,7 +131,13 @@ ${exampleMarkdown}
147131
if (body.includes("<StreamList")) {
148132
const streams = collectStreamEntries(STREAM_CATEGORY_MAP.crypto, chainCache, { publicType: "crypto" } as any)
149133

150-
const exampleMarkdown = buildStreamExample(streams)
134+
const exampleMarkdown = streams.length > 0 ? buildStreamExample(streams) : ""
135+
136+
const fallbackExample = `
137+
| Stream | Feed ID | Schema |
138+
|--------|---------|--------|
139+
| BTC/USD | \`0x00039d9f...\` | v3 |
140+
`
151141

152142
const replacement = `
153143
## Full datasets
@@ -164,7 +154,7 @@ Networks provide verifier proxy addresses.
164154
165155
## Example (Crypto Streams)
166156
167-
${exampleMarkdown}
157+
${exampleMarkdown || fallbackExample}
168158
`
169159

170160
body = body.replace(/<StreamList[\s\S]*?\/>/g, replacement)
@@ -183,8 +173,6 @@ ${exampleMarkdown}
183173
}
184174
}
185175

186-
// -----------------------
187-
// STREAM EXAMPLE BUILDER
188176
// -----------------------
189177
function buildStreamExample(streams: Array<{ name: string; feedId: string; schema: string }>): string {
190178
const sample = streams.slice(0, 10)
@@ -198,8 +186,6 @@ function buildStreamExample(streams: Array<{ name: string; feedId: string; schem
198186
return lines.join("\n")
199187
}
200188

201-
// -----------------------
202-
// UTILITIES
203189
// -----------------------
204190
function buildFallbackMarkdownBody(body: string): string {
205191
return stripRuntimeMdxSyntax(body)

0 commit comments

Comments
 (0)