From 97f6516c44099b4562291882ca1726776a358bde Mon Sep 17 00:00:00 2001 From: Elior Date: Wed, 18 Nov 2026 16:51:30 +0200 Subject: [PATCH 1/2] feat(docs): add custom header site config --- astro.config.mjs | 20 ++++++++++++++--- e2e/header-footer.spec.ts | 47 +++++++++++++++++++++++++++++++++++++++ src/config/site.ts | 22 ++++++++++++++++++ src/env.d.ts | 6 +++++ 4 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 e2e/header-footer.spec.ts create mode 100644 src/config/site.ts diff --git a/astro.config.mjs b/astro.config.mjs index b588941..b7bf6cf 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -3,6 +3,7 @@ import { defineConfig } from 'astro/config'; import mdx from '@astrojs/mdx'; import starlight from '@astrojs/starlight'; import AutoImport from 'astro-auto-import'; +import { site } from './src/config/site'; // Material themes that have a matching bundled Shiki theme (code blocks follow these 5 only); // every other theme falls back to github-dark/light by its light/dark type. @@ -43,10 +44,17 @@ export default defineConfig({ title: 'Material Theme UI', customCss: ['./src/styles/custom.css'], head: [ - { tag: 'link', attrs: { rel: 'preconnect', href: 'https://fonts.googleapis.com' } }, { tag: 'link', - attrs: { rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: '' }, + attrs: { rel: 'preconnect', href: 'https://fonts.googleapis.com' }, + }, + { + tag: 'link', + attrs: { + rel: 'preconnect', + href: 'https://fonts.gstatic.com', + crossorigin: '', + }, }, { tag: 'link', @@ -60,7 +68,12 @@ export default defineConfig({ { icon: 'github', label: 'GitHub', - href: 'https://github.com/mallowigi/material-theme-docs', + href: site.github, + }, + { + icon: 'slack', + label: 'Slack', + href: site.slack, }, ], sidebar: [], @@ -69,6 +82,7 @@ export default defineConfig({ ThemeSelect: './src/components/overrides/ThemeSelect.astro', PageTitle: './src/components/overrides/PageTitle.astro', Footer: './src/components/overrides/Footer.astro', + Header: './src/components/overrides/Header.astro', }, expressiveCode: { themes: /** @type {any} */ (['github-dark', 'github-light', ...Object.keys(CODE_THEMES)]), diff --git a/e2e/header-footer.spec.ts b/e2e/header-footer.spec.ts new file mode 100644 index 0000000..10ead45 --- /dev/null +++ b/e2e/header-footer.spec.ts @@ -0,0 +1,47 @@ +import { expect, test } from '@playwright/test'; + +test.describe('Header and footer', () => { + test.use({ viewport: { width: 1280, height: 800 } }); + + test('the header shows the five top links and the social icons on desktop', async ({ page }) => { + await page.goto('/docs/reference/color-palette/'); + + const nav = page.getByRole('navigation', { name: 'Main', exact: true }); + + for (const label of [ + 'Getting Started', + 'Configuration', + 'Reference', + "What's New", + 'Pricing', + ]) { + await expect(nav.getByRole('link', { name: label })).toBeVisible(); + } + + await expect(nav.getByRole('link', { name: 'Reference' })).toHaveAttribute( + 'aria-current', + 'page', + ); + await expect(page.locator('header').getByRole('link', { name: 'GitHub' })).toBeVisible(); + await expect(page.locator('header').getByRole('link', { name: 'Slack' })).toBeVisible(); + }); + + test('the footer shows support links, version and the EULA link', async ({ page }) => { + await page.goto('/docs/reference/color-palette/'); + + const footer = page.locator('[data-mt-footer]'); + + await expect(footer.getByRole('link', { name: 'PayPal' })).toBeVisible(); + await expect(footer.getByRole('link', { name: 'OpenCollective' })).toBeVisible(); + await expect(footer.getByRole('link', { name: 'Join Slack' })).toBeVisible(); + await expect(footer).toContainText(/Material Theme v\d+\.\d+\.\d+ © 2015-\d{4}/); + await expect(footer.getByRole('link', { name: 'EULA' })).toHaveAttribute('href', '/docs/eula/'); + }); + + test('the top links are hidden on mobile', async ({ page }) => { + await page.setViewportSize({ width: 390, height: 800 }); + await page.goto('/docs/reference/color-palette/'); + + await expect(page.getByRole('navigation', { name: 'Main', exact: true })).toBeHidden(); + }); +}); diff --git a/src/config/site.ts b/src/config/site.ts new file mode 100644 index 0000000..6a9a659 --- /dev/null +++ b/src/config/site.ts @@ -0,0 +1,22 @@ +// The single place for site-wide constants. Bump `version` here on each plugin release. +export const site = { + version: '14.2.0', + firstYear: 2015, + github: 'https://github.com/mallowigi/material-theme-issues', + slack: + 'https://join.slack.com/t/material-theme-ui/shared_invite/zt-4w78iblt-cHXYRYERpuGNbD~TqsD8rg', + paypal: 'https://paypal.me/mallowigi', + openCollective: 'https://opencollective.com/atom-material-themes-and-plugins', +}; + +// Computed at build time, so the footer never goes stale. +export const years = `${site.firstYear}-${new Date().getFullYear()}`; + +// The desktop header links, in display order. +export const topLinks = [ + { label: 'Getting Started', href: '/docs/introduction/' }, + { label: 'Configuration', href: '/docs/configuration/settings/' }, + { label: 'Reference', href: '/docs/reference/color-palette/' }, + { label: "What's New", href: '/docs/what-s-new/' }, + { label: 'Pricing', href: '/docs/pricing/' }, +]; diff --git a/src/env.d.ts b/src/env.d.ts index c20c2db..dbddb7f 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -1,3 +1,9 @@ interface Window { materialTheme: { apply: (id: string, persist?: boolean) => string; current: () => string }; } + +// Starlight resolves overridable components (Search, ThemeSelect...) through virtual modules, which ship no types. +declare module 'virtual:starlight/components/*' { + const component: import('astro/runtime/server/index.js').AstroComponentFactory; + export default component; +} From 044869599b3641f9c9aa73080bebab95fbc48021 Mon Sep 17 00:00:00 2001 From: Elior Date: Wed, 18 Nov 2026 16:52:12 +0200 Subject: [PATCH 2/2] feat(docs): add custom header and footer overrides --- src/components/overrides/Footer.astro | 78 ++++++++++++++++++++- src/components/overrides/Header.astro | 98 +++++++++++++++++++++++++++ 2 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 src/components/overrides/Header.astro diff --git a/src/components/overrides/Footer.astro b/src/components/overrides/Footer.astro index 3573c4e..c3af5ee 100644 --- a/src/components/overrides/Footer.astro +++ b/src/components/overrides/Footer.astro @@ -1,8 +1,84 @@ --- -// Keeps Starlight's footer and adds the floating theme picker on every page. +// Keeps Starlight's footer (edit link, pagination), then adds the site footer and the floating theme picker. import Default from '@astrojs/starlight/components/Footer.astro'; +import { site, years } from '../../config/site'; import ThemeFab from '../theme/ThemeFab.astro'; --- + + + + + diff --git a/src/components/overrides/Header.astro b/src/components/overrides/Header.astro new file mode 100644 index 0000000..047accc --- /dev/null +++ b/src/components/overrides/Header.astro @@ -0,0 +1,98 @@ +--- +// Starlight's default header plus the five top links on desktop. +// The default component has no slot for extra content, so this re-composes the same building blocks. +import Search from 'virtual:starlight/components/Search'; +import SiteTitle from 'virtual:starlight/components/SiteTitle'; +import SocialIcons from 'virtual:starlight/components/SocialIcons'; +import ThemeSelect from 'virtual:starlight/components/ThemeSelect'; +import { topLinks } from '../../config/site'; + +const { pathname } = Astro.url; +--- + +
+
+ +
+ + + + + +
+ + +
+
+ +