Skip to content

Commit c0d0464

Browse files
committed
HeadLinks -> more general HeadTags + e2e tests
1 parent 8df90f4 commit c0d0464

File tree

10 files changed

+55
-22
lines changed

10 files changed

+55
-22
lines changed

docs/tutorialkit.dev/src/content/docs/guides/overriding-components.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,20 @@ interface Props {
9191
}
9292
```
9393

94-
### HeadLinks
94+
### HeadTags
9595

9696
Component for overriding links in the head tag.
9797

98-
When overriding `HeadLinks` you can place TutorialKit's default links using the `default-links` [Astro slot](https://docs.astro.build/en/basics/astro-components/#named-slots).
98+
When overriding `HeadTags` you can place TutorialKit's default components using following [Astro slots](https://docs.astro.build/en/basics/astro-components/#named-slots):
99+
100+
- `title`: The page title
101+
- `links`: Links for the favicon, fonts and other assets
102+
- `meta`: Metadata and Open Graph tags
99103

100104
```jsx title="src/components/CustomHeadLinks.astro"
101-
<slot name="default-links" />
105+
<slot name="title" />
106+
<slot name="links" />
107+
<slot name="meta" />
108+
{/** Add your own tags */}
102109
<link rel="sitemap" href="/sitemap-index.xml" />
103110
```

e2e/configs/override-components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default defineConfig({
1010
components: {
1111
Dialog: './src/components/Dialog.tsx',
1212
TopBar: './src/components/TopBar.astro',
13-
HeadLinks: './src/components/HeadLinks.astro',
13+
HeadTags: './src/components/CustomHeadTags.astro',
1414
},
1515
}),
1616
],
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<slot name="title" />
2+
<slot name="links" />
3+
<slot name="meta" />
4+
<link rel="sitemap" href="/sitemap-index.xml" />
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('developer can override HeadTags', async ({ page }) => {
4+
await page.goto('/');
5+
6+
const defaultElems = [
7+
page.locator('title'),
8+
page.locator('meta[name="og:title"]'),
9+
page.locator('link[rel="stylesheet"]').first(),
10+
];
11+
const customElems = [page.locator('link[rel="sitemap"]')];
12+
13+
for (const e of defaultElems) {
14+
await expect(e).toBeAttached();
15+
}
16+
17+
for (const e of customElems) {
18+
await expect(e).toBeAttached();
19+
}
20+
});

packages/astro/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"./default/pages/index.astro": "./dist/default/pages/index.astro",
2121
"./default/pages/[...slug].astro": "./dist/default/pages/[...slug].astro",
2222
"./default/components/TopBar.astro": "./dist/default/components/TopBar.astro",
23-
"./default/components/HeadLinks.astro": "./dist/default/components/HeadLinks.astro",
23+
"./default/components/HeadTags.astro": "./dist/default/components/HeadTags.astro",
2424
"./package.json": "./package.json"
2525
},
2626
"files": [

packages/astro/src/default/components/HeadLinks.astro

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<slot name="title" />
2+
<slot name="links" />
3+
<slot name="meta" />

packages/astro/src/default/env-default.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ interface WebContainerConfig {
99

1010
declare module 'tutorialkit:override-components' {
1111
const topBar: typeof import('./src/default/components/TopBar.astro').default;
12-
const headLinks: typeof import('./src/default/components/HeadLinks.astro').default;
12+
const headLinks: typeof import('./src/default/components/HeadTags.astro').default;
1313
const dialog: typeof import('@tutorialkit/react/dialog').default;
1414

15-
export { topBar as TopBar, dialog as Dialog, headLinks as HeadLinks };
15+
export { topBar as TopBar, dialog as Dialog, headLinks as HeadTags };
1616
}
1717

1818
declare const __ENTERPRISE__: boolean;

packages/astro/src/default/layouts/Layout.astro

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import { HeadLinks } from 'tutorialkit:override-components';
2+
import { HeadTags } from 'tutorialkit:override-components';
33
import { ViewTransitions } from 'astro:transitions';
44
import type { MetaTagsConfig } from '@tutorialkit/types';
55
import MetaTags from '../components/MetaTags.astro';
@@ -16,11 +16,10 @@ const faviconUrl = readPublicAsset('favicon.svg');
1616
<!doctype html>
1717
<html lang="en" transition:animate="none" class="h-full overflow-hidden">
1818
<head>
19-
<title>{title}</title>
20-
{faviconUrl ? <link rel="icon" type="image/svg+xml" href={faviconUrl} /> : null}
21-
<MetaTags meta={meta} />
22-
<HeadLinks>
23-
<Fragment slot="default-links">
19+
<HeadTags>
20+
<title slot="title">{title}</title>
21+
<Fragment slot="links">
22+
{faviconUrl ? <link rel="icon" type="image/svg+xml" href={faviconUrl} /> : null}
2423
<link rel="preconnect" href="https://fonts.googleapis.com" />
2524
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
2625
<link
@@ -29,7 +28,8 @@ const faviconUrl = readPublicAsset('favicon.svg');
2928
/>
3029
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap" rel="stylesheet" />
3130
</Fragment>
32-
</HeadLinks>
31+
<MetaTags slot="meta" meta={meta} />
32+
</HeadTags>
3333
<ViewTransitions />
3434
<script is:inline>
3535
setTutorialKitTheme();

packages/astro/src/vite-plugins/override-components.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* components: {
1919
* TopBar: './CustomTopBar.astro',
2020
* Dialog: './CustomDialog.tsx',
21-
* HeadLinks: './CustomHeadLinks.astro',
21+
* HeadTags: './CustomHeadLinks.astro',
2222
* },
2323
* }),
2424
* ],
@@ -66,7 +66,7 @@ export interface OverrideComponentsOptions {
6666
* <link rel="sitemap" href="/sitemap-index.xml" />
6767
* ```
6868
*/
69-
HeadLinks: string;
69+
HeadTags: string;
7070
}
7171

7272
interface Options {
@@ -90,13 +90,13 @@ export function overrideComponents({ components, defaultRoutes }: Options): Vite
9090
async load(id) {
9191
if (id === resolvedId) {
9292
const topBar = components?.TopBar || resolveDefaultTopBar(defaultRoutes);
93-
const headLinks = components?.HeadLinks || resolveDefaultHeadLinks(defaultRoutes);
93+
const headLinks = components?.HeadTags || resolveDefaultHeadLinks(defaultRoutes);
9494
const dialog = components?.Dialog || '@tutorialkit/react/dialog';
9595

9696
return `
9797
export { default as TopBar } from '${topBar}';
9898
export { default as Dialog } from '${dialog}';
99-
export { default as HeadLinks } from '${headLinks}';
99+
export { default as HeadTags } from '${headLinks}';
100100
`;
101101
}
102102

@@ -116,9 +116,9 @@ function resolveDefaultTopBar(defaultRoutes: boolean) {
116116

117117
function resolveDefaultHeadLinks(defaultRoutes: boolean) {
118118
if (defaultRoutes) {
119-
return '@tutorialkit/astro/default/components/HeadLinks.astro';
119+
return '@tutorialkit/astro/default/components/HeadTags.astro';
120120
}
121121

122-
// default `HeadLinks` is used from local file when `defaultRoutes` is disabled
123-
return './src/components/HeadLinks.astro';
122+
// default `HeadTags` is used from local file when `defaultRoutes` is disabled
123+
return './src/components/HeadTags.astro';
124124
}

0 commit comments

Comments
 (0)