From a8eeae7a1e24d1ccab3348d68e75c71b696f3e13 Mon Sep 17 00:00:00 2001 From: Vitor Ayres Date: Tue, 7 Nov 2023 13:45:24 -0300 Subject: [PATCH 01/22] i18n(pt-BR): Update `reference/configuration.mdx` (#1050) --- docs/src/content/docs/pt-br/reference/configuration.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/content/docs/pt-br/reference/configuration.mdx b/docs/src/content/docs/pt-br/reference/configuration.mdx index 390cbb3dfd9..df932ec3346 100644 --- a/docs/src/content/docs/pt-br/reference/configuration.mdx +++ b/docs/src/content/docs/pt-br/reference/configuration.mdx @@ -183,10 +183,10 @@ sidebar: [ type SidebarItem = { label: string; translations?: Record; + badge?: string | BadgeConfig; } & ( | { link: string; - badge?: string | BadgeConfig; attrs?: Record; } | { items: SidebarItem[]; collapsed?: boolean } From 5e51300c01b49e15bdf61be3cea97099237c21b1 Mon Sep 17 00:00:00 2001 From: Paul Valladares <85648028+dreyfus92@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:31:55 -0600 Subject: [PATCH 02/22] i18n(es): Update `i18n` (#1028) * update: update i18n * Apply suggestions from kevin's review Co-authored-by: Kevin Zuniga Cuellar <46791833+kevinzunigacuellar@users.noreply.github.com> --------- Co-authored-by: Kevin Zuniga Cuellar <46791833+kevinzunigacuellar@users.noreply.github.com> --- docs/src/content/docs/es/guides/i18n.mdx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/src/content/docs/es/guides/i18n.mdx b/docs/src/content/docs/es/guides/i18n.mdx index 0a359b4ef5a..7274ab75045 100644 --- a/docs/src/content/docs/es/guides/i18n.mdx +++ b/docs/src/content/docs/es/guides/i18n.mdx @@ -140,7 +140,11 @@ Si no hay una traducción disponible para un idioma, Starlight mostrará a los l ## Traduce la UI de Starlight -Starlight proporciona de forma predeterminada traducciones para los textos utilizados en la UI al inglés, checo, francés, alemán, italiano, japonés, holandés, portugués, danés, español, turco, árabe, noruego, farsi, hebreo, chino simplificado, coreano, indonesio, ruso, sueco, ucraniano y vietnamita. También damos la bienvenida a [contribuciones para agregar más idiomas predeterminados](https://github.com/withastro/starlight/blob/main/CONTRIBUTING.md). +Además de alojar archivos de contenido traducidos, Starlight te permite traducir las etiquetas de UI predeterminadas (p. ej. el encabezado "En esta página" en la tabla de contenidos) para que tus lectores puedan experimentar tu sitio completamente en el idioma seleccionado. + +Inglés, checo, francés, alemán, italiano, japonés, portugués, holandés, danés, español, turco, árabe, noruego, farsi, hebreo, chino simplificado, coreano, indonesio, ruso, sueco, ucraniano, vietnamita y gallego se proporcionan de forma predeterminada, y damos la bienvenida a [contribuciones para agregar más idiomas predeterminados](https://github.com/withastro/starlight/blob/main/CONTRIBUTING.md). + +Puedes proprocionar traducciones para idiomas adicionales, o editar nuestras etiquetas predeterminadas, a través de la colección de datos `i18n`. 1. Configura la colección de datos `i18n` en `src/content/config.ts` si aún no está configurada: From 0c9d9732650c8028bdcba1b1825944f3ec534ed2 Mon Sep 17 00:00:00 2001 From: Paul Valladares <85648028+dreyfus92@users.noreply.github.com> Date: Wed, 8 Nov 2023 10:39:18 -0600 Subject: [PATCH 03/22] i18n(es): Update `frontmatter` (#1030) --- .../content/docs/es/reference/frontmatter.md | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/docs/src/content/docs/es/reference/frontmatter.md b/docs/src/content/docs/es/reference/frontmatter.md index 61a528327ec..b2a8cb6581b 100644 --- a/docs/src/content/docs/es/reference/frontmatter.md +++ b/docs/src/content/docs/es/reference/frontmatter.md @@ -111,20 +111,44 @@ hero: --- ``` +Puedes mostrar diferentes versiones de la imagen hero en los modos claro y oscuro. + +```md +--- +hero: + image: + alt: Un logotipo brillante, de colores brillantes + dark: ../../assets/logo-dark.png + light: ../../assets/logo-light.png +--- +``` + #### `HeroConfig` ```ts interface HeroConfig { title?: string; tagline?: string; - image?: { - alt?: string; - // Ruta relativa a una imagen en tu repositorio. - file?: string; - // HTML crudo para usar en el espacio de la imagen. - // Podría ser una etiqueta `` personalizada o un `` en línea. - html?: string; - }; + image?: + | { + // Ruta relativa a una imagen en tu repositorio. + file: string; + // Texto alternativo para hacer que la imagen sea accesible a la tecnología de asistencia + alt?: string; + } + | { + // Ruta relativa a una imagen en tu repositorio para usar en el modo oscuro. + dark: string; + // Ruta relativa a una imagen en tu repositorio para usar en el modo claro. + light: string; + // Texto alternativo para hacer que la imagen sea accesible a la tecnología de asistencia + alt?: string; + } + | { + // HTML crudo para usar en el espacio de la imagen. + // Podría ser una etiqueta `` personalizada o un `` en línea. + html: string; + }; actions?: Array<{ text: string; link: string; From 5e0aed9e404281512b423548d00092e2bcdcd1e4 Mon Sep 17 00:00:00 2001 From: Vitor Ayres Date: Wed, 8 Nov 2023 21:29:07 -0300 Subject: [PATCH 04/22] i18n(pt-BR): Update `reference/frontmatter.md` (#1051) * Update frontmatter.md #280 * Update frontmatter.md * Update frontmatter.md * improve wording --- .../docs/pt-br/reference/frontmatter.md | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/docs/src/content/docs/pt-br/reference/frontmatter.md b/docs/src/content/docs/pt-br/reference/frontmatter.md index ed8d73d07e4..1e38930a6df 100644 --- a/docs/src/content/docs/pt-br/reference/frontmatter.md +++ b/docs/src/content/docs/pt-br/reference/frontmatter.md @@ -111,20 +111,44 @@ hero: --- ``` +Você pode exibir diferentes versões da imagem hero no modo claro e escuro. + +```md +--- +hero: + image: + alt: Um logo brilhante e colorido + dark: ../../assets/logo-escuro.png + light: ../../assets/logo-claro.png +--- +``` + #### `HeroConfig` ```ts interface HeroConfig { title?: string; tagline?: string; - image?: { - alt?: string; - // Caminho relativo a uma imagem no seu repositório. - file?: string; - // HTML bruto para utilizar no slot de imagem. - // Pode ser uma tag `` customizada ou um `` inline. - html?: string; - }; + image?: + | { + // Caminho relativo de uma imagem no seu repositório. + file: string; + // Texto alternativo para tornar a imagem acessível à tecnologia assistiva + alt?: string; + } + | { + // Caminho relativo de uma imagem em seu repositório para ser usada no modo escuro. + dark: string; + // Caminho relativo de uma imagem em seu repositório para ser usada no modo claro. + light: string; + // Texto alternativo para tornar a imagem acessível à tecnologia assistiva + alt?: string; + } + | { + // HTML bruto para utilizar no slot de imagem. + // Pode ser uma tag `` personalizada ou um `` inline. + html: string; + }; actions?: Array<{ text: string; link: string; From 1c1acd386bb5f0e42eb7b7b0d77841f165907407 Mon Sep 17 00:00:00 2001 From: trueberryless <99918022+trueberryless@users.noreply.github.com> Date: Thu, 9 Nov 2023 09:54:57 +0100 Subject: [PATCH 05/22] i18n(de): Update translation of another file into German (#1057) Co-authored-by: HiDeoo <494699+HiDeoo@users.noreply.github.com> --- docs/src/content/docs/de/reference/configuration.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/content/docs/de/reference/configuration.mdx b/docs/src/content/docs/de/reference/configuration.mdx index 306ed7dce4b..abc6711b866 100644 --- a/docs/src/content/docs/de/reference/configuration.mdx +++ b/docs/src/content/docs/de/reference/configuration.mdx @@ -181,10 +181,10 @@ sidebar: [ type SidebarItem = { label: string; translations?: Record; + badge?: string | BadgeConfig; } & ( | { link: string; - badge?: string | BadgeConfig; attrs?: Record; } | { items: SidebarItem[]; collapsed?: boolean } From dea8490b3c4664c5e9286afa3f8cd34b2a78ee56 Mon Sep 17 00:00:00 2001 From: trueberryless <99918022+trueberryless@users.noreply.github.com> Date: Thu, 9 Nov 2023 11:29:24 +0100 Subject: [PATCH 06/22] i18n(de): Update translation of authoring-content.md into German (#1053) * i18n(de): Update translation of authoring-content.md into German * Update docs/src/content/docs/de/guides/authoring-content.md Co-authored-by: Chris Swithinbank --------- Co-authored-by: Chris Swithinbank --- docs/src/content/docs/de/guides/authoring-content.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/src/content/docs/de/guides/authoring-content.md b/docs/src/content/docs/de/guides/authoring-content.md index e376af0fa08..88ffcf85b6f 100644 --- a/docs/src/content/docs/de/guides/authoring-content.md +++ b/docs/src/content/docs/de/guides/authoring-content.md @@ -207,3 +207,7 @@ Lange, einzeilige Codeblöcke sollten nicht umgebrochen werden. Sie sollten hori ## Andere allgemeine Markdown-Funktionen Starlight unterstützt alle anderen Markdown-Autorensyntaxen, wie Listen und Tabellen. Einen schnellen Überblick über alle Markdown-Syntaxelemente findest du im [Markdown Cheat Sheet von The Markdown Guide](https://www.markdownguide.org/cheat-sheet/). + +## Erweiterte Markdown- und MDX-Konfiguration + +Starlight verwendet Astros Markdown- und MDX-Renderer, der auf remark und rehype aufbaut. Du kannst eine Unterstützung für eigene Syntax und Verhalten hinzufügen, indem du `remarkPlugins` oder `rehypePlugins` in deiner Astro-Konfigurationsdatei hinzufügst. Weitere Informationen findest du unter ["Markdown konfigurieren"] (https://docs.astro.build/de/guides/markdown-content/#markdown-konfigurieren) in der Astro-Dokumentation. From f77c6c0d6c1ac07c3c98d2b247d4c28f9d971003 Mon Sep 17 00:00:00 2001 From: trueberryless <99918022+trueberryless@users.noreply.github.com> Date: Thu, 9 Nov 2023 18:34:34 +0100 Subject: [PATCH 07/22] i18n(de): Update translating of `i18n.mdx` into German (#1054) Co-authored-by: HiDeoo <494699+HiDeoo@users.noreply.github.com> --- docs/src/content/docs/de/guides/i18n.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/content/docs/de/guides/i18n.mdx b/docs/src/content/docs/de/guides/i18n.mdx index 46478e5d25b..40ffae09356 100644 --- a/docs/src/content/docs/de/guides/i18n.mdx +++ b/docs/src/content/docs/de/guides/i18n.mdx @@ -143,7 +143,7 @@ Wenn für eine Sprache noch keine Übersetzung verfügbar ist, zeigt Starlight d Starlight bietet nicht nur übersetzte Inhaltsdateien, sondern auch die Möglichkeit, die Standard-Benutzeroberfläche zu übersetzen (z.B. die Überschrift "Auf dieser Seite" im Inhaltsverzeichnis), so dass deine Leser deine Website vollständig in der ausgewählten Sprache erleben können. -Englisch, Tschechisch, Französisch, Deutsch, Italienisch, Japanisch, Portugiesisch, Niederländisch, Dänisch, Spanisch, Türkisch, Arabisch, Norwegisch, Farsi, Hebräisch, Chinesisch (vereinfacht), Koreanisch, Indonesisch, Russisch, Schwedisch, Ukrainisch und Vietnamesisch werden standardmäßig übersetzt, und wir freuen uns über [Beiträge zur Aufnahme weiterer Standardsprachen](https://github.com/withastro/starlight/blob/main/CONTRIBUTING.md). +Englisch, Tschechisch, Französisch, Deutsch, Italienisch, Japanisch, Portugiesisch, Niederländisch, Dänisch, Spanisch, Türkisch, Arabisch, Norwegisch, Farsi, Hebräisch, Chinesisch (vereinfacht), Koreanisch, Indonesisch, Russisch, Schwedisch, Ukrainisch, Vietnamesisch und Galizisch werden standardmäßig übersetzt, und wir freuen uns über [Beiträge zur Aufnahme weiterer Standardsprachen](https://github.com/withastro/starlight/blob/main/CONTRIBUTING.md). Du kannst Übersetzungen für zusätzliche Sprachen, die du unterstützt, über die `i18n` Datensammlung zur Verfügung stellen - oder unsere Standardbezeichnungen überschreiben. From 8e8f03532f470269e8cdda3f3bcfbbae15fbe235 Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Fri, 10 Nov 2023 23:07:14 +0100 Subject: [PATCH 08/22] Migrate docs site to Vercel (#795) Co-authored-by: Tony Sullivan --- .gitignore | 3 +++ docs/astro.config.mjs | 9 +++++++-- docs/public/_headers | 4 ---- docs/public/_redirects | 3 --- docs/vercel.json | 22 ++++++++++++++++++++++ 5 files changed, 32 insertions(+), 9 deletions(-) delete mode 100644 docs/public/_headers delete mode 100644 docs/public/_redirects create mode 100644 docs/vercel.json diff --git a/.gitignore b/.gitignore index 9f880cb7098..e790eb4de4e 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ pnpm-debug.log* # Vitest __coverage__/ + +# Vercel output +.vercel \ No newline at end of file diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs index 37ecec8bd16..2405fd09de4 100644 --- a/docs/astro.config.mjs +++ b/docs/astro.config.mjs @@ -16,7 +16,13 @@ export const locales = { ru: { label: 'Русский', lang: 'ru' }, }; -const site = 'https://starlight.astro.build/'; +/* https://vercel.com/docs/projects/environment-variables/system-environment-variables#system-environment-variables */ +const VERCEL_PREVIEW_SITE = + process.env.VERCEL_ENV !== 'production' && + process.env.VERCEL_URL && + `https://${process.env.VERCEL_URL}`; + +const site = VERCEL_PREVIEW_SITE || 'https://starlight.astro.build/'; export default defineConfig({ site, @@ -175,7 +181,6 @@ export default defineConfig({ autogenerate: { directory: 'reference' }, }, ], - lastUpdated: true, }), ], }); diff --git a/docs/public/_headers b/docs/public/_headers deleted file mode 100644 index aaa51ef2a6e..00000000000 --- a/docs/public/_headers +++ /dev/null @@ -1,4 +0,0 @@ -/_astro/* - Cache-Control: public - Cache-Control: max-age=604800 - Cache-Control: immutable diff --git a/docs/public/_redirects b/docs/public/_redirects deleted file mode 100644 index a7aa40820f3..00000000000 --- a/docs/public/_redirects +++ /dev/null @@ -1,3 +0,0 @@ -/ph/* https://astro-houston-ph.pages.dev/ph/:splat 200 -/zh/* /zh-cn/:splat -/:lang/* /:lang/404/ 404 diff --git a/docs/vercel.json b/docs/vercel.json new file mode 100644 index 00000000000..e5259e57302 --- /dev/null +++ b/docs/vercel.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://openapi.vercel.sh/vercel.json", + + "routes": [ + { + "src": "^/_astro/(.*)$", + "headers": { "cache-control": "public, max-age=31536000, immutable" }, + "continue": true + }, + + { "src": "/(ph$|ph/)(.*)", "dest": "https://astro-houston-ph.pages.dev/ph/$2" }, + + { "src": "(.*)/([^./]+)$", "dest": "$1/$2/", "status": 301 }, + { "src": "(.*)/index.html$", "dest": "$1/", "status": 301 }, + + { "handle": "filesystem" }, + + { "src": "/zh/(.*)", "dest": "/zh-cn/$1", "status": 301 }, + + { "src": "/(?[^/]*)/(.*)", "dest": "/$lang/404/", "status": 404 } + ] +} From 60edb22374a73bc0d02dbe2e26c2566d6400a3e8 Mon Sep 17 00:00:00 2001 From: HiDeoo <494699+HiDeoo@users.noreply.github.com> Date: Sun, 12 Nov 2023 12:11:21 +0100 Subject: [PATCH 09/22] Fix `test-utils.ts` error (#1059) --- packages/starlight/__tests__/test-utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/starlight/__tests__/test-utils.ts b/packages/starlight/__tests__/test-utils.ts index b9b0e8991af..96ff4f649e9 100644 --- a/packages/starlight/__tests__/test-utils.ts +++ b/packages/starlight/__tests__/test-utils.ts @@ -17,6 +17,7 @@ const frontmatterSchema = docsSchema()({ z.literal('webp'), z.literal('gif'), z.literal('svg'), + z.literal('avif'), ]), }), }); From 0af505081968c2519e5d028d15d4c18e7a215240 Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Thu, 16 Nov 2023 22:27:18 +0100 Subject: [PATCH 10/22] Expand testing (#1045) --- .../__tests__/basics/sitemap.test.ts | 40 ++++++++ .../__tests__/remark-rehype/asides.test.ts | 87 ++++++++++++++++++ .../remark-rehype/asides/generates-aside.html | 1 + .../asides/handles-complex-children.html | 2 + .../remark-rehype/asides/nested-asides.html | 1 + .../remark-rehype/rehype-tabs.test.ts | 91 +++++++++++++++++++ packages/starlight/integrations/sitemap.ts | 18 ++-- packages/starlight/package.json | 1 + pnpm-lock.yaml | 3 + 9 files changed, 237 insertions(+), 7 deletions(-) create mode 100644 packages/starlight/__tests__/basics/sitemap.test.ts create mode 100644 packages/starlight/__tests__/remark-rehype/asides.test.ts create mode 100644 packages/starlight/__tests__/remark-rehype/asides/generates-aside.html create mode 100644 packages/starlight/__tests__/remark-rehype/asides/handles-complex-children.html create mode 100644 packages/starlight/__tests__/remark-rehype/asides/nested-asides.html create mode 100644 packages/starlight/__tests__/remark-rehype/rehype-tabs.test.ts diff --git a/packages/starlight/__tests__/basics/sitemap.test.ts b/packages/starlight/__tests__/basics/sitemap.test.ts new file mode 100644 index 00000000000..d33820402be --- /dev/null +++ b/packages/starlight/__tests__/basics/sitemap.test.ts @@ -0,0 +1,40 @@ +import { describe, expect, test } from 'vitest'; +import { getSitemapConfig, starlightSitemap } from '../../integrations/sitemap'; +import type { StarlightConfig } from '../../types'; +import { StarlightConfigSchema, type StarlightUserConfig } from '../../utils/user-config'; + +describe('starlightSitemap', () => { + test('returns @astrojs/sitemap integration', () => { + const integration = starlightSitemap({} as StarlightConfig); + expect(integration.name).toBe('@astrojs/sitemap'); + }); +}); + +describe('getSitemapConfig', () => { + test('configures i18n config', () => { + const config = getSitemapConfig( + StarlightConfigSchema.parse({ + title: 'i18n test', + locales: { root: { lang: 'en', label: 'English' }, fr: { label: 'French' } }, + } satisfies StarlightUserConfig) + ); + expect(config).toMatchInlineSnapshot(` + { + "i18n": { + "defaultLocale": "root", + "locales": { + "fr": "fr", + "root": "en", + }, + }, + } + `); + }); + + test('no config for monolingual sites', () => { + const config = getSitemapConfig( + StarlightConfigSchema.parse({ title: 'i18n test' } satisfies StarlightUserConfig) + ); + expect(config).toMatchInlineSnapshot('{}'); + }); +}); diff --git a/packages/starlight/__tests__/remark-rehype/asides.test.ts b/packages/starlight/__tests__/remark-rehype/asides.test.ts new file mode 100644 index 00000000000..57fe4191840 --- /dev/null +++ b/packages/starlight/__tests__/remark-rehype/asides.test.ts @@ -0,0 +1,87 @@ +import { createMarkdownProcessor } from '@astrojs/markdown-remark'; +import { describe, expect, test } from 'vitest'; +import { starlightAsides } from '../../integrations/asides'; + +const processor = await createMarkdownProcessor({ + remarkPlugins: [...starlightAsides()], +}); + +test('generates ${label}

`); + }); +}); + +describe('custom labels', () => { + test.each(['note', 'tip', 'caution', 'danger'])('%s with custom label', async (type) => { + const label = 'Custom Label'; + const res = await processor.render(` +:::${type}[${label}] +Some text +::: + `); + expect(res.code).includes(`aria-label="${label}"`); + expect(res.code).includes(`${label}

`); + }); +}); + +test('ignores unknown directive variants', async () => { + const res = await processor.render(` +:::unknown +Some text +::: +`); + expect(res.code).toMatchInlineSnapshot('"

Some text

"'); +}); + +test('handles complex children', async () => { + const res = await processor.render(` +:::note +Paragraph [link](/href/). + +![alt](/img.jpg) + +
+See more + +More. + +
+::: +`); + expect(res.code).toMatchFileSnapshot('./asides/handles-complex-children.html'); +}); + +test('nested asides', async () => { + const res = await processor.render(` +::::note +Note contents. + +:::tip +Nested tip. +::: + +:::: +`); + expect(res.code).toMatchFileSnapshot('./asides/nested-asides.html'); +}); diff --git a/packages/starlight/__tests__/remark-rehype/asides/generates-aside.html b/packages/starlight/__tests__/remark-rehype/asides/generates-aside.html new file mode 100644 index 00000000000..fb95a152382 --- /dev/null +++ b/packages/starlight/__tests__/remark-rehype/asides/generates-aside.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/starlight/__tests__/remark-rehype/asides/handles-complex-children.html b/packages/starlight/__tests__/remark-rehype/asides/handles-complex-children.html new file mode 100644 index 00000000000..8cb4524903b --- /dev/null +++ b/packages/starlight/__tests__/remark-rehype/asides/handles-complex-children.html @@ -0,0 +1,2 @@ + \ No newline at end of file diff --git a/packages/starlight/__tests__/remark-rehype/asides/nested-asides.html b/packages/starlight/__tests__/remark-rehype/asides/nested-asides.html new file mode 100644 index 00000000000..51da5fcc4b3 --- /dev/null +++ b/packages/starlight/__tests__/remark-rehype/asides/nested-asides.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/starlight/__tests__/remark-rehype/rehype-tabs.test.ts b/packages/starlight/__tests__/remark-rehype/rehype-tabs.test.ts new file mode 100644 index 00000000000..f1f3b1c3155 --- /dev/null +++ b/packages/starlight/__tests__/remark-rehype/rehype-tabs.test.ts @@ -0,0 +1,91 @@ +import { expect, test } from 'vitest'; +import { processPanels, TabItemTagname } from '../../user-components/rehype-tabs'; + +const TabItem = ({ label, slot }: { label: string; slot: string }) => + `<${TabItemTagname} data-label="${label}">${slot}`; + +/** Get an array of HTML strings, one for each `
` created by rehype-tabs for each tab item. */ +const extractSections = (html: string) => + [...html.matchAll(//g)].map(([section]) => section); + +test('empty component returns no html or panels', () => { + const { panels, html } = processPanels(''); + expect(html).toEqual(''); + expect(panels).toEqual([]); +}); + +test('non-tab-item content is passed unchanged', () => { + const input = '

Random paragraph

'; + const { panels, html } = processPanels(input); + expect(html).toEqual(input); + expect(panels).toEqual([]); +}); + +test('tab items are processed', () => { + const label = 'Test'; + const slot = '

Random paragraph

'; + const input = TabItem({ label, slot }); + const { panels, html } = processPanels(input); + + expect(html).toMatchInlineSnapshot( + '"

Random paragraph

"' + ); + expect(panels).toHaveLength(1); + expect(panels?.[0]?.label).toBe(label); + expect(panels?.[0]?.panelId).toMatchInlineSnapshot('"tab-panel-0"'); + expect(panels?.[0]?.tabId).toMatchInlineSnapshot('"tab-0"'); +}); + +test('only first item is not hidden', () => { + const labels = ['One', 'Two', 'Three']; + const input = labels.map((label) => TabItem({ label, slot: `
${label}
` })).join(''); + const { panels, html } = processPanels(input); + + expect(panels).toHaveLength(3); + expect(html).toMatchInlineSnapshot( + '"
One
"' + ); + const sections = extractSections(html); + expect(sections).toMatchInlineSnapshot(` + [ + "
One
", + "", + "", + ] + `); + expect(sections.map((section) => section.includes('hidden'))).toEqual([false, true, true]); +}); + +test('applies incrementing ID and aria-labelledby to each tab item', () => { + const labels = ['One', 'Two', 'Three']; + const input = labels.map((label) => TabItem({ label, slot: `
${label}
` })).join(''); + const { panels, html } = processPanels(input); + + // IDs are incremented globally to ensure they are unique, so we need to extract from the panel data. + const firstTabIdMatches = panels?.[0]?.tabId.match(/^tab-(\d)+$/); + const firstTabId = parseInt(firstTabIdMatches![1]!, 10); + + extractSections(html).forEach((section, index) => { + expect(section).includes(`id="tab-panel-${firstTabId + index}"`); + expect(section).includes(`aria-labelledby="tab-${firstTabId + index}"`); + }); +}); + +test('applies tabindex="0" to tab items without focusable content', () => { + const input = [ + TabItem({ label: 'Focusable', slot: `` }), + TabItem({ label: 'Not Focusable', slot: `
Plain text
` }), + TabItem({ + label: 'Focusable Nested', + slot: `

`, + }), + ].join(''); + const { html } = processPanels(input); + expect(html).toMatchInlineSnapshot( + '"
"' + ); + const sections = extractSections(html); + expect(sections[0]).not.includes('tabindex="0"'); + expect(sections[1]).includes('tabindex="0"'); + expect(sections[2]).not.includes('tabindex="0"'); +}); diff --git a/packages/starlight/integrations/sitemap.ts b/packages/starlight/integrations/sitemap.ts index ba18af034f1..3b63370ec23 100644 --- a/packages/starlight/integrations/sitemap.ts +++ b/packages/starlight/integrations/sitemap.ts @@ -1,19 +1,23 @@ import sitemap, { type SitemapOptions } from '@astrojs/sitemap'; import type { StarlightConfig } from '../types'; -/** - * A wrapped version of the `@astrojs/sitemap` integration configured based - * on Starlight i18n config. - */ -export function starlightSitemap(opts: StarlightConfig) { +export function getSitemapConfig(opts: StarlightConfig): SitemapOptions { const sitemapConfig: SitemapOptions = {}; if (opts.isMultilingual) { sitemapConfig.i18n = { - defaultLocale: opts.defaultLocale.locale! || 'root', + defaultLocale: opts.defaultLocale.locale || 'root', locales: Object.fromEntries( Object.entries(opts.locales).map(([locale, config]) => [locale, config?.lang!]) ), }; } - return sitemap(sitemapConfig); + return sitemapConfig; +} + +/** + * A wrapped version of the `@astrojs/sitemap` integration configured based + * on Starlight i18n config. + */ +export function starlightSitemap(opts: StarlightConfig) { + return sitemap(getSitemapConfig(opts)); } diff --git a/packages/starlight/package.json b/packages/starlight/package.json index 946dc1eb4df..123de1f411f 100644 --- a/packages/starlight/package.json +++ b/packages/starlight/package.json @@ -164,6 +164,7 @@ "astro": "^3.2.0" }, "devDependencies": { + "@astrojs/markdown-remark": "^3.2.1", "@types/node": "^18.16.19", "@vitest/coverage-v8": "^0.33.0", "astro": "^3.2.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c6035741368..e3e9cf1d112 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -181,6 +181,9 @@ importers: specifier: ^5.3.7 version: 5.3.7 devDependencies: + '@astrojs/markdown-remark': + specifier: ^3.2.1 + version: 3.2.1(astro@3.2.3) '@types/node': specifier: ^18.16.19 version: 18.16.19 From 1a8824f3c7e11d6418664ff0d720f16b94ae7586 Mon Sep 17 00:00:00 2001 From: delucis Date: Thu, 16 Nov 2023 21:27:57 +0000 Subject: [PATCH 11/22] [ci] format --- .../remark-rehype/asides/generates-aside.html | 17 +++++++- .../asides/handles-complex-children.html | 25 +++++++++++- .../remark-rehype/asides/nested-asides.html | 40 ++++++++++++++++++- 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/packages/starlight/__tests__/remark-rehype/asides/generates-aside.html b/packages/starlight/__tests__/remark-rehype/asides/generates-aside.html index fb95a152382..bafb265f997 100644 --- a/packages/starlight/__tests__/remark-rehype/asides/generates-aside.html +++ b/packages/starlight/__tests__/remark-rehype/asides/generates-aside.html @@ -1 +1,16 @@ - \ No newline at end of file + diff --git a/packages/starlight/__tests__/remark-rehype/asides/handles-complex-children.html b/packages/starlight/__tests__/remark-rehype/asides/handles-complex-children.html index 8cb4524903b..27d75df09a5 100644 --- a/packages/starlight/__tests__/remark-rehype/asides/handles-complex-children.html +++ b/packages/starlight/__tests__/remark-rehype/asides/handles-complex-children.html @@ -1,2 +1,23 @@ - \ No newline at end of file + diff --git a/packages/starlight/__tests__/remark-rehype/asides/nested-asides.html b/packages/starlight/__tests__/remark-rehype/asides/nested-asides.html index 51da5fcc4b3..44fa4e7f78e 100644 --- a/packages/starlight/__tests__/remark-rehype/asides/nested-asides.html +++ b/packages/starlight/__tests__/remark-rehype/asides/nested-asides.html @@ -1 +1,39 @@ - \ No newline at end of file + From d59eb1313a0512dcfd9636beb075745245fa0e6e Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Thu, 16 Nov 2023 23:34:30 +0100 Subject: [PATCH 12/22] Avoid formatting test snapshots (#1074) --- .prettierignore | 5 ++- .../__tests__/remark-rehype/asides.test.ts | 6 +-- .../remark-rehype/asides/generates-aside.html | 16 -------- .../asides/handles-complex-children.html | 23 ----------- .../remark-rehype/asides/nested-asides.html | 39 ------------------- .../snapshots/generates-aside.html | 1 + .../snapshots/handles-complex-children.html | 2 + .../snapshots/nested-asides.html | 1 + 8 files changed, 11 insertions(+), 82 deletions(-) delete mode 100644 packages/starlight/__tests__/remark-rehype/asides/generates-aside.html delete mode 100644 packages/starlight/__tests__/remark-rehype/asides/handles-complex-children.html delete mode 100644 packages/starlight/__tests__/remark-rehype/asides/nested-asides.html create mode 100644 packages/starlight/__tests__/remark-rehype/snapshots/generates-aside.html create mode 100644 packages/starlight/__tests__/remark-rehype/snapshots/handles-complex-children.html create mode 100644 packages/starlight/__tests__/remark-rehype/snapshots/nested-asides.html diff --git a/.prettierignore b/.prettierignore index 8b16453a2c2..871a65eb470 100644 --- a/.prettierignore +++ b/.prettierignore @@ -10,4 +10,7 @@ .changeset # Files -pnpm-lock.yaml \ No newline at end of file +pnpm-lock.yaml + +# Test snapshots +**/__tests__/**/snapshots diff --git a/packages/starlight/__tests__/remark-rehype/asides.test.ts b/packages/starlight/__tests__/remark-rehype/asides.test.ts index 57fe4191840..7d1da5a6781 100644 --- a/packages/starlight/__tests__/remark-rehype/asides.test.ts +++ b/packages/starlight/__tests__/remark-rehype/asides.test.ts @@ -12,7 +12,7 @@ test('generates