Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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';
import starlightLinksValidator from 'starlight-links-validator';

// Material themes that have a matching bundled Shiki theme (code blocks follow these 5 only);
Expand Down Expand Up @@ -45,10 +46,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',
Expand All @@ -62,7 +70,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: [
Expand Down Expand Up @@ -104,6 +117,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)]),
Expand Down
47 changes: 47 additions & 0 deletions e2e/header-footer.spec.ts
Original file line number Diff line number Diff line change
@@ -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();

Check failure on line 18 in e2e/header-footer.spec.ts

View workflow job for this annotation

GitHub Actions / check

e2e/header-footer.spec.ts:6:3 › Header and footer › the header shows the five top links and the social icons on desktop

1) e2e/header-footer.spec.ts:6:3 › Header and footer › the header shows the five top links and the social icons on desktop Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(locator).toBeVisible() failed Locator: getByRole('navigation', { name: 'Main', exact: true }).getByRole('link', { name: 'Getting Started' }) Expected: visible Error: strict mode violation: getByRole('navigation', { name: 'Main', exact: true }).getByRole('link', { name: 'Getting Started' }) resolved to 2 elements: 1) <a href="/docs/introduction/" data-astro-cid-xiqy3rs3="">Getting Started</a> aka getByRole('banner').getByRole('link', { name: 'Getting Started' }) 2) <a class="large" data-astro-cid-xomcvlef="" href="/docs/getting-started/">…</a> aka locator('#starlight__sidebar').getByRole('link', { name: 'Getting Started' }) Call log: - Expect "toBeVisible" getByRole('navigation', { name: 'Main', exact: true }).getByRole('link', { name: 'Getting Started' }) with timeout 5000ms - waiting for getByRole('navigation', { name: 'Main', exact: true }).getByRole('link', { name: 'Getting Started' }) 16 | 'Pricing', 17 | ]) { > 18 | await expect(nav.getByRole('link', { name: label })).toBeVisible(); | ^ 19 | } 20 | 21 | await expect(nav.getByRole('link', { name: 'Reference' })).toHaveAttribute( at /home/runner/work/material-theme-docs/material-theme-docs/e2e/header-footer.spec.ts:18:60

Check failure on line 18 in e2e/header-footer.spec.ts

View workflow job for this annotation

GitHub Actions / check

e2e/header-footer.spec.ts:6:3 › Header and footer › the header shows the five top links and the social icons on desktop

1) e2e/header-footer.spec.ts:6:3 › Header and footer › the header shows the five top links and the social icons on desktop Error: expect(locator).toBeVisible() failed Locator: getByRole('navigation', { name: 'Main', exact: true }).getByRole('link', { name: 'Getting Started' }) Expected: visible Error: strict mode violation: getByRole('navigation', { name: 'Main', exact: true }).getByRole('link', { name: 'Getting Started' }) resolved to 2 elements: 1) <a href="/docs/introduction/" data-astro-cid-xiqy3rs3="">Getting Started</a> aka getByRole('banner').getByRole('link', { name: 'Getting Started' }) 2) <a class="large" data-astro-cid-xomcvlef="" href="/docs/getting-started/">…</a> aka locator('#starlight__sidebar').getByRole('link', { name: 'Getting Started' }) Call log: - Expect "toBeVisible" getByRole('navigation', { name: 'Main', exact: true }).getByRole('link', { name: 'Getting Started' }) with timeout 5000ms - waiting for getByRole('navigation', { name: 'Main', exact: true }).getByRole('link', { name: 'Getting Started' }) 16 | 'Pricing', 17 | ]) { > 18 | await expect(nav.getByRole('link', { name: label })).toBeVisible(); | ^ 19 | } 20 | 21 | await expect(nav.getByRole('link', { name: 'Reference' })).toHaveAttribute( at /home/runner/work/material-theme-docs/material-theme-docs/e2e/header-footer.spec.ts:18:60
}

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();
});
});
78 changes: 77 additions & 1 deletion src/components/overrides/Footer.astro
Original file line number Diff line number Diff line change
@@ -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';
---

<Default />

<div
class="mt-footer"
data-mt-footer
>
<div class="mt-footer-cols">
<section>
<h2>Support Us</h2>
<p>
Thank you for using our plugins! If you liked them, you can support us
on PayPal or OpenCollective.
</p>
<p>
<a href={site.paypal}>PayPal</a>·
<a href={site.openCollective}>OpenCollective</a>
</p>
</section>

<section>
<h2>Join the Discussion</h2>
<p>
Talk directly with us on Slack about new features, goals, problems or
anything else.
</p>
<p>
<a href={site.slack}>Join Slack</a>
</p>
</section>
</div>

<p class="mt-footer-copyright">
<span>
Material Theme v{site.version} © {years}
</span>
<a href="/docs/eula/">EULA</a>
</p>
</div>

<ThemeFab />

<style>
.mt-footer {
margin-top: 2rem;
padding-top: 1.5rem;
border-top: 1px solid var(--sl-color-hairline);
font-size: var(--sl-text-sm);
color: var(--sl-color-gray-2);
}

.mt-footer-cols {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
gap: 1.5rem;
}

.mt-footer h2 {
margin: 0 0 0.5rem;
font-size: var(--sl-text-base);
color: var(--sl-color-white);
}

.mt-footer p {
margin: 0 0 0.5rem;
}

.mt-footer a {
color: var(--sl-color-accent-high);
}

.mt-footer-copyright {
display: flex;
flex-wrap: wrap;
gap: 1rem;
margin-top: 1.5rem;
}
</style>
98 changes: 98 additions & 0 deletions src/components/overrides/Header.astro
Original file line number Diff line number Diff line change
@@ -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;
---

<div class="header">
<div class="title-wrapper sl-flex">
<SiteTitle />
</div>

<nav
class="top-links sl-hidden lg:sl-flex print:hidden"
aria-label="Main"
>
{topLinks.map((link) => (
<a
href={link.href}
aria-current={
pathname.startsWith(link.href.split('/').slice(0, 3).join('/'))
? 'page'
: undefined
}
>
{link.label}
</a>
))}
</nav>

<div class="search sl-flex print:hidden">
<Search />
</div>

<div class="right-group sl-hidden md:sl-flex print:hidden">
<div class="social-icons sl-flex">
<SocialIcons />
</div>
<ThemeSelect />
</div>
</div>

<style>
@layer starlight.core {
.header {
display: flex;
gap: var(--sl-nav-gap);
align-items: center;
height: 100%;
}

.title-wrapper {
overflow: clip;
padding: 0.25rem;
margin: -0.25rem;
min-width: 0;
}

.top-links {
gap: 1.25rem;
align-items: center;
}

.top-links a {
color: var(--sl-color-gray-2);
text-decoration: none;
font-size: var(--sl-text-sm);
white-space: nowrap;
}

.top-links a:hover,
.top-links a[aria-current='page'] {
color: var(--sl-color-accent);
}

.search {
flex: 1;
justify-content: flex-end;
}

.right-group,
.social-icons {
gap: 1rem;
align-items: center;
}

.social-icons::after {
content: '';
height: 2rem;
border-inline-end: 1px solid var(--sl-color-gray-5);
}
}
</style>
22 changes: 22 additions & 0 deletions src/config/site.ts
Original file line number Diff line number Diff line change
@@ -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/' },
];
6 changes: 6 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Loading