-
-
Notifications
You must be signed in to change notification settings - Fork 832
Make social icon configuration more flexible
#3025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5e0c507
Create dedicated icon schema & refactor hero schema to use it
delucis b023b6e
New `social` config syntax
delucis 0ab7c5b
Update docs config for new syntax
delucis 077742e
Update examples config for new syntax
delucis ce338f4
Update docs
delucis 5edbed1
Fix use of social config in `Head.astro`
delucis 3b6597e
Fix tests
delucis 8bfccf9
Add changeset
delucis 23836fb
Merge branch 'main' into chris/social-links
delucis 8fa2f66
Add link to icon reference in social links type component
delucis 69ed1a6
Improve the error message for people whose `social` configuration is …
delucis 3178cc6
Merge branch 'main' into chris/social-links
delucis 957e584
Add test for `twitter:site` meta tag
delucis 21f2b82
Fix `<head>` logic to generate valid `twitter:site` meta tag
delucis 128a56e
Fix user config types for `social` schema
delucis bd5f90f
Merge branch 'main' into chris/social-links
delucis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- | ||
| '@astrojs/starlight': minor | ||
| --- | ||
|
|
||
| Makes `social` configuration more flexible. | ||
|
|
||
| ⚠️ **BREAKING CHANGE:** The `social` configuration option has changed syntax. You will need to update this in `astro.config.mjs` when upgrading. | ||
|
|
||
| Previously, a limited set of platforms were supported using a shorthand syntax with labels built in to Starlight. While convenient, this approach was less flexible and required dedicated code for each social platform added. | ||
|
|
||
| Now, you must specify the icon and label for each social link explicitly and you can use any of [Starlight’s built-in icons](https://starlight.astro.build/reference/icons/) for social links. | ||
|
|
||
| The following example shows updating the old `social` syntax to the new: | ||
|
|
||
| ```diff | ||
| - social: { | ||
| - github: 'https://github.com/withastro/starlight', | ||
| - discord: 'https://astro.build/chat', | ||
| - }, | ||
| + social: [ | ||
| + { icon: 'github', label: 'GitHub', href: 'https://github.com/withastro/starlight' }, | ||
| + { icon: 'discord', label: 'Discord', href: 'https://astro.build/chat' }, | ||
| + ], | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,4 @@ | ||
| --- | ||
| import { socialLinks } from '../../../packages/starlight/schemas/social'; | ||
| const socials = [...socialLinks].sort((a, b) => a.localeCompare(b, 'en')); | ||
| --- | ||
|
|
||
| <code>{`Partial<Record<${socials.map((social) => `'${social}'`).join(' | ')}, string>>`}</code> | ||
| <code set:text="Array<{ label: string; icon: string; href: string }>" /> | ||
delucis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,12 +84,13 @@ if (Astro.site) { | |
| } | ||
|
|
||
| // Link to Twitter account if set in Starlight config. | ||
| if (config.social?.twitter) { | ||
| const twitterLink = config.social?.find(({ icon }) => icon === 'twitter' || icon === 'x.com'); | ||
| if (twitterLink) { | ||
| headDefaults.push({ | ||
| tag: 'meta', | ||
| attrs: { | ||
| name: 'twitter:site', | ||
| content: new URL(config.social.twitter.url).pathname, | ||
| content: new URL(twitterLink.href).pathname, | ||
| }, | ||
| }); | ||
| } | ||
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { z } from 'astro/zod'; | ||
| import { Icons, type StarlightIcon } from '../components/Icons'; | ||
|
|
||
| const iconNames = Object.keys(Icons) as [StarlightIcon, ...StarlightIcon[]]; | ||
|
|
||
| /** String that matches the name of one of Starlight’s built-in icons. */ | ||
| export const IconSchema = () => z.enum(iconNames); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.