Skip to content

Commit 76e1a39

Browse files
Add query param for language in Arcade embed (#1114)
Add query param for language
1 parent df7c081 commit 76e1a39

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

.changeset/deep-spoons-throw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/integration-arcade': minor
3+
---
4+
5+
Add query param for language

integrations/arcade/src/arcade.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ export async function fetchArcadeOEmbedData(flowId: string): Promise<ArcadeOEmbe
3030
}
3131

3232
/**
33-
* Extract the Arcade flow ID from the embed URL.
33+
* Extract the Arcade flow ID and language from the embed URL.
3434
*/
3535
export function extractArcadeFlowFromURL(input: string): {
3636
flowId?: string;
37+
language?: string;
3738
} {
3839
const url = new URL(input);
3940
if (!['app.arcade.software', 'demo.arcade.software'].includes(url.hostname)) {
@@ -45,5 +46,6 @@ export function extractArcadeFlowFromURL(input: string): {
4546
return {};
4647
}
4748

48-
return { flowId: parts[2] };
49+
const language = url.searchParams.get('language') ?? undefined;
50+
return { flowId: parts[2], ...(language && { language }) };
4951
}

integrations/arcade/src/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type ArcadeRuntimeContext = RuntimeContext<ArcadeRuntimeEnvironment>;
1818
const embedBlock = createComponent<{
1919
flowId?: string;
2020
url?: string;
21+
language?: string;
2122
}>({
2223
componentId: 'embed',
2324

@@ -41,7 +42,7 @@ const embedBlock = createComponent<{
4142

4243
async render(element, context) {
4344
const { environment } = context;
44-
const { flowId, url } = element.props;
45+
const { flowId, url, language } = element.props;
4546

4647
if (!flowId) {
4748
return (
@@ -69,11 +70,12 @@ const embedBlock = createComponent<{
6970

7071
const embedData = await fetchArcadeOEmbedData(flowId);
7172
const aspectRatio = embedData.width / embedData.height;
73+
const embedUrl = `https://demo.arcade.software/${flowId}?embed${language ? `&language=${encodeURIComponent(language)}` : ''}`;
7274
return (
7375
<block>
7476
<webframe
7577
source={{
76-
url: `https://demo.arcade.software/${flowId}?embed`,
78+
url: embedUrl,
7779
}}
7880
aspectRatio={aspectRatio}
7981
/>

0 commit comments

Comments
 (0)