@mannisto/astro-metadata 2.0.0 → 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.
- package/README.md +21 -5
- package/package.json +8 -8
- package/src/lib/config.ts +2 -2
- package/src/lib/page.ts +5 -4
- package/src/lib/site.ts +4 -3
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|

|
|
7
|
+

|
|
7
8
|

|
|
8
9
|
|
|
9
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.
|
|
@@ -14,8 +15,6 @@ The page metadata for Astro: the title, the description, the canonical URL, soci
|
|
|
14
15
|
npm install @mannisto/astro-metadata
|
|
15
16
|
```
|
|
16
17
|
|
|
17
|
-
The integration requires Astro 6.4.6 or later, or Astro 7.
|
|
18
|
-
|
|
19
18
|
## Configuration
|
|
20
19
|
|
|
21
20
|
```typescript
|
|
@@ -194,6 +193,25 @@ metadata({
|
|
|
194
193
|
|
|
195
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.
|
|
196
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
|
+
|
|
197
215
|
### Locales
|
|
198
216
|
|
|
199
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.
|
|
@@ -292,7 +310,7 @@ favicon: {
|
|
|
292
310
|
}
|
|
293
311
|
```
|
|
294
312
|
|
|
295
|
-
The extension
|
|
313
|
+
The file extension decides the format: `.ico`, `.png` or `.svg`. The name and the size decide where the file goes:
|
|
296
314
|
|
|
297
315
|
- `.ico` and `.svg` files, and `.png` files smaller than 192 px, get an icon link tag.
|
|
298
316
|
- `apple-touch-icon.png` gets the Apple link tag.
|
|
@@ -413,8 +431,6 @@ For a personal site, use `publisher: { type: "Person" }`. Set `schema: false` to
|
|
|
413
431
|
/>
|
|
414
432
|
```
|
|
415
433
|
|
|
416
|
-
All items go into one graph. The items link to each other with `@id`, and all URLs are absolute.
|
|
417
|
-
|
|
418
434
|
## Dev toolbar app
|
|
419
435
|
|
|
420
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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mannisto/astro-metadata",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
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",
|
|
@@ -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.
|
|
47
|
+
"@playwright/test": "^1.64.1",
|
|
48
48
|
"@types/node": "^22.20.5",
|
|
49
|
-
"astro": "^7.
|
|
50
|
-
"eslint": "^10.
|
|
49
|
+
"astro": "^7.4.2",
|
|
50
|
+
"eslint": "^10.13.0",
|
|
51
51
|
"eslint-config-prettier": "^10.1.8",
|
|
52
|
-
"prettier": "^3.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.
|
|
57
|
-
"vitest": "^4.1.
|
|
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.
|
|
62
|
+
"schema-dts": "^2.1.0"
|
|
63
63
|
}
|
|
64
64
|
}
|
package/src/lib/config.ts
CHANGED
|
@@ -48,8 +48,8 @@ export type MetadataConfig = {
|
|
|
48
48
|
titleTemplate?: Localized
|
|
49
49
|
/** The description of a page without a description. */
|
|
50
50
|
description?: Localized
|
|
51
|
-
/** The social image of a page without an image. */
|
|
52
|
-
image?: Omit<MetadataImage, "alt"> & { alt?: Localized }
|
|
51
|
+
/** The social image of a page without an image. The URL and the alt text can have a value for each locale. */
|
|
52
|
+
image?: Omit<MetadataImage, "url" | "alt"> & { url: Localized; alt?: Localized }
|
|
53
53
|
twitter?: {
|
|
54
54
|
/** The card type for pages with an image. Defaults to "summary_large_image". */
|
|
55
55
|
card?: "summary" | "summary_large_image"
|
package/src/lib/page.ts
CHANGED
|
@@ -106,15 +106,16 @@ export function pageHreflang(page: I18nPage, props: MetadataProps): HreflangLink
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
|
-
* Returns the social image of the page: the prop, or the image of the config with the
|
|
110
|
-
* text of the locale.
|
|
109
|
+
* Returns the social image of the page: the prop, or the image of the config with the URL
|
|
110
|
+
* and the alt text of the locale.
|
|
111
111
|
*/
|
|
112
112
|
export function pageImage(props: MetadataProps, locale?: string): MetadataImage | undefined {
|
|
113
113
|
if (props.image) return props.image
|
|
114
114
|
|
|
115
115
|
const image = getConfig().image
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
const url = localize(image?.url, locale)
|
|
117
|
+
if (!image || !url) return undefined
|
|
118
|
+
return { ...image, url, alt: localize(image.alt, locale) }
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
/**
|
package/src/lib/site.ts
CHANGED
|
@@ -45,16 +45,17 @@ export const Site = {
|
|
|
45
45
|
},
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* Returns the `image` with an absolute URL
|
|
48
|
+
* Returns the `image` of the locale, with an absolute URL and the alt text of the locale.
|
|
49
49
|
*
|
|
50
50
|
* @example Site.image() // { url: "https://example.com/og.jpg", alt: "Acme Studio", … }
|
|
51
51
|
*/
|
|
52
52
|
image(options: SiteOptions = {}): MetadataImage | undefined {
|
|
53
53
|
const image = getConfig().image
|
|
54
|
-
|
|
54
|
+
const path = localize(image?.url, options.locale)
|
|
55
|
+
if (!image || !path) return undefined
|
|
55
56
|
|
|
56
57
|
return {
|
|
57
|
-
url: url(
|
|
58
|
+
url: url(path),
|
|
58
59
|
alt: localize(image.alt, options.locale),
|
|
59
60
|
width: image.width,
|
|
60
61
|
height: image.height,
|