summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiDeoo2024-05-01 17:51:26 +0200
committerGitHub2024-05-01 17:51:26 +0200
commit1c0fc3849771713d5a3e7a572bdbf1483ae5551b (patch)
treee6eabe4087c47a62875f5be1d6c46beee5e28087
parent0e4d4f4e503aafbaf674f6cde2347b4f4db164a7 (diff)
downloadIT.starlight-1c0fc3849771713d5a3e7a572bdbf1483ae5551b.tar.gz
IT.starlight-1c0fc3849771713d5a3e7a572bdbf1483ae5551b.tar.bz2
IT.starlight-1c0fc3849771713d5a3e7a572bdbf1483ae5551b.zip
Add missing `siteTitle` property to Starlight pages route data (#1812)
-rw-r--r--.changeset/six-ravens-tap.md5
-rw-r--r--packages/starlight/__tests__/basics/starlight-page-route-data.test.ts18
-rw-r--r--packages/starlight/utils/route-data.ts2
-rw-r--r--packages/starlight/utils/starlight-page.ts3
4 files changed, 26 insertions, 2 deletions
diff --git a/.changeset/six-ravens-tap.md b/.changeset/six-ravens-tap.md
new file mode 100644
index 00000000..aeac6efa
--- /dev/null
+++ b/.changeset/six-ravens-tap.md
@@ -0,0 +1,5 @@
+---
+'@astrojs/starlight': patch
+---
+
+Fixes an issue where the `siteTitle` property would not be set when using the `<StarlightPage />` component.
diff --git a/packages/starlight/__tests__/basics/starlight-page-route-data.test.ts b/packages/starlight/__tests__/basics/starlight-page-route-data.test.ts
index 95f611e2..e5164e04 100644
--- a/packages/starlight/__tests__/basics/starlight-page-route-data.test.ts
+++ b/packages/starlight/__tests__/basics/starlight-page-route-data.test.ts
@@ -1,4 +1,6 @@
import { assert, expect, test, vi } from 'vitest';
+import { generateRouteData } from '../../utils/route-data';
+import { routes } from '../../utils/routing';
import {
generateStarlightPageRouteData,
type StarlightPageProps,
@@ -46,6 +48,7 @@ test('adds data to route shape', async () => {
// Starlight pages respect the passed data.
expect(data.entry.data.title).toBe(starlightPageProps.frontmatter.title);
// Starlight pages get expected defaults.
+ expect(data.siteTitle).toBe('Basics');
expect(data.hasSidebar).toBe(true);
expect(data.headings).toEqual([]);
expect(data.entryMeta.dir).toBe('ltr');
@@ -494,3 +497,18 @@ test('strips unknown frontmatter properties', async () => {
});
expect('unknown' in data.entry.data).toBe(false);
});
+
+test('generates data with a similar root shape to regular route data', async () => {
+ const route = routes[0]!;
+ const data = generateRouteData({
+ props: { ...route, headings: [{ depth: 1, slug: 'heading-1', text: 'Heading 1' }] },
+ url: new URL('https://example.com'),
+ });
+
+ const starlightPageData = await generateStarlightPageRouteData({
+ props: starlightPageProps,
+ url: starlightPageUrl,
+ });
+
+ expect(Object.keys(data).sort()).toEqual(Object.keys(starlightPageData).sort());
+});
diff --git a/packages/starlight/utils/route-data.ts b/packages/starlight/utils/route-data.ts
index f9c6717d..a47e68f2 100644
--- a/packages/starlight/utils/route-data.ts
+++ b/packages/starlight/utils/route-data.ts
@@ -111,7 +111,7 @@ function getEditUrl({ entry, id, isFallback }: PageProps): URL | undefined {
}
/** Get the site title for a given language. **/
-function getSiteTitle(lang: string): string {
+export function getSiteTitle(lang: string): string {
const defaultLang = config.defaultLocale.lang as string;
if (lang && config.title[lang]) {
return config.title[lang] as string;
diff --git a/packages/starlight/utils/starlight-page.ts b/packages/starlight/utils/starlight-page.ts
index 88fbef87..e736457b 100644
--- a/packages/starlight/utils/starlight-page.ts
+++ b/packages/starlight/utils/starlight-page.ts
@@ -3,7 +3,7 @@ import { type ContentConfig, type SchemaContext } from 'astro:content';
import config from 'virtual:starlight/user-config';
import { parseWithFriendlyErrors } from './error-map';
import { stripLeadingAndTrailingSlashes } from './path';
-import { getToC, type PageProps, type StarlightRouteData } from './route-data';
+import { getSiteTitle, getToC, type PageProps, type StarlightRouteData } from './route-data';
import type { StarlightDocsEntry } from './routing';
import { slugToLocaleData, urlToSlug } from './slugs';
import { getPrevNextLinks, getSidebar } from './navigation';
@@ -223,6 +223,7 @@ export async function generateStarlightPageRouteData({
lastUpdated,
pagination: getPrevNextLinks(sidebar, config.pagination, entry.data),
sidebar,
+ siteTitle: getSiteTitle(localeData.lang),
slug,
toc: getToC({
...routeProps,