Skip to content

Commit c8351ad

Browse files
authored
Merge pull request #14265 from ethereum/staging
Update dev branch
2 parents ff21b03 + 73ccea4 commit c8351ad

File tree

6 files changed

+63
-15
lines changed

6 files changed

+63
-15
lines changed

netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@
3939
path = "en/developers/tutorials/creating-a-wagmi-ui-for-your-contract/"
4040

4141
[functions]
42-
included_files = ["src/data/mocks/**/*"]
42+
included_files = ["i18n.config.json","src/data/mocks/**/*"]

src/pages/api/revalidate.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import type { NextApiRequest, NextApiResponse } from "next"
2+
3+
import i18nConfig from "../../../i18n.config.json"
4+
5+
export default async function handler(
6+
req: NextApiRequest,
7+
res: NextApiResponse
8+
) {
9+
if (req.query.secret !== process.env.REVALIDATE_SECRET) {
10+
return res.status(401).json({ message: "Invalid secret" })
11+
}
12+
13+
const BUILD_LOCALES = process.env.BUILD_LOCALES
14+
// Supported locales defined in `i18n.config.json`
15+
const locales = BUILD_LOCALES
16+
? BUILD_LOCALES.split(",")
17+
: i18nConfig.map(({ code }) => code)
18+
19+
const path = req.query.path as string
20+
console.log("Revalidating", path)
21+
22+
try {
23+
if (!path) {
24+
return res.status(400).json({ message: "No path provided" })
25+
}
26+
27+
const hasLocaleInPath = locales.some((locale) =>
28+
path.startsWith(`/${locale}/`)
29+
)
30+
31+
if (hasLocaleInPath) {
32+
await res.revalidate(path)
33+
} else {
34+
// First revalidate the default locale to cache the results
35+
await res.revalidate(`/en${path}`)
36+
37+
// Then revalidate all other locales
38+
await Promise.all(
39+
locales.map(async (locale) => {
40+
const localePath = `/${locale}${path}`
41+
console.log(`Revalidating ${localePath}`)
42+
try {
43+
await res.revalidate(localePath)
44+
} catch (err) {
45+
console.error(`Error revalidating ${localePath}`, err)
46+
throw new Error(`Error revalidating ${localePath}`)
47+
}
48+
})
49+
)
50+
}
51+
52+
return res.json({ revalidated: true })
53+
} catch (err) {
54+
console.error(err)
55+
// If there was an error, Next.js will continue
56+
// to show the last successfully generated page
57+
return res.status(500).send("Error revalidating")
58+
}
59+
}

src/pages/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ type Props = BasePageProps & {
119119
}
120120

121121
// In seconds
122-
const REVALIDATE_TIME = BASE_TIME_UNIT * 24
122+
const REVALIDATE_TIME = BASE_TIME_UNIT * 1
123123

124124
const loadData = dataLoader(
125125
[
@@ -193,8 +193,6 @@ export const getStaticProps = (async ({ locale }) => {
193193
metricResults,
194194
rssData: { rssItems, blogLinks },
195195
},
196-
// TODO: re-enable revalidation once we have a workaround for failing builds
197-
// revalidate: BASE_TIME_UNIT * 24,
198196
}
199197
}) satisfies GetStaticProps<Props>
200198

src/pages/stablecoins.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type Props = BasePageProps & {
9292
}
9393

9494
// In seconds
95-
const REVALIDATE_TIME = BASE_TIME_UNIT * 24 * 7
95+
const REVALIDATE_TIME = BASE_TIME_UNIT * 1
9696

9797
const loadData = dataLoader<[EthereumDataResponse, StablecoinDataResponse]>(
9898
[
@@ -191,9 +191,6 @@ export const getStaticProps = (async ({ locale }) => {
191191
markets,
192192
marketsHasError,
193193
},
194-
// Updated once a week
195-
// TODO: re-enable revalidation once we have a workaround for failing builds
196-
// revalidate: BASE_TIME_UNIT * 24 * 7,
197194
}
198195
}) satisfies GetStaticProps<Props>
199196

src/pages/staking/index.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ type Props = BasePageProps & {
154154
}
155155

156156
// In seconds
157-
const REVALIDATE_TIME = BASE_TIME_UNIT * 24
157+
const REVALIDATE_TIME = BASE_TIME_UNIT * 1
158158

159159
const loadData = dataLoader(
160160
[["stakingStatsData", fetchBeaconchainData]],
@@ -181,9 +181,6 @@ export const getStaticProps = (async ({ locale }) => {
181181
data,
182182
lastDeployLocaleTimestamp,
183183
},
184-
// Updated once a day
185-
// TODO: re-enable revalidation once we have a workaround for failing builds
186-
// revalidate: BASE_TIME_UNIT * 24,
187184
}
188185
}) satisfies GetStaticProps<Props>
189186

src/pages/wallets/find-wallet.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ export const getStaticProps = (async ({ locale }) => {
7777
lastDeployLocaleTimestamp,
7878
wallets,
7979
},
80-
// Updated once a day
81-
// TODO: re-enable revalidation once we have a workaround for failing builds
82-
// revalidate: BASE_TIME_UNIT * 24,
8380
}
8481
}) satisfies GetStaticProps<Props>
8582

0 commit comments

Comments
 (0)