From 3adbdbbb71a4b3648984fa1028fa116d0aff9a7d Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Tue, 16 May 2023 16:44:13 +0200 Subject: Support displaying a custom logo in the nav bar (#51) --- .changeset/polite-numbers-check.md | 5 ++ .changeset/real-beers-drum.md | 5 ++ docs/astro.config.mjs | 5 ++ docs/src/assets/logo-dark.svg | 11 ++++ docs/src/assets/logo-light.svg | 11 ++++ docs/src/content/docs/environmental-impact.md | 3 +- docs/src/content/docs/reference/configuration.md | 23 ++++++++ docs/src/env.d.ts | 2 +- packages/starlight/components/Header.astro | 14 +---- packages/starlight/components/SiteTitle.astro | 74 ++++++++++++++++++++++++ packages/starlight/index.ts | 6 ++ packages/starlight/schemas/logo.ts | 28 +++++++++ packages/starlight/utils/user-config.ts | 4 ++ packages/starlight/virtual.d.ts | 8 +++ 14 files changed, 186 insertions(+), 13 deletions(-) create mode 100644 .changeset/polite-numbers-check.md create mode 100644 .changeset/real-beers-drum.md create mode 100644 docs/src/assets/logo-dark.svg create mode 100644 docs/src/assets/logo-light.svg create mode 100644 packages/starlight/components/SiteTitle.astro create mode 100644 packages/starlight/schemas/logo.ts diff --git a/.changeset/polite-numbers-check.md b/.changeset/polite-numbers-check.md new file mode 100644 index 00000000..dac1f975 --- /dev/null +++ b/.changeset/polite-numbers-check.md @@ -0,0 +1,5 @@ +--- +'@astrojs/starlight': patch +--- + +Support displaying a custom logo in the nav bar. diff --git a/.changeset/real-beers-drum.md b/.changeset/real-beers-drum.md new file mode 100644 index 00000000..d8aa21c7 --- /dev/null +++ b/.changeset/real-beers-drum.md @@ -0,0 +1,5 @@ +--- +"@astrojs/starlight": patch +--- + +All Starlight projects now use Astro’s experimental optimized asset support. diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs index 783555e7..c679b3a1 100644 --- a/docs/astro.config.mjs +++ b/docs/astro.config.mjs @@ -7,6 +7,11 @@ export default defineConfig({ integrations: [ starlight({ title: 'Starlight', + logo: { + light: '/src/assets/logo-light.svg', + dark: '/src/assets/logo-dark.svg', + replacesTitle: true, + }, editLink: { baseUrl: 'https://github.com/withastro/starlight/edit/main/docs/', }, diff --git a/docs/src/assets/logo-dark.svg b/docs/src/assets/logo-dark.svg new file mode 100644 index 00000000..8c5f408b --- /dev/null +++ b/docs/src/assets/logo-dark.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/docs/src/assets/logo-light.svg b/docs/src/assets/logo-light.svg new file mode 100644 index 00000000..c189f252 --- /dev/null +++ b/docs/src/assets/logo-light.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/docs/src/content/docs/environmental-impact.md b/docs/src/content/docs/environmental-impact.md index 2f1b81f3..86d5f397 100644 --- a/docs/src/content/docs/environmental-impact.md +++ b/docs/src/content/docs/environmental-impact.md @@ -20,7 +20,8 @@ With a good caching strategy, subsequent navigations can download as little as 1 ### Images -While Starlight provides a good baseline, images you add to your docs pages can quickly increase your page weight. Try enabling Astro’s [optimized asset support][assets] if your docs require a lot of images. +While Starlight provides a good baseline, images you add to your docs pages can quickly increase your page weight. +Starlight uses Astro’s [optimized asset support][assets] to optimize local images in your Markdown and MDX files. ### UI components diff --git a/docs/src/content/docs/reference/configuration.md b/docs/src/content/docs/reference/configuration.md index cddc7906..a3cd1902 100644 --- a/docs/src/content/docs/reference/configuration.md +++ b/docs/src/content/docs/reference/configuration.md @@ -19,6 +19,29 @@ Set the title for your website. Will be used in metadata and in the browser tab Set the description for your website. Used in metadata shared with search engines in the `` tag if `description` is not set in a page’s frontmatter. +### `logo` + +**type:** [`LogoConfig`](#logoconfig) + +Set a logo image to show in the navigation bar alongside or instead of the site title. You can either set a single `src` property or set separate image sources for `light` and `dark`. + +```js +starlight({ + logo: { + src: '/src/assets/my-logo.svg', + }, +}); +``` + +#### `LogoConfig` + +```ts +type LogoConfig = { alt?: string; replacesTitle?: boolean } & ( + | { src: string } + | { light: string; dark: string } +); +``` + ### `tableOfContents` **type:** `{ minHeadingLevel?: number; maxHeadingLevel?: number; }` diff --git a/docs/src/env.d.ts b/docs/src/env.d.ts index acef35f1..4170bce9 100644 --- a/docs/src/env.d.ts +++ b/docs/src/env.d.ts @@ -1,2 +1,2 @@ /// -/// +/// diff --git a/packages/starlight/components/Header.astro b/packages/starlight/components/Header.astro index 235ade3a..565f2503 100644 --- a/packages/starlight/components/Header.astro +++ b/packages/starlight/components/Header.astro @@ -1,9 +1,9 @@ --- -import config from 'virtual:starlight/user-config'; import LanguageSelect from './LanguageSelect.astro'; import Search from './Search.astro'; -import ThemeSelect from './ThemeSelect.astro'; +import SiteTitle from './SiteTitle.astro'; import SocialIcons from './SocialIcons.astro'; +import ThemeSelect from './ThemeSelect.astro'; interface Props { locale: string | undefined; @@ -11,7 +11,7 @@ interface Props { ---
- {config.title} +