Skip to content

Commit 2a3e2eb

Browse files
committed
feat: allow images in the accordion module
1 parent 9a0fea6 commit 2a3e2eb

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

app/components/modules/Accordion.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
class="overflow-hidden data-[state=open]:animate-slideDown data-[state=closed]:animate-slideUp"
3232
>
3333
<div class="pb-4 type-body">
34-
<RichTextRenderer :json="item.copy?.json" />
34+
<RichTextRenderer
35+
:json="item.copy?.json"
36+
:assets="getEmbeddedAssets(item.copy?.links)"
37+
/>
3538
</div>
3639
</AccordionContent>
3740
</AccordionItem>

app/components/modules/CenterText.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,12 @@
1212
</template>
1313

1414
<script setup lang="ts">
15-
import type { EmbeddedAsset } from "~/components/render/RichTextRenderer.vue";
1615
import type { ModuleProps } from "~/types/module";
1716
import type { CenterTextFragment } from "~~/shared/types/graphql";
1817
1918
const { data } = defineProps<ModuleProps<CenterTextFragment>>();
2019
21-
const embeddedAssets = computed((): EmbeddedAsset[] => {
22-
const blockAssets = data?.text?.links?.assets?.block;
23-
if (!blockAssets?.length) return [];
24-
return blockAssets.filter(
25-
(asset): asset is EmbeddedAsset => asset !== null && asset.sys?.id != null,
26-
);
20+
const embeddedAssets = computed(() => {
21+
return getEmbeddedAssets(data?.text?.links);
2722
});
2823
</script>

app/utils/helpers.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { EmbeddedAsset } from "~/components/render/RichTextRenderer.vue";
12
import type { Pagination } from "~~/shared/types/Pagination";
23

34
export const ariaCurrent = (route: string, currentRoute: string) => {
@@ -36,3 +37,12 @@ export const formatRelationshipType = (type: string) => {
3637
return type;
3738
}
3839
};
40+
41+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
42+
export const getEmbeddedAssets = (links: any): EmbeddedAsset[] => {
43+
const blockAssets = (links?.assets?.block ?? []) as (EmbeddedAsset | null)[];
44+
if (!blockAssets?.length) return [];
45+
return blockAssets.filter(
46+
(asset): asset is EmbeddedAsset => asset !== null && asset.sys?.id != null,
47+
);
48+
};

server/graphql/fragments/title-copy.fragment.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ export const TITLE_COPY_FRAGMENT = gql`
55
title
66
copy {
77
json
8+
links {
9+
assets {
10+
block {
11+
sys {
12+
id
13+
}
14+
...Image
15+
}
16+
}
17+
}
818
}
919
}
1020
`;

0 commit comments

Comments
 (0)