Skip to content

Commit

Permalink
fix: add more context to site
Browse files Browse the repository at this point in the history
  • Loading branch information
shepherdjerred committed Jul 2, 2024
1 parent 531d5f4 commit 3db768a
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 54 deletions.
122 changes: 70 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,64 +111,82 @@ You've probably seen this in action when posting a link on Facebook, Twitter, Sl
```diff
export default defineConfig({
+ site: "https://<your site>.com",
});
```
The `site` property is required because Open Graph images must be referenced as an absolute URL.
- site: "https://<your site>.com",
integrations: [
opengraphImages({
options: {
fonts: [
{
name: "Roboto",
weight: 400,
style: "normal",
data: fs.readFileSync("node_modules/@fontsource/roboto/files/roboto-latin-400-normal.woff"),
},
],
},
render: presets.blackAndWhite,
}),
],
});
Install the [`astro-seo`](https://github.com/jonasmerlin/astro-seo) package to make this a bit easier:
````
```bash
npm i astro-seo
```
The `site` property is required because Open Graph images must be referenced as an absolute URL.
Update your Astro layout:
Install the [`astro-seo`](https://github.com/jonasmerlin/astro-seo) package to make this a bit easier:
```diff
---
+ import { SEO } from "astro-seo";
interface Props {
title: string;
}
const { title } = Astro.props;
+const { url, site } = Astro;
+const openGraphImageUrl = getImagePath({ url, site });
---
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="description" content="Astro description" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
+ <SEO
+ openGraph={
+ {
+ basic: {
+ title: title,
+ type: "website",
+ image: openGraphImageUrl,
+ url: url,
+ },
+ optional: {
+ description: "My page description",
+ },
+ }
+ }
+ />
</head>
<body>
<slot />
</body>
</html>
```
```bash
npm i astro-seo
````
Update your Astro layout:
```diff
---
+ import { SEO } from "astro-seo";
interface Props {
title: string;
}
const { title } = Astro.props;
+const { url, site } = Astro;
+const openGraphImageUrl = getImagePath({ url, site });
---
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="description" content="Astro description" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
+ <SEO
+ openGraph={
+ {
+ basic: {
+ title: title,
+ type: "website",
+ image: openGraphImageUrl,
+ url: url,
+ },
+ optional: {
+ description: "My page description",
+ },
+ }
+ }
+ />
</head>
<body>
<slot />
</body>
</html>
```
1. Build your site. You should see a `.png` file next to each `.html` page in your `dist` folder. Double-check that the `og:image` proprety in your `.html` file matches the path to the `.png` file.
Expand Down
17 changes: 16 additions & 1 deletion README.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,22 @@ You've probably seen this in action when posting a link on Facebook, Twitter, Sl

```diff
export default defineConfig({
+ site: "https://<your site>.com",
+ site: "https://<your site>.com",
integrations: [
opengraphImages({
options: {
fonts: [
{
name: "Roboto",
weight: 400,
style: "normal",
data: fs.readFileSync("node_modules/@fontsource/roboto/files/roboto-latin-400-normal.woff"),
},
],
},
render: presets.blackAndWhite,
}),
],
});
```

Expand Down
1 change: 0 additions & 1 deletion example/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { defineConfig } from "astro/config";

import opengraphImages, { presets } from "astro-opengraph-images";

// https://astro.build/config
Expand Down

0 comments on commit 3db768a

Please sign in to comment.