-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tried adding opengraph to the docs site
- Loading branch information
1 parent
73b41d9
commit 77c6179
Showing
5 changed files
with
108 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
import type { Props } from '@astrojs/starlight/props' | ||
import Default from '@astrojs/starlight/components/Head.astro' | ||
// Get the URL of the generated image for the current page using its | ||
// ID and replace the file extension with `.png`. | ||
const ogImageUrl = new URL( | ||
`/og/${Astro.props.id.replace(/\.\w+$/, '.png')}`, | ||
Astro.site, | ||
) | ||
--- | ||
|
||
<!-- Render the default <Head/> component. --> | ||
<Default {...Astro.props}><slot /></Default> | ||
|
||
<!-- Render the <meta/> tags for the Open Graph images. --> | ||
<meta property="og:image" content={ogImageUrl} /> | ||
<meta name="twitter:image" content={ogImageUrl} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { OGImageRoute } from "astro-og-canvas"; | ||
import { getCollection } from "astro:content"; | ||
|
||
// Get all entries from the `docs` content collection. | ||
const entries = await getCollection("docs"); | ||
|
||
// Map the entry array to an object with the page ID as key and the | ||
// frontmatter data as value. | ||
const pages = Object.fromEntries(entries.map(({ data, id }) => [id, { data }])); | ||
|
||
export const { getStaticPaths, GET } = OGImageRoute({ | ||
// Pass down the documentation pages. | ||
pages, | ||
// Define the name of the parameter used in the endpoint path, here `slug` | ||
// as the file is named `[...slug].ts`. | ||
param: "slug", | ||
// Define a function called for each page to customize the generated image. | ||
getImageOptions: (_path, page: (typeof pages)[number]) => { | ||
return { | ||
// Use the page title and description as the image title and description. | ||
title: page.data.title, | ||
description: page.data.description, | ||
// Customize various colors and add a border. | ||
bgGradient: [[24, 24, 27]], | ||
border: { color: [63, 63, 70], width: 20 }, | ||
padding: 120, | ||
}; | ||
}, | ||
}); |