Skip to content

Commit a9c633d

Browse files
committed
separate document title and meta title, finalize default meta tags
1 parent 9b6a148 commit a9c633d

File tree

7 files changed

+10
-16
lines changed

7 files changed

+10
-16
lines changed

docs/tutorialkit.dev/src/content/docs/guides/deployment.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The [`site`](https://docs.astro.build/fr/reference/configuration-reference/#site
4040
This will allow to compute absolute URLs for SEO metadata.
4141

4242
Example:
43-
```json
43+
```js
4444
// astro.config.mjs
4545
site:"https://tutorialkit.dev"
4646
```

packages/astro/src/default/components/MetaTags.astro

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
---
22
import type { MetaTagsConfig } from '@tutorialkit/types';
3-
import { readFaviconFile } from '../utils/favicon';
43
import { readLogoFile } from '../utils/logo';
54
import { readPublicImage } from '../utils/publicImage';
65
76
interface Props {
87
meta?: MetaTagsConfig;
98
}
109
const { meta = {} } = Astro.props;
11-
const site = Astro.site?.toString();
1210
let imageUrl;
1311
if (meta.image) {
1412
imageUrl = readPublicImage(meta.image, true);
@@ -17,15 +15,12 @@ if (meta.image) {
1715
}
1816
}
1917
imageUrl ??= readLogoFile('logo', true);
20-
const faviconUrl = readFaviconFile('favicon', true);
2118
---
2219

2320
<meta charset="UTF-8" />
2421
<meta name="viewport" content="width=device-width" />
2522
<meta name="generator" content={Astro.generator} />
2623
{meta.description ? <meta name="description" content={meta.description} /> : null}
27-
{meta.title ? <title>{meta.title}</title> : null}
28-
{faviconUrl ? <link rel="icon" type="image/svg+xml" href={faviconUrl} /> : null}
2924
{/* open graph */}
3025
{meta.title ? <meta name="og:title" content={meta.title} /> : null}
3126
{meta.description ? <meta name="og:description" content={meta.description} /> : null}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
import { ViewTransitions } from 'astro:transitions';
33
import type { MetaTagsConfig } from '@tutorialkit/types';
44
import MetaTags from '../components/MetaTags.astro';
5+
import { readPublicImage } from '../utils/publicImage';
56
67
interface Props {
8+
title: string;
79
meta?: MetaTagsConfig;
810
}
9-
const { meta } = Astro.props;
11+
const { title, meta } = Astro.props;
12+
const faviconUrl = readPublicImage('favicon.svg', true);
1013
---
1114

1215
<!doctype html>
1316
<html lang="en" transition:animate="none" class="h-full overflow-hidden">
1417
<head>
18+
<title>{title}</title>
19+
{faviconUrl ? <link rel="icon" type="image/svg+xml" href={faviconUrl} /> : null}
1520
<MetaTags meta={meta} />
1621
<link rel="preconnect" href="https://fonts.googleapis.com" />
1722
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />

packages/astro/src/default/pages/[...slug].astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ type Props = InferGetStaticPropsType<typeof getStaticPaths>;
1616
1717
const { lesson, logoLink, navList, title } = Astro.props as Props;
1818
const meta = lesson.data?.meta || {};
19-
// Use lesson default title and a default description for SEO metadata
19+
// Use lesson's default title and a default description for SEO metadata
2020
meta.title ??= title;
2121
meta.description ??= 'A TutorialKit interactive lesson';
2222
---
2323

24-
<Layout meta={meta}>
24+
<Layout title={title} meta={meta}>
2525
<PageLoadingIndicator />
2626
<div id="previews-container"></div>
2727
<main class="max-w-full flex flex-col h-full overflow-hidden" data-swap-root>

packages/astro/src/default/utils/favicon.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/astro/src/default/utils/publicImage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function readPublicImage(filename: string, absolute?: boolean) {
1616
const site = import.meta.env.SITE;
1717

1818
if (!site) {
19+
// the SITE env variable inherits the value from Astro.site configuration
1920
console.warn('Trying to compute an absolute file URL but Astro.site is not set.');
2021
} else {
2122
image = joinPaths(site, image);

packages/astro/src/default/utils/routes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export async function generateStaticRoutes() {
2626
logoLink: tutorial.logoLink,
2727
navList: generateNavigationList(tutorial, import.meta.env.BASE_URL),
2828
title: `${part.data.title} / ${chapter.data.title} / ${lesson.data.title}`,
29-
meta: lesson.data.meta,
3029
lesson: lesson as Lesson<AstroComponentFactory>,
3130
},
3231
} satisfies GetStaticPathsItem);

0 commit comments

Comments
 (0)