summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Kössler2024-02-16 23:31:14 +0100
committerGitHub2024-02-16 23:31:14 +0100
commit2cb35782dace67c7c418a31005419fa95493b3d3 (patch)
tree1b92f47afd757d5d1959fe8b6bda14f21b9037d1
parente7427797a9a784c75acfcd4d89551eed36c32956 (diff)
downloadIT.starlight-2cb35782dace67c7c418a31005419fa95493b3d3.tar.gz
IT.starlight-2cb35782dace67c7c418a31005419fa95493b3d3.tar.bz2
IT.starlight-2cb35782dace67c7c418a31005419fa95493b3d3.zip
feat: Add html attributes to hero action links (#1485)
* feat: Add html attributes to hero action links * Implement requested changes * Discard changes to docs/src/content/docs/de/reference/frontmatter.md * Discard changes to docs/src/content/docs/id/reference/frontmatter.md --------- Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
-rw-r--r--.changeset/eighty-icons-leave.md5
-rw-r--r--docs/src/content/docs/es/reference/frontmatter.md3
-rw-r--r--docs/src/content/docs/fr/reference/frontmatter.md3
-rw-r--r--docs/src/content/docs/it/reference/frontmatter.md3
-rw-r--r--docs/src/content/docs/ja/reference/frontmatter.md3
-rw-r--r--docs/src/content/docs/ko/reference/frontmatter.md3
-rw-r--r--docs/src/content/docs/pt-br/reference/frontmatter.md3
-rw-r--r--docs/src/content/docs/reference/frontmatter.md3
-rw-r--r--docs/src/content/docs/zh-cn/reference/frontmatter.md3
-rw-r--r--packages/starlight/components/CallToAction.astro5
-rw-r--r--packages/starlight/schemas/hero.ts2
11 files changed, 35 insertions, 1 deletions
diff --git a/.changeset/eighty-icons-leave.md b/.changeset/eighty-icons-leave.md
new file mode 100644
index 00000000..f6c62a60
--- /dev/null
+++ b/.changeset/eighty-icons-leave.md
@@ -0,0 +1,5 @@
+---
+'@astrojs/starlight': minor
+---
+
+Add support for setting html attributes of hero action links
diff --git a/docs/src/content/docs/es/reference/frontmatter.md b/docs/src/content/docs/es/reference/frontmatter.md
index cfc959de..ddc07b2b 100644
--- a/docs/src/content/docs/es/reference/frontmatter.md
+++ b/docs/src/content/docs/es/reference/frontmatter.md
@@ -119,6 +119,8 @@ hero:
- text: View on GitHub
link: https://github.com/astronaut/my-project
icon: external
+ attrs:
+ rel: me
---
```
@@ -166,6 +168,7 @@ interface HeroConfig {
link: string;
variant: 'primary' | 'secondary' | 'minimal';
icon: string;
+ attrs?: Record<string, string | number | boolean>;
}>;
}
```
diff --git a/docs/src/content/docs/fr/reference/frontmatter.md b/docs/src/content/docs/fr/reference/frontmatter.md
index 5043ee80..5f8e55b0 100644
--- a/docs/src/content/docs/fr/reference/frontmatter.md
+++ b/docs/src/content/docs/fr/reference/frontmatter.md
@@ -119,6 +119,8 @@ hero:
- text: Voir sur GitHub
link: https://github.com/astronaut/my-project
icon: external
+ attrs:
+ rel: me
---
```
@@ -166,6 +168,7 @@ interface HeroConfig {
link: string;
variant: 'primary' | 'secondary' | 'minimal';
icon: string;
+ attrs?: Record<string, string | number | boolean>;
}>;
}
```
diff --git a/docs/src/content/docs/it/reference/frontmatter.md b/docs/src/content/docs/it/reference/frontmatter.md
index ba94e441..844ae349 100644
--- a/docs/src/content/docs/it/reference/frontmatter.md
+++ b/docs/src/content/docs/it/reference/frontmatter.md
@@ -119,6 +119,8 @@ hero:
- text: Vedi su GitHub
link: https://github.com/astronaut/my-project
icon: external
+ attrs:
+ rel: me
---
```
@@ -166,6 +168,7 @@ interface HeroConfig {
link: string;
variant: 'primary' | 'secondary' | 'minimal';
icon: string;
+ attrs?: Record<string, string | number | boolean>;
}>;
}
```
diff --git a/docs/src/content/docs/ja/reference/frontmatter.md b/docs/src/content/docs/ja/reference/frontmatter.md
index bb82e7f2..3f3391f5 100644
--- a/docs/src/content/docs/ja/reference/frontmatter.md
+++ b/docs/src/content/docs/ja/reference/frontmatter.md
@@ -116,6 +116,8 @@ hero:
- text: GitHubで見る
link: https://github.com/astronaut/my-project
icon: external
+ attrs:
+ rel: me
---
```
@@ -163,6 +165,7 @@ interface HeroConfig {
link: string;
variant: 'primary' | 'secondary' | 'minimal';
icon: string;
+ attrs?: Record<string, string | number | boolean>;
}>;
}
```
diff --git a/docs/src/content/docs/ko/reference/frontmatter.md b/docs/src/content/docs/ko/reference/frontmatter.md
index 5c1bb88c..7ff21f61 100644
--- a/docs/src/content/docs/ko/reference/frontmatter.md
+++ b/docs/src/content/docs/ko/reference/frontmatter.md
@@ -117,6 +117,8 @@ hero:
- text: Github에서 보기
link: https://github.com/astronaut/my-project
icon: external
+ attrs:
+ rel: me
---
```
@@ -164,6 +166,7 @@ interface HeroConfig {
link: string;
variant: 'primary' | 'secondary' | 'minimal';
icon: string;
+ attrs?: Record<string, string | number | boolean>;
}>;
}
```
diff --git a/docs/src/content/docs/pt-br/reference/frontmatter.md b/docs/src/content/docs/pt-br/reference/frontmatter.md
index 72a181c1..3218f13c 100644
--- a/docs/src/content/docs/pt-br/reference/frontmatter.md
+++ b/docs/src/content/docs/pt-br/reference/frontmatter.md
@@ -119,6 +119,8 @@ hero:
- text: Veja no GitHub
link: https://github.com/astronaut/meu-projeto
icon: external
+ attrs:
+ rel: me
---
```
@@ -166,6 +168,7 @@ interface HeroConfig {
link: string;
variant: 'primary' | 'secondary' | 'minimal';
icon: string;
+ attrs?: Record<string, string | number | boolean>;
}>;
}
```
diff --git a/docs/src/content/docs/reference/frontmatter.md b/docs/src/content/docs/reference/frontmatter.md
index 8e11bea0..89f3b43c 100644
--- a/docs/src/content/docs/reference/frontmatter.md
+++ b/docs/src/content/docs/reference/frontmatter.md
@@ -119,6 +119,8 @@ hero:
- text: View on GitHub
link: https://github.com/astronaut/my-project
icon: external
+ attrs:
+ rel: me
---
```
@@ -166,6 +168,7 @@ interface HeroConfig {
link: string;
variant: 'primary' | 'secondary' | 'minimal';
icon: string;
+ attrs?: Record<string, string | number | boolean>;
}>;
}
```
diff --git a/docs/src/content/docs/zh-cn/reference/frontmatter.md b/docs/src/content/docs/zh-cn/reference/frontmatter.md
index c6551fcd..0691ce24 100644
--- a/docs/src/content/docs/zh-cn/reference/frontmatter.md
+++ b/docs/src/content/docs/zh-cn/reference/frontmatter.md
@@ -118,6 +118,8 @@ hero:
- text: 在 GitHub 上查看
link: https://github.com/astronaut/my-project
icon: external
+ attrs:
+ rel: me
---
```
@@ -165,6 +167,7 @@ interface HeroConfig {
link: string;
variant: 'primary' | 'secondary' | 'minimal';
icon: string;
+ attrs?: Record<string, string | number | boolean>;
}>;
}
```
diff --git a/packages/starlight/components/CallToAction.astro b/packages/starlight/components/CallToAction.astro
index 44ef78de..591ffab0 100644
--- a/packages/starlight/components/CallToAction.astro
+++ b/packages/starlight/components/CallToAction.astro
@@ -1,4 +1,5 @@
---
+import type { HTMLAttributes } from 'astro/types';
import Icon from '../user-components/Icon.astro';
import type { Icons } from './Icons';
@@ -6,12 +7,14 @@ interface Props {
variant: 'primary' | 'secondary' | 'minimal';
link: string;
icon?: undefined | { type: 'icon'; name: keyof typeof Icons } | { type: 'raw'; html: string };
+ attrs?: Omit<HTMLAttributes<'a'>, 'href'>;
}
const { link, variant, icon } = Astro.props;
+const { class: customClass, ...attrs } = Astro.props.attrs || {};
---
-<a class:list={['sl-flex action', variant]} href={link}>
+<a class:list={['sl-flex action', variant, customClass]} href={link} {...attrs}>
<slot />
{icon?.type === 'icon' && <Icon name={icon.name} size="1.5rem" />}
{icon?.type === 'raw' && <Fragment set:html={icon.html} />}
diff --git a/packages/starlight/schemas/hero.ts b/packages/starlight/schemas/hero.ts
index e1b5611c..0c335124 100644
--- a/packages/starlight/schemas/hero.ts
+++ b/packages/starlight/schemas/hero.ts
@@ -64,6 +64,8 @@ export const HeroSchema = ({ image }: SchemaContext) =>
: ({ type: 'raw', html: icon } as const);
})
.optional(),
+ /** HTML attributes to add to the link */
+ attrs: z.record(z.union([z.string(), z.number(), z.boolean()])).optional(),
})
.array()
.default([]),