Skip to content

Commit d0ebd12

Browse files
authored
feat(link): support the changes from Strapi 5.30.x (#21)
1 parent 5fa0e11 commit d0ebd12

5 files changed

Lines changed: 39 additions & 17 deletions

File tree

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v20.12.0
1+
v20

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sensinum/astro-strapi-blocks",
3-
"version": "1.2.4",
3+
"version": "1.2.5",
44
"description": "Astro components for Strapi Block Field",
55
"keywords": ["astro", "strapi", "blocks", "components", "astro-component", "withastro", "astro-loader", "content-layer", "astro-integration"],
66
"type": "module",

src/components/blocks/items/StrapiBlockLinkItem.astro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import type { StrapiBlockTextItem, StrapiBlockTextNodePartial } from "../../../t
66
77
type Props = {
88
url: string;
9+
target?: string;
10+
rel?: string;
911
class?: string;
1012
data: Array<StrapiBlockTextItem>;
1113
theme: StrapiBlockTextNodePartial;
1214
};
1315
14-
const { data, url, class: classes = "", theme = {} as StrapiBlockTextNodePartial } = Astro.props;
16+
const { data, url, target = "", rel = "", class: classes = "", theme = {} as StrapiBlockTextNodePartial } = Astro.props;
1517
1618
---
1719

@@ -20,6 +22,8 @@ const { data, url, class: classes = "", theme = {} as StrapiBlockTextNodePartial
2022
<a
2123
class={classes}
2224
href={url}
25+
target={target}
26+
rel={rel}
2327
>
2428
{data.map((item: StrapiBlockTextItem) => (
2529
<Text data={item} theme={theme} />
Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
11
---
2-
import Text from './StrapiBlockTextItem.astro';
3-
import Link from './StrapiBlockLinkItem.astro';
4-
import type { StrapiBlockTextItem, StrapiBlockLinkItem, StrapiBlockNode, StrapiBlockTextNodePartial } from '../../../types';
2+
import Text from "./StrapiBlockTextItem.astro";
3+
import Link from "./StrapiBlockLinkItem.astro";
4+
import type {
5+
StrapiBlockTextItem,
6+
StrapiBlockLinkItem,
7+
StrapiBlockNode,
8+
StrapiBlockTextNodePartial,
9+
} from "../../../types";
510
611
type Props = {
712
data: Array<StrapiBlockNode>;
813
theme: StrapiBlockTextNodePartial;
9-
}
14+
};
1015
1116
const { data, theme = {} as StrapiBlockTextNodePartial } = Astro.props;
12-
1317
---
14-
{ data.map((item: StrapiBlockNode) => {
15-
if ((item as StrapiBlockTextItem)?.text) {
16-
return (<Text data={item as StrapiBlockTextItem} theme={theme} />);
17-
}
1818

19-
if ((item as StrapiBlockLinkItem)?.url) {
20-
return (<Link class={theme.link.join(' ')} url={(item as StrapiBlockLinkItem)?.url} data={(item as StrapiBlockLinkItem).children} theme={theme} />);
21-
}
19+
{
20+
data.map((item: StrapiBlockNode) => {
21+
if ((item as StrapiBlockTextItem)?.text) {
22+
return <Text data={item as StrapiBlockTextItem} theme={theme} />;
23+
}
2224

23-
return null;
24-
}) }
25+
if ((item as StrapiBlockLinkItem)?.url) {
26+
return (
27+
<Link
28+
class={theme.link.join(" ")}
29+
url={(item as StrapiBlockLinkItem)?.url}
30+
target={(item as StrapiBlockLinkItem)?.target}
31+
rel={(item as StrapiBlockLinkItem)?.rel}
32+
data={(item as StrapiBlockLinkItem).children}
33+
theme={theme}
34+
/>
35+
);
36+
}
37+
38+
return null;
39+
})
40+
}

src/types/strapi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export type StrapiBlockTextItem = {
3131

3232
export type StrapiBlockLinkItem = {
3333
url: string;
34+
target?: string;
35+
rel?: string;
3436
type: 'link';
3537
children: Array<StrapiBlockTextItem>;
3638
};

0 commit comments

Comments
 (0)