From 07deb7125a4cfac4cee5e890104f67a9c5f54d21 Mon Sep 17 00:00:00 2001 From: Marcos Passos Date: Wed, 23 Oct 2024 13:10:39 -0600 Subject: [PATCH] Add automatic fallback --- package-lock.json | 7 +++++++ package.json | 1 + src/server/fetchContent.ts | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/package-lock.json b/package-lock.json index 74fe899..dcfb2d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.0-dev", "license": "MIT", "dependencies": { + "@croct/content": "^1.0.0", "@croct/plug": "^0.16.2", "@croct/plug-react": "^0.9.0", "@croct/sdk": "^0.17.4", @@ -1961,6 +1962,12 @@ "dev": true, "license": "MIT" }, + "node_modules/@croct/content": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@croct/content/-/content-1.0.0.tgz", + "integrity": "sha512-WCqzCT+Uz7vLCPVbc9M8/yXjS1MJZprwtVCdkkbWsct3mu3LMBd953VdUVRDepGJE4gJP65VPezVlojI2NL2Lg==", + "license": "MIT" + }, "node_modules/@croct/eslint-plugin": { "version": "0.7.1", "resolved": "https://registry.npmjs.org/@croct/eslint-plugin/-/eslint-plugin-0.7.1.tgz", diff --git a/package.json b/package.json index 8a45f2e..5e96ae9 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0" }, "dependencies": { + "@croct/content": "^1.0.0", "@croct/plug": "^0.16.2", "@croct/plug-react": "^0.9.0", "@croct/sdk": "^0.17.4", diff --git a/src/server/fetchContent.ts b/src/server/fetchContent.ts index a87a5eb..c4985a2 100644 --- a/src/server/fetchContent.ts +++ b/src/server/fetchContent.ts @@ -97,5 +97,10 @@ export function fetchContent( }, ...commonOptions, ...rest, + }).catch(error => { + const locale = options.preferredLocale ?? null; + const file = `${slotId}${locale !== null ? `.${locale}` : ''}.json`; + + return import(`@croct/content/${file}`).catch(() => Promise.reject(error)); }); }