-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2992545
commit cfffc4b
Showing
5 changed files
with
77 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
import type { Props } from '@astrojs/starlight/props' | ||
import Default from '@astrojs/starlight/components/Head.astro' | ||
const ogImageUrl = new URL( | ||
`/og/${Astro.props.id.replace(/\.\w+$/, '.png')}`, | ||
Astro.site, | ||
) | ||
--- | ||
|
||
<Default {...Astro.props}><slot /></Default> | ||
|
||
<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,28 @@ | ||
import { getCollection } from 'astro:content' | ||
import { OGImageRoute } from 'astro-og-canvas' | ||
|
||
// 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({ | ||
pages, | ||
param: 'slug', | ||
getImageOptions: (_path, page: (typeof pages)[number]) => { | ||
return { | ||
title: page.data.title, | ||
description: page.data.description, | ||
// Specify the path to your background image. | ||
backgroundImage: '/assets/banner.png', | ||
// Add a semi-transparent background color on top of the image. | ||
// The color is specified in RGB format, and the alpha channel (opacity) is set to 0.4. | ||
backgroundColor: [24, 24, 27, 0.4], | ||
bgGradient: [[24, 24, 27]], | ||
border: { color: [63, 63, 70], width: 20 }, | ||
padding: 120, | ||
} | ||
}, | ||
}) |