@mannisto/astro-metadata 2.0.0-alpha.5 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +267 -112
  2. package/package.json +9 -9
  3. package/src/components/Canonical.astro +10 -0
  4. package/src/components/Description.astro +10 -0
  5. package/src/components/Favicon.astro +9 -0
  6. package/src/components/Feeds.astro +29 -0
  7. package/src/components/LanguageAlternates.astro +13 -0
  8. package/src/components/Manifest.astro +11 -0
  9. package/src/components/Metadata.astro +27 -199
  10. package/src/components/OpenGraph.astro +70 -0
  11. package/src/components/Robots.astro +10 -0
  12. package/src/components/Schema.astro +42 -0
  13. package/src/components/ThemeColor.astro +15 -0
  14. package/src/components/Title.astro +10 -0
  15. package/src/components/Twitter.astro +21 -0
  16. package/src/components/index.ts +13 -1
  17. package/src/integration.js +0 -6
  18. package/src/lib/checks.js +6 -1
  19. package/src/lib/config.ts +2 -2
  20. package/src/lib/manifest.ts +0 -1
  21. package/src/lib/open-graph.ts +54 -0
  22. package/src/lib/page.ts +165 -0
  23. package/src/lib/rules.js +0 -1
  24. package/src/lib/site.ts +66 -43
  25. package/src/lib/url.ts +4 -1
  26. package/src/runtime.ts +1 -3
  27. package/src/toolbar/app.ts +1 -15
  28. package/src/toolbar/data.ts +0 -2
  29. package/src/toolbar/highlight.ts +0 -3
  30. package/src/toolbar/ui/alert/alert.css +0 -2
  31. package/src/toolbar/ui/section/section.css +0 -7
  32. package/src/toolbar/ui/table/table.css +0 -2
  33. package/src/toolbar/views/metadata-panel.css +0 -7
  34. package/src/toolbar/views/metadata-panel.ts +1 -5
  35. package/src/toolbar/views/overview-view.css +0 -2
  36. package/src/toolbar/views/overview-view.ts +13 -0
  37. package/src/toolbar/views/previews/previews-view.css +0 -1
  38. package/src/toolbar/views/previews/previews-view.ts +0 -1
package/README.md CHANGED
@@ -1,25 +1,13 @@
1
1
  # Astro Metadata
2
2
 
3
- ![banner](./assets/banner.png)
3
+ ![banner](./docs/banner.png)
4
4
 
5
5
  ![Astro](https://img.shields.io/badge/astro-%232C2052.svg?style=for-the-badge&logo=astro&logoColor=white)
6
6
  ![npm version](https://img.shields.io/npm/v/@mannisto/astro-metadata?style=for-the-badge)
7
+ ![Astro version](https://img.shields.io/npm/dependency-version/@mannisto/astro-metadata/peer/astro?style=for-the-badge&label=astro)
7
8
  ![license](https://img.shields.io/badge/license-MIT-green?style=for-the-badge)
8
9
 
9
- The page metadata for Astro: the title, the description, the canonical URL, social cards, favicons, the web app manifest and structured data. Set the site values one time, and give each page only its own values.
10
-
11
- - [Install](#install)
12
- - [Configuration](#configuration)
13
- - [Metadata component](#metadata-component)
14
- - [Favicons](#favicons)
15
- - [Web app manifest](#web-app-manifest)
16
- - [Structured data](#structured-data)
17
- - [Checks](#checks)
18
- - [API](#api)
19
- - [Good to know](#good-to-know)
20
- - [Migrate from v1](#migrate-from-v1)
21
- - [Contributing](#contributing)
22
- - [License](#license)
10
+ The page metadata for Astro: the title, the description, the canonical URL, social cards, favicons, the web app manifest and structured data. Set the site values one time, and give each page only its own values. In dev, an app in the Astro dev toolbar checks each page.
23
11
 
24
12
  ## Install
25
13
 
@@ -27,8 +15,6 @@ The page metadata for Astro: the title, the description, the canonical URL, soci
27
15
  npm install @mannisto/astro-metadata
28
16
  ```
29
17
 
30
- The integration requires Astro 6.4.6 or later, or Astro 7.
31
-
32
18
  ## Configuration
33
19
 
34
20
  ```typescript
@@ -43,12 +29,28 @@ export default defineConfig({
43
29
  siteName: "Acme Studio",
44
30
  titleTemplate: "%s | Acme Studio",
45
31
  description: "Tools for small teams.",
46
- image: { url: "/og.jpg", alt: "Acme Studio", width: 1200, height: 630 },
47
- twitter: { site: "@acmestudio" },
32
+ image: {
33
+ url: "/og.jpg",
34
+ alt: "Acme Studio",
35
+ width: 1200,
36
+ height: 630,
37
+ },
38
+ twitter: {
39
+ site: "@acmestudio",
40
+ },
48
41
  themeColor: "#111111",
49
- feeds: [{ href: "/rss.xml", title: "News" }],
50
- favicon: { source: "./src/assets/logo.svg" },
51
- manifest: { name: "Acme Studio" },
42
+ feeds: [
43
+ {
44
+ href: "/rss.xml",
45
+ title: "News",
46
+ },
47
+ ],
48
+ favicon: {
49
+ source: "./src/assets/logo.svg",
50
+ },
51
+ manifest: {
52
+ name: "Acme Studio",
53
+ },
52
54
  }),
53
55
  ],
54
56
  })
@@ -69,32 +71,10 @@ Set `site` in the Astro config. The canonical URL and the social images must be
69
71
  | `favicon` | — | Generates the favicons from one image. See [Favicons](#favicons). |
70
72
  | `manifest` | — | Generates the web app manifest, or links your own. See [Web app manifest](#web-app-manifest). |
71
73
  | `schema` | — | The structured data of the site: `publisher` is the organization or the person behind the site. `false` turns it off. See [Structured data](#structured-data). |
72
- | `debug` | `true` | The Metadata app in the dev toolbar (`client`) and the checks in the build log (`build`). Set `false` to turn off both, or `{ client: false }` or `{ build: false }` to turn off one. See [Checks](#checks). |
74
+ | `debug` | `true` | The dev toolbar app (`client`) and the build log (`build`). See [Checks](#checks). |
73
75
  | `rules` | — | `ignore`: the ids of the check rules to turn off. `custom`: your own rules. See [Checks](#checks). |
74
76
  | `pages` | — | `ignore`: the pages without checks, as path patterns, for example `["/404", "/drafts/**"]`. See [Checks](#checks). |
75
77
 
76
- ### Translations
77
-
78
- Each text can be one string, or an object with one string for each locale:
79
-
80
- ```typescript
81
- metadata({
82
- siteName: { en: "Acme Studio", fi: "Acme Studio Suomi" },
83
- titleTemplate: { en: "%s | Acme Studio", fi: "%s | Acme Studio Suomi" },
84
- })
85
- ```
86
-
87
- `<Metadata>` uses the text of the locale of the page, or of its `locale` prop. A locale without a text uses the first text.
88
-
89
- ### Locales
90
-
91
- `<Metadata>` reads the locales from your i18n setup. You do not need extra code:
92
-
93
- - **[`@mannisto/astro-i18n`](https://github.com/eremannisto/astro-i18n):** the locale, the public URL of the page (`/about` and not `/en/about`) and the hreflang links.
94
- - **The `i18n` option of Astro:** the locale and the hreflang links.
95
-
96
- The hreflang links contain the page in each locale, and `x-default` for the default locale. To give your own links, use the `hreflang` prop. `hreflang={[]}` turns the links off, for example on a 404 page.
97
-
98
78
  ## Metadata component
99
79
 
100
80
  Put `<Metadata>` into the `<head>` of your layout, and give it the values of the page:
@@ -164,7 +144,117 @@ The page values override the site values. For example, `title="About"` gives:
164
144
  | `schema` | — | Structured data items of your own, for example a `Product`. See [Structured data](#structured-data). |
165
145
  | `locale` | The locale of the page | The locale of the translated site values. See [Locales](#locales). |
166
146
 
167
- A tag is rendered only when it has a value. For example, the robots tag is necessary only with `index` or `follow` set to `false`.
147
+ `<Metadata>` renders a tag only when the tag has a value. For example, the robots tag is necessary only with `index` or `follow` set to `false`.
148
+
149
+ ### Single components
150
+
151
+ `<Metadata>` renders all tags. To render only some of them, use the single components. They take the same props as `<Metadata>`, and they use the same site values:
152
+
153
+ ```astro
154
+ ---
155
+ import { Canonical, OpenGraph, Title } from "@mannisto/astro-metadata/components"
156
+ ---
157
+
158
+ <Title title="About" />
159
+ <Canonical />
160
+ <OpenGraph title="About" />
161
+ ```
162
+
163
+ | Component | Tags |
164
+ |---|---|
165
+ | `<Title>` | `title` |
166
+ | `<Description>` | `description` |
167
+ | `<Canonical>` | The canonical link |
168
+ | `<Robots>` | `robots` |
169
+ | `<ThemeColor>` | `theme-color` |
170
+ | `<OpenGraph>` | `og:*` and `article:*` |
171
+ | `<Twitter>` | `twitter:*` |
172
+ | `<Favicon>` | The favicon links |
173
+ | `<Manifest>` | The manifest link |
174
+ | `<Feeds>` | The feed links |
175
+ | `<LanguageAlternates>` | The hreflang links |
176
+ | `<Schema>` | The structured data |
177
+
178
+ ## Multiple languages
179
+
180
+ ### Translations
181
+
182
+ Each text can be one string, or an object with one string for each locale:
183
+
184
+ ```typescript
185
+ metadata({
186
+ siteName: "Acme Studio",
187
+ description: {
188
+ en: "Tools for small teams.",
189
+ fi: "Työkaluja pienille tiimeille.",
190
+ },
191
+ })
192
+ ```
193
+
194
+ `<Metadata>` uses the text of the locale of the page, or of its `locale` prop. A locale without a text uses the first text.
195
+
196
+ The social image can also have one image for each locale, for example when the image has text on it:
197
+
198
+ ```typescript
199
+ metadata({
200
+ image: {
201
+ url: {
202
+ en: "/og-en.jpg",
203
+ fi: "/og-fi.jpg",
204
+ },
205
+ alt: {
206
+ en: "Acme Studio",
207
+ fi: "Acme Studio",
208
+ },
209
+ width: 1200,
210
+ height: 630,
211
+ },
212
+ })
213
+ ```
214
+
215
+ ### Locales
216
+
217
+ On a site with more than one language, `<Metadata>` finds the language of each page and its other language versions by itself. This works with [`@mannisto/astro-i18n`](https://github.com/eremannisto/astro-i18n) and with the [native i18n of Astro](https://docs.astro.build/en/guides/internationalization/). You do not need extra code.
218
+
219
+ Each page then tells search engines and social sites its language, and where the same page is in the other languages:
220
+
221
+ ```html
222
+ <meta property="og:locale" content="en_US">
223
+ <meta property="og:locale:alternate" content="fi_FI">
224
+ <link rel="alternate" hreflang="en" href="https://example.com/about/">
225
+ <link rel="alternate" hreflang="fi" href="https://example.com/fi/about/">
226
+ <link rel="alternate" hreflang="x-default" href="https://example.com/about/">
227
+ ```
228
+
229
+ With `@mannisto/astro-i18n`, the URLs also follow your `prefixDefaultLocale` option, for example `/about` and not `/en/about`.
230
+
231
+ With another i18n library, give the language of the page in `locale`, and the language versions in `hreflang`. `<Metadata>` makes the same tags from them:
232
+
233
+ ```astro
234
+ <Metadata
235
+ locale="fi"
236
+ hreflang={[
237
+ {
238
+ hreflang: "en",
239
+ href: "/about",
240
+ },
241
+ {
242
+ hreflang: "fi",
243
+ href: "/fi/about",
244
+ },
245
+ {
246
+ hreflang: "x-default",
247
+ href: "/about",
248
+ },
249
+ ]}
250
+ />
251
+ ```
252
+
253
+ A page that has no other language versions, for example a 404 page, can turn off the links:
254
+
255
+ ```astro
256
+ <Metadata hreflang={[]} />
257
+ ```
168
258
 
169
259
  ## Favicons
170
260
 
@@ -197,16 +287,30 @@ To generate other files, give a `files` list. It replaces the default files:
197
287
  favicon: {
198
288
  source: "./src/assets/logo.svg",
199
289
  files: [
200
- { path: "/favicon.ico", sizes: [16, 32, 48] },
201
- { path: "/favicon.svg" },
202
- { path: "/apple-touch-icon.png", size: 180 },
203
- { path: "/favicon-96.png", size: 96 },
204
- { path: "/favicon-512.png", size: 512 },
290
+ {
291
+ path: "/favicon.ico",
292
+ sizes: [16, 32, 48],
293
+ },
294
+ {
295
+ path: "/favicon.svg",
296
+ },
297
+ {
298
+ path: "/apple-touch-icon.png",
299
+ size: 180,
300
+ },
301
+ {
302
+ path: "/favicon-96.png",
303
+ size: 96,
304
+ },
305
+ {
306
+ path: "/favicon-512.png",
307
+ size: 512,
308
+ },
205
309
  ],
206
310
  }
207
311
  ```
208
312
 
209
- The extension sets the format: `.ico`, `.png` or `.svg`. The name and the size set the use:
313
+ The file extension decides the format: `.ico`, `.png` or `.svg`. The name and the size decide where the file goes:
210
314
 
211
315
  - `.ico` and `.svg` files, and `.png` files smaller than 192 px, get an icon link tag.
212
316
  - `apple-touch-icon.png` gets the Apple link tag.
@@ -249,7 +353,19 @@ metadata({
249
353
  })
250
354
  ```
251
355
 
252
- Your own manifest endpoint can use the generated icons with `Favicon.icons()`.
356
+ Your own manifest endpoint can use the generated icons with `Site.icons()`:
357
+
358
+ ```typescript
359
+ // src/pages/site.webmanifest.ts
360
+ import { Site } from "@mannisto/astro-metadata/runtime"
361
+
362
+ export const GET = () => {
363
+ return Response.json({
364
+ name: Site.name(),
365
+ icons: Site.icons(),
366
+ })
367
+ }
368
+ ```
253
369
 
254
370
  ## Structured data
255
371
 
@@ -278,7 +394,11 @@ For a personal site, use `publisher: { type: "Person" }`. Set `schema: false` to
278
394
  title="Hello"
279
395
  type="article"
280
396
  published={post.date}
281
- author={{ name: "Acme Writer", url: "/about", twitter: "@acmewriter" }}
397
+ author={{
398
+ name: "Acme Writer",
399
+ url: "/about",
400
+ twitter: "@acmewriter",
401
+ }}
282
402
  />
283
403
  ```
284
404
 
@@ -287,8 +407,14 @@ For a personal site, use `publisher: { type: "Person" }`. Set `schema: false` to
287
407
  ```astro
288
408
  <Metadata
289
409
  breadcrumbs={[
290
- { name: "Home", url: "/" },
291
- { name: "Blog", url: "/blog" },
410
+ {
411
+ name: "Home",
412
+ url: "/",
413
+ },
414
+ {
415
+ name: "Blog",
416
+ url: "/blog",
417
+ },
292
418
  ]}
293
419
  />
294
420
  ```
@@ -296,40 +422,73 @@ For a personal site, use `publisher: { type: "Person" }`. Set `schema: false` to
296
422
  **Your own items.** Give other types, for example a `Product` or an `Event`, in `schema`. The types come from [`schema-dts`](https://github.com/google/schema-dts), so your editor completes the schema.org fields:
297
423
 
298
424
  ```astro
299
- <Metadata schema={{ "@type": "Event", name: "Opening night", startDate: "2026-11-01" }} />
425
+ <Metadata
426
+ schema={{
427
+ "@type": "Event",
428
+ name: "Opening night",
429
+ startDate: "2026-11-01",
430
+ }}
431
+ />
300
432
  ```
301
433
 
302
- All items go into one graph. The items link to each other with `@id`, and all URLs are absolute.
434
+ ## Dev toolbar app
435
+
436
+ Run `astro dev`, and open the Metadata app in the dev toolbar. The app checks the current page, and shows its tags and its link previews. Click a problem to open the row of its tag.
437
+
438
+ <table>
439
+ <tr>
440
+ <td><img src="./docs/screenshots/01.png" alt="The Overview tab with no problems" width="260"></td>
441
+ <td><img src="./docs/screenshots/02.png" alt="The Overview tab with an error, two warnings and two notes" width="260"></td>
442
+ <td><img src="./docs/screenshots/03.png" alt="The Social section with the Open Graph tags" width="260"></td>
443
+ </tr>
444
+ <tr>
445
+ <td><img src="./docs/screenshots/04.png" alt="The Structured data section with the JSON-LD of the page" width="260"></td>
446
+ <td><img src="./docs/screenshots/05.png" alt="The Previews tab with the Google and Twitter (X) previews" width="260"></td>
447
+ <td><img src="./docs/screenshots/06.png" alt="The Raw tab with the tags of the head" width="260"></td>
448
+ </tr>
449
+ </table>
303
450
 
304
451
  ## Checks
305
452
 
306
- The integration checks the metadata of each page. Each problem has a level:
453
+ The dev toolbar app checks the current page. The build checks all prerendered pages, and compares them, for example for the same title on two pages. It logs the errors and the warnings:
454
+
455
+ ```
456
+ [WARN] [@mannisto/astro-metadata] /about/index.html
457
+ - The page has no description.
458
+ ```
307
459
 
308
- | Level | Meaning | Examples |
460
+ | Level | Description | Examples |
309
461
  | --- | --- | --- |
310
- | Error | The metadata is broken. | No title, placeholder text such as `undefined`, two canonical links, invalid JSON-LD, an `og:image` that does not load |
311
- | Warning | Fix it for better results. | A long title, the same title on two pages, no `twitter:card`, an `og:image` over 600 KB, an hreflang page that does not link back |
462
+ | Error | The metadata is broken. | No title, placeholder text such as `undefined`, invalid JSON-LD, an `og:image` that does not load |
463
+ | Warning | Fix it for better results. | A long title, the same title on two pages, an `og:image` over 600 KB |
312
464
  | Info | Good to know. | `noindex`, a short description, no `og:image:alt` |
313
465
 
314
- The checks look at three things:
315
-
316
- - **The head of each page:** the tags, the structured data and the hreflang links. A page with `noindex` gets no search and sharing checks.
317
- - **The files of each page:** the `og:image` and the favicons. The checks load them, and compare the real image size, format and file size with the tags. Files on other sites are not checked.
318
- - **All pages together:** the same title or description on two pages, and hreflang links that do not link back. Only the build can compare the pages.
466
+ To turn off the checks, use `debug`:
319
467
 
320
- The results show in two places:
468
+ ```typescript
469
+ // No dev toolbar app
470
+ metadata({
471
+ debug: {
472
+ client: false,
473
+ },
474
+ })
321
475
 
322
- - **In dev:** Open the Metadata app in the Astro dev toolbar. It shows the problems of the current page. Click a problem to open the row of its tag. The app also shows the link previews of Google, Twitter (X), Facebook, LinkedIn, WhatsApp, Discord and Slack, and all metadata tags.
323
- - **In the build:** The integration logs the errors and the warnings of the prerendered pages:
476
+ // No build log
477
+ metadata({
478
+ debug: {
479
+ build: false,
480
+ },
481
+ })
324
482
 
325
- ```
326
- [WARN] [@mannisto/astro-metadata] /about/index.html
327
- - The page has no description.
483
+ // Neither
484
+ metadata({
485
+ debug: false,
486
+ })
328
487
  ```
329
488
 
330
489
  ### Turn off rules
331
490
 
332
- All rules and their ids are in [`src/lib/rules.js`](./src/lib/rules.js). Give the ids of the rules to turn off in `rules.ignore`. This applies to the dev toolbar app and to the build:
491
+ Give the ids of the rules in `rules.ignore`. All rules and their ids are in [`src/lib/rules.js`](./src/lib/rules.js).
333
492
 
334
493
  ```typescript
335
494
  metadata({
@@ -341,7 +500,7 @@ metadata({
341
500
 
342
501
  ### Custom rules
343
502
 
344
- Add your own rules in `rules.custom`. A rule has an `id`, a `level` (`"error"`, `"warning"` or `"info"`), a `message`, and a `check` function that returns `true` when the page has the problem:
503
+ Add your own rules in `rules.custom`. A rule has an `id`, a `level` (`"error"`, `"warning"` or `"info"`), a `message` and a `check` function. The function returns `true` when the page has the problem:
345
504
 
346
505
  ```typescript
347
506
  metadata({
@@ -376,11 +535,11 @@ The rule can also have:
376
535
  - `field`, the tag of the problem, for example `"og:title"`. A click on the problem in the dev toolbar app opens its row.
377
536
  - `indexed: true`, to skip the rule on a noindex page.
378
537
 
379
- The custom rules run in the build and in the dev toolbar app. In dev, the dev server runs them, because they are functions in the Astro config. Text between backticks in a message shows as code in the dev toolbar app. The `MetadataRule` type gives your editor completion.
538
+ Text between backticks in a message shows as code in the dev toolbar app. The `MetadataRule` type gives your editor completion.
380
539
 
381
540
  ### Ignore pages
382
541
 
383
- Some pages do not need checks, for example a 404 page or the drafts. Give their paths in `pages.ignore`, without the base. In a pattern, `*` matches one part of the path, and `**` matches any number of parts:
542
+ Give the paths of the pages without checks in `pages.ignore`, without the base. `*` matches one part of the path, and `**` matches any number of parts:
384
543
 
385
544
  ```typescript
386
545
  metadata({
@@ -390,46 +549,36 @@ metadata({
390
549
  })
391
550
  ```
392
551
 
393
- The build does not check these pages, and does not compare them with the other pages. The dev toolbar app shows all values of these pages, but no problems.
394
-
395
- Set `debug: { build: false }` to hide the build warnings, `debug: { client: false }` to remove the dev toolbar app, and `debug: false` to turn off both.
552
+ The dev toolbar app still shows the values of these pages, but no problems.
396
553
 
397
554
  ## API
398
555
 
556
+ `Site` returns the values that you set in the integration, for example for a footer, a feed or your own manifest:
557
+
399
558
  ```typescript
400
- import { Favicon, Manifest, Schema, Site } from "@mannisto/astro-metadata/runtime"
559
+ import { Site } from "@mannisto/astro-metadata/runtime"
560
+
561
+ Site.description({ locale: "fi" })
401
562
  ```
402
563
 
403
- | Method | Returns | Description |
404
- |---|---|---|
405
- | `Site.config` | `MetadataConfig` | The site values of the integration |
406
- | `Site.name("fi")` | `string` | The site name of a locale |
407
- | `Site.title("About", "fi")` | `string` | The page title in the title template |
408
- | `Site.url("/og.jpg")` | `string` | The absolute URL of a path |
409
- | `Site.pageUrl("/about")` | `string` | The absolute URL of a page, with the trailing slash of Astro |
410
- | `Favicon.config` | `FaviconConfig` | The favicon config, or `undefined` without the `favicon` option |
411
- | `Favicon.files` | `ResolvedFaviconFile[]` | The generated files |
412
- | `Favicon.links()` | `FaviconLink[]` | The link tags of the generated files |
413
- | `Favicon.icons()` | `ManifestIcon[]` | The icons for a web app manifest |
414
- | `Favicon.url("/favicon.ico")` | `string` | The URL of a file, with the base and a hash |
415
- | `Favicon.generate("/favicon-32.png")` | `Promise<Response>` | Generates a file of the config |
416
- | `Manifest.config` | `ManifestConfig \| string` | The `manifest` option |
417
- | `Manifest.url("fi")` | `string` | The URL of the manifest of a locale |
418
- | `Manifest.build("fi")` | `object` | The manifest of a locale |
419
- | `Manifest.paths()` | `ManifestPath[]` | The generated manifest files |
420
- | `Schema.graph(page)` | `Graph` | The structured data that `<Metadata>` renders for a page |
421
- | `Schema.stringify(data)` | `string` | JSON that is safe inside a script tag |
422
-
423
- | Component | Props |
564
+ | Method | Returns |
424
565
  |---|---|
425
- | `<Metadata>` | See [Metadata component](#metadata-component) |
566
+ | `Site.name()` | `siteName` |
567
+ | `Site.template()` | `titleTemplate` |
568
+ | `Site.description()` | `description` |
569
+ | `Site.image()` | `image`, with an absolute URL |
570
+ | `Site.twitter()` | `twitter`, with the default card |
571
+ | `Site.themeColor()` | `themeColor` |
572
+ | `Site.icons()` | The generated favicons, for the `icons` of a web app manifest |
573
+
574
+ A translated text returns the text of `locale`, or the first text without `locale`. An option that is not set returns `undefined`.
426
575
 
427
576
  Import the types from `@mannisto/astro-metadata/runtime`, for example `import type { MetadataImage } from "@mannisto/astro-metadata/runtime"`.
428
577
 
429
578
  ## Good to know
430
579
 
431
- - **CMS data.** Give CMS values to `<Metadata>` as props. The site values of the integration are fixed at startup, and a change restarts the dev server.
432
- - **Trailing slash.** The canonical URL and the `hreflang` links follow the `trailingSlash` setting of Astro. With `"ignore"`, `build.format` decides.
580
+ - **CMS data.** Give CMS values to `<Metadata>` as props. The integration reads its site values one time at startup, and a change restarts the dev server.
581
+ - **Trailing slash.** The canonical URL and the `hreflang` links follow the `trailingSlash` option of Astro. With `"ignore"`, `build.format` decides.
433
582
  - **`sharp`.** The favicons use the `sharp` package that Astro installs. If you install Astro without its optional dependencies, install `sharp` yourself.
434
583
  - **Files in `public/`.** A file in `public/` with the same path as a generated favicon replaces the generated file. The integration shows a warning.
435
584
 
@@ -441,7 +590,10 @@ Version 2 is a new API. The main changes:
441
590
 
442
591
  ```diff
443
592
  - <Head title="About" titleTemplate="%s | My Site" description="..." />
444
- + metadata({ titleTemplate: "%s | My Site", description: "..." })
593
+ + metadata({
594
+ + titleTemplate: "%s | My Site",
595
+ + description: "...",
596
+ + })
445
597
  ```
446
598
 
447
599
  ### Use `<Metadata>` inside your own `<head>`
@@ -458,19 +610,18 @@ Version 2 is a new API. The main changes:
458
610
  + </head>
459
611
  ```
460
612
 
461
- ### Replace the removed components
613
+ ### Use the new props of the single components
462
614
 
463
- `Title`, `Description`, `Canonical`, `Robots`, `OpenGraph`, `Twitter`, `Favicon`, `LanguageAlternates`, `Keywords` and `Schema` are removed. `<Metadata>` renders their tags.
615
+ The single components take the props of `<Metadata>`, and `<Metadata>` renders all of them. There is no `Keywords` component, because search engines do not use the tag.
464
616
 
465
617
  ```diff
466
618
  - <LanguageAlternates alternates={links} />
467
- - <Schema schema={data} />
468
- + <Metadata hreflang={links} schema={data} />
619
+ + <LanguageAlternates hreflang={links} />
469
620
  ```
470
621
 
471
622
  ### Replace the `Metadata` store
472
623
 
473
- `Metadata.set()` and `Metadata.resolve()` are removed. Give the values as props to your layout.
624
+ v2 has no `Metadata.set()` and `Metadata.resolve()`. Give the values as props to your layout.
474
625
 
475
626
  ### Replace the robots object and the `false` props
476
627
 
@@ -483,7 +634,11 @@ Version 2 is a new API. The main changes:
483
634
 
484
635
  ```diff
485
636
  - <Head favicon={{ icons: [{ path: "/favicon.ico" }] }} />
486
- + metadata({ favicon: { source: "./src/assets/logo.svg" } })
637
+ + metadata({
638
+ + favicon: {
639
+ + source: "./src/assets/logo.svg",
640
+ + },
641
+ + })
487
642
  ```
488
643
 
489
644
  ## Contributing
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mannisto/astro-metadata",
3
- "version": "2.0.0-alpha.5",
4
- "description": "Metadata for Astro: page tags, social cards, favicons, the web app manifest and structured data.",
3
+ "version": "2.1.0",
4
+ "description": "Metadata for Astro: page tags, social cards, favicons, the web app manifest, structured data and a dev toolbar app that checks your pages.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "homepage": "https://github.com/eremannisto/astro-metadata#readme",
@@ -44,21 +44,21 @@
44
44
  "devDependencies": {
45
45
  "@eslint/js": "^10.0.1",
46
46
  "@ianvs/prettier-plugin-sort-imports": "^4.7.1",
47
- "@playwright/test": "^1.63.0",
47
+ "@playwright/test": "^1.64.1",
48
48
  "@types/node": "^22.20.5",
49
- "astro": "^7.3.5",
50
- "eslint": "^10.11.0",
49
+ "astro": "^7.4.2",
50
+ "eslint": "^10.13.0",
51
51
  "eslint-config-prettier": "^10.1.8",
52
- "prettier": "^3.9.9",
52
+ "prettier": "^3.9.10",
53
53
  "prettier-plugin-astro": "^0.14.1",
54
54
  "sharp": "^0.35.5",
55
55
  "typescript": "^5.9.3",
56
- "typescript-eslint": "^8.71.0",
57
- "vitest": "^4.1.11"
56
+ "typescript-eslint": "^8.72.1",
57
+ "vitest": "^4.1.12"
58
58
  },
59
59
  "packageManager": "pnpm@10.32.1",
60
60
  "dependencies": {
61
61
  "lit": "^3.3.3",
62
- "schema-dts": "^2.0.0"
62
+ "schema-dts": "^2.1.0"
63
63
  }
64
64
  }
@@ -0,0 +1,10 @@
1
+ ---
2
+ import { pageCanonical } from "../lib/page.ts"
3
+ import type { MetadataProps } from "../lib/page.ts"
4
+
5
+ export type Props = Pick<MetadataProps, "canonical">
6
+
7
+ const canonical = pageCanonical(Astro, Astro.props)
8
+ ---
9
+
10
+ <link rel="canonical" href={canonical} />
@@ -0,0 +1,10 @@
1
+ ---
2
+ import { pageDescription, pageLocale } from "../lib/page.ts"
3
+ import type { MetadataProps } from "../lib/page.ts"
4
+
5
+ export type Props = Pick<MetadataProps, "description" | "locale">
6
+
7
+ const description = pageDescription(Astro.props, pageLocale(Astro, Astro.props))
8
+ ---
9
+
10
+ {description && <meta name="description" content={description} />}
@@ -0,0 +1,9 @@
1
+ ---
2
+ import { Favicon } from "../lib/favicon.ts"
3
+ ---
4
+
5
+ {
6
+ Favicon.links().map((link) => {
7
+ return <link rel={link.rel} type={link.type} href={link.href} sizes={link.sizes} />
8
+ })
9
+ }
@@ -0,0 +1,29 @@
1
+ ---
2
+ import { getConfig, localize } from "../lib/config.ts"
3
+ import { pageLocale } from "../lib/page.ts"
4
+ import type { MetadataProps } from "../lib/page.ts"
5
+ import { withBase } from "../lib/url.ts"
6
+
7
+ export type Props = Pick<MetadataProps, "locale">
8
+
9
+ const locale = pageLocale(Astro, Astro.props)
10
+
11
+ const FEED_TYPES = {
12
+ rss: "application/rss+xml",
13
+ atom: "application/atom+xml",
14
+ json: "application/feed+json",
15
+ }
16
+ ---
17
+
18
+ {
19
+ getConfig().feeds?.map((feed) => {
20
+ return (
21
+ <link
22
+ rel="alternate"
23
+ type={FEED_TYPES[feed.type ?? "rss"]}
24
+ title={localize(feed.title, locale)}
25
+ href={withBase(feed.href)}
26
+ />
27
+ )
28
+ })
29
+ }
@@ -0,0 +1,13 @@
1
+ ---
2
+ import { pageHreflang } from "../lib/page.ts"
3
+ import type { MetadataProps } from "../lib/page.ts"
4
+ import { pageUrl } from "../lib/url.ts"
5
+
6
+ export type Props = Pick<MetadataProps, "hreflang">
7
+ ---
8
+
9
+ {
10
+ pageHreflang(Astro, Astro.props).map((link) => {
11
+ return <link rel="alternate" hreflang={link.hreflang} href={pageUrl(link.href)} />
12
+ })
13
+ }
@@ -0,0 +1,11 @@
1
+ ---
2
+ import { Manifest } from "../lib/manifest.ts"
3
+ import { pageLocale } from "../lib/page.ts"
4
+ import type { MetadataProps } from "../lib/page.ts"
5
+
6
+ export type Props = Pick<MetadataProps, "locale">
7
+
8
+ const manifest = Manifest.url(pageLocale(Astro, Astro.props))
9
+ ---
10
+
11
+ {manifest && <link rel="manifest" href={manifest} />}