From 2cb35782dace67c7c418a31005419fa95493b3d3 Mon Sep 17 00:00:00 2001 From: Timo Kössler Date: Fri, 16 Feb 2024 23:31:14 +0100 Subject: 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 --- .changeset/eighty-icons-leave.md | 5 +++++ docs/src/content/docs/es/reference/frontmatter.md | 3 +++ docs/src/content/docs/fr/reference/frontmatter.md | 3 +++ docs/src/content/docs/it/reference/frontmatter.md | 3 +++ docs/src/content/docs/ja/reference/frontmatter.md | 3 +++ docs/src/content/docs/ko/reference/frontmatter.md | 3 +++ docs/src/content/docs/pt-br/reference/frontmatter.md | 3 +++ docs/src/content/docs/reference/frontmatter.md | 3 +++ docs/src/content/docs/zh-cn/reference/frontmatter.md | 3 +++ packages/starlight/components/CallToAction.astro | 5 ++++- packages/starlight/schemas/hero.ts | 2 ++ 11 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .changeset/eighty-icons-leave.md 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; }>; } ``` 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; }>; } ``` 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; }>; } ``` 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; }>; } ``` 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; }>; } ``` 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; }>; } ``` 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; }>; } ``` 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; }>; } ``` 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, 'href'>; } const { link, variant, icon } = Astro.props; +const { class: customClass, ...attrs } = Astro.props.attrs || {}; --- - + {icon?.type === 'icon' && } {icon?.type === 'raw' && } 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([]), -- cgit