astro-opengraph-images 1.2.1 → 1.3.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.3.1](https://github.com/shepherdjerred/astro-opengraph-images/compare/v1.3.0...v1.3.1) (2024-06-29)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * update import ([585b310](https://github.com/shepherdjerred/astro-opengraph-images/commit/585b3100ec97f3634a67d8b8a9694a56380fd388))
9
+
10
+ ## [1.3.0](https://github.com/shepherdjerred/astro-opengraph-images/compare/v1.2.1...v1.3.0) (2024-06-29)
11
+
12
+
13
+ ### Features
14
+
15
+ * use React jsx ([b2e8622](https://github.com/shepherdjerred/astro-opengraph-images/commit/b2e862217788735eacebf20396951193dfdb894d))
16
+
3
17
  ## [1.2.1](https://github.com/shepherdjerred/astro-opengraph-images/compare/v1.2.0...v1.2.1) (2024-06-29)
4
18
 
5
19
 
package/README.md CHANGED
@@ -1,32 +1,128 @@
1
- # Astro OpenGraph Images
1
+ <div align="center">
2
+ <h1>Astro OpenGraph Images</h1>
2
3
 
3
4
  [![astro-opengraph-images](https://img.shields.io/npm/v/astro-opengraph-images.svg)](https://www.npmjs.com/package/astro-opengraph-images)
4
5
 
5
- Generate fully customizable OpenGraph images with a few lines of code.
6
+ Generate fully customizable OpenGraph images for your entire Astro site with just a few lines of code.
7
+
8
+ This project is actively maintained. If you have a feature request or need help, please [create an issue](https://github.com/shepherdjerred/astro-opengraph-images/issues/new).
9
+
10
+ </div>
11
+
12
+ ## Features
13
+
14
+ - Generate OpenGraph images for every page on your site.
15
+ - Use a preset renderer to get started quickly.
16
+ - Use React syntax or vanilla JavaScript to define your own custom images.
17
+ - Supports both static pages and Astro content collections.
18
+ - Pages can be written in Markdown, MDX, HTML, or any other format.
19
+
20
+ > [!WARNING]
21
+ > This integration has only been tested with statically rendered sites. It is untested with server-side rendering.
6
22
 
7
23
  ## Quick Start
8
24
 
9
25
  1. Add this integration:
10
26
 
11
- ```bash
12
- npm i astro-opengraph-images
27
+ - Option 1: use the `astro` command:
28
+
29
+ ```bash
30
+ npx astro add astro-opengraph-images
31
+ ```
32
+
33
+ - Option 2: install the package and add the integration to your `astro.config.js`:
34
+
35
+ ```bash
36
+ npm i astro-opengraph-images
37
+ ```
38
+
39
+ ```typescript
40
+ import opengraphImages from "astro-opengraph-images";
41
+
42
+ export default defineConfig({
43
+ integrations: [opengraphImages()],
44
+ });
45
+ ```
46
+
47
+ 1. Configure the integration in your `astro.config.js` file:
48
+
49
+ ```typescript
50
+ // import presets
51
+ import astroOpenGraphImages, { presets } from "astro-opengraph-images";
52
+
53
+ // load any fonts you want to use
54
+ // either store these fonts with your project, or use `fetch` to download them when building
55
+ const path = new URL("./public/fonts/CommitMono/CommitMono-700-Regular.otf", import.meta.url);
56
+ const font = fs.readFileSync(path);
57
+
58
+ export default defineConfig({
59
+ integrations: [
60
+ opengraphImages({
61
+ options: {
62
+ width: 1200,
63
+ height: 630,
64
+ fonts: [
65
+ {
66
+ data: font,
67
+ name: "Commit Mono",
68
+ weight: 400,
69
+ style: "normal",
70
+ },
71
+ ],
72
+ },
73
+ // use a preset render function to get started
74
+ render: presets.blackAndWhite,
75
+ }),
76
+ ],
77
+ });
13
78
  ```
14
79
 
15
80
  1. Update your layout to add the appropriate `meta` tags. The [OpenGraph site](https://ogp.me/) has more information about valid tags. At a minimum, you should define the tags below.
16
81
 
17
- ```astro
18
- ---
19
- const { url } = Astro;
20
- ---
82
+ The integration will replace `[[OPENGRAPH IMAGE]]` with the path to the image it generated for that page. Note: `site` must be defined in your Astro config.
83
+
84
+ The image text comes from your page `<title />` and `<meta name="description" />` tags, so those should be defined.
21
85
 
22
- <meta property="og:title" content="" />
23
- <meta property="og:type" content="" />
24
- <meta property="og:url" content={url} />
25
- <meta property="og:image" content={url.toString()}openGraph.png} />
26
- ```
86
+ ```astro
87
+ ---
88
+ const { url, site } = Astro;
89
+ ---
90
+
91
+ <title>Your page title</title>
92
+
93
+ <meta name="description" content="Your page description" />
94
+
95
+ <meta property="og:title" content="" />
96
+ <meta property="og:type" content="" />
97
+ <meta property="og:url" content={url} />
98
+ <meta property="og:image" content={`${site?.toString()}[[OPENGRAPH IMAGE]]`} />
99
+ ```
27
100
 
28
101
  1. Confirm that your OpenGraph images are accessible. After you deploy these changes, navigate to [OpenGraph.xyz](https://www.opengraph.xyz/) and test your site.
29
102
 
103
+ ## Presets
104
+
105
+ Presets are located in [`src/presets/`](https://github.com/shepherdjerred/astro-opengraph-images/tree/main/src/presets). [Open a pull request](https://github.com/shepherdjerred/astro-opengraph-images/compare) to contribute a preset you've created.
106
+
107
+ Here are the current presets:
108
+
109
+ ### Black and White
110
+
111
+ This is what I use for my personal blog. It's a good starting point for creating your own custom images.
112
+
113
+ ![The black and white preset](./assets/presets/blackAndWhite.png)
114
+
115
+ ## Custom Renderers
116
+
117
+ You can create your own custom images with a render function. Take a look at how [a preset](https://github.com/shepherdjerred/astro-opengraph-images/blob/main/src/presets/blackAndWhite.tsx) works.
118
+
119
+ This library uses [Satori](https://github.com/vercel/satori) to convert React components to SVG. The SVG is then converted to a PNG using [resvg-js](https://github.com/yisibl/resvg-js).
120
+
121
+ > [!TIP]
122
+ > Satori supports [a subset of CSS](https://github.com/vercel/satori?tab=readme-ov-file#css). Be sure to familiarize yourself with its limitations.
123
+ >
124
+ > You can use the [Satori playground](https://og-playground.vercel.app/) to work on your images.
125
+
30
126
  ## Alternatives
31
127
 
32
128
  Here are some similar libraries using Satori and Astro. I haven't done a feature comparison.
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  export function blackAndWhite({ title, description }) {
3
- return (<div style={{
3
+ return (React.createElement("div", { style: {
4
4
  height: "100%",
5
5
  width: "100%",
6
6
  display: "flex",
@@ -10,17 +10,12 @@ export function blackAndWhite({ title, description }) {
10
10
  color: "#fff",
11
11
  fontFamily: "Commit Mono",
12
12
  fontSize: 72,
13
- }}>
14
- <div style={{
15
- marginTop: 96,
16
- }}>
17
- {title}
18
- </div>
19
- <div style={{
20
- fontSize: 40,
21
- }}>
22
- {description ?? ""}
23
- </div>
24
- </div>);
13
+ } },
14
+ React.createElement("div", { style: {
15
+ marginTop: 96,
16
+ } }, title),
17
+ React.createElement("div", { style: {
18
+ fontSize: 40,
19
+ } }, description ?? "")));
25
20
  }
26
- //# sourceMappingURL=blackAndWhite.jsx.map
21
+ //# sourceMappingURL=blackAndWhite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blackAndWhite.js","sourceRoot":"","sources":["../../src/presets/blackAndWhite.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,MAAM,UAAU,aAAa,CAAC,EAAE,KAAK,EAAE,WAAW,EAAuB;IACvE,OAAO,CACL,6BACE,KAAK,EAAE;YACL,MAAM,EAAE,MAAM;YACd,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,MAAM;YACf,aAAa,EAAE,QAAQ;YACvB,eAAe,EAAE,MAAM;YACvB,OAAO,EAAE,WAAW;YACpB,KAAK,EAAE,MAAM;YACb,UAAU,EAAE,aAAa;YACzB,QAAQ,EAAE,EAAE;SACb;QAED,6BACE,KAAK,EAAE;gBACL,SAAS,EAAE,EAAE;aACd,IAEA,KAAK,CACF;QACN,6BACE,KAAK,EAAE;gBACL,QAAQ,EAAE,EAAE;aACb,IAEA,WAAW,IAAI,EAAE,CACd,CACF,CACP,CAAC;AACJ,CAAC"}
@@ -1,4 +1,4 @@
1
- import { blackAndWhite } from "./blackAndWhite.jsx";
1
+ import { blackAndWhite } from "./blackAndWhite.js";
2
2
  export declare const presets: {
3
3
  blackAndWhite: typeof blackAndWhite;
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/presets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,eAAO,MAAM,OAAO;;CAEnB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/presets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,eAAO,MAAM,OAAO;;CAEnB,CAAC"}
@@ -1,4 +1,4 @@
1
- import { blackAndWhite } from "./blackAndWhite.jsx";
1
+ import { blackAndWhite } from "./blackAndWhite.js";
2
2
  export const presets = {
3
3
  blackAndWhite: blackAndWhite,
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/presets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,aAAa,EAAE,aAAa;CAC7B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/presets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,aAAa,EAAE,aAAa;CAC7B,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "astro-opengraph-images",
3
3
  "type": "module",
4
- "version": "1.2.1",
4
+ "version": "1.3.1",
5
5
  "scripts": {
6
6
  "prepare": "husky",
7
7
  "lint": "eslint src",
@@ -1,4 +1,4 @@
1
- import { blackAndWhite } from "./blackAndWhite.jsx";
1
+ import { blackAndWhite } from "./blackAndWhite.js";
2
2
 
3
3
  export const presets = {
4
4
  blackAndWhite: blackAndWhite,
@@ -1 +0,0 @@
1
- {"version":3,"file":"blackAndWhite.jsx","sourceRoot":"","sources":["../../src/presets/blackAndWhite.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,MAAM,UAAU,aAAa,CAAC,EAAE,KAAK,EAAE,WAAW,EAAuB;IACvE,OAAO,CACL,CAAC,GAAG,CACF,KAAK,CAAC,CAAC;YACL,MAAM,EAAE,MAAM;YACd,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,MAAM;YACf,aAAa,EAAE,QAAQ;YACvB,eAAe,EAAE,MAAM;YACvB,OAAO,EAAE,WAAW;YACpB,KAAK,EAAE,MAAM;YACb,UAAU,EAAE,aAAa;YACzB,QAAQ,EAAE,EAAE;SACb,CAAC,CAEF;MAAA,CAAC,GAAG,CACF,KAAK,CAAC,CAAC;YACL,SAAS,EAAE,EAAE;SACd,CAAC,CAEF;QAAA,CAAC,KAAK,CACR;MAAA,EAAE,GAAG,CACL;MAAA,CAAC,GAAG,CACF,KAAK,CAAC,CAAC;YACL,QAAQ,EAAE,EAAE;SACb,CAAC,CAEF;QAAA,CAAC,WAAW,IAAI,EAAE,CACpB;MAAA,EAAE,GAAG,CACP;IAAA,EAAE,GAAG,CAAC,CACP,CAAC;AACJ,CAAC"}