Skip to content

Commit

Permalink
fix twitter preview image & add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vincanger committed Nov 27, 2024
1 parent 9e0bb6f commit e467048
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 0 deletions.
10 changes: 10 additions & 0 deletions opensaas-sh/blog/public/og-images/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Images stored here must follow the naming convention `<post-slug>.webp` and must always be .webp files, e.g. `2023-11-21-coverlettergpt.webp`.

This is because OG Image URLs are automatically generated for each blog post based on the logic in `src/components/HeadWithOGImage.astro`:

```tsx
const ogImageUrl = new URL(
`/og-images/${Astro.props.id.replace(/blog\//, '').replace(/\.\w+$/, '.webp')}`,
Astro.site,
)
```
2 changes: 2 additions & 0 deletions opensaas-sh/blog/src/components/HeadWithOGImage.astro
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ const ogImageUrl = new URL(

<!-- Open Graph images. -->
<meta property="og:image" content={ogImageUrl} />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:image" content={ogImageUrl} />
1 change: 1 addition & 0 deletions template/blog/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default defineConfig({
components: {
SiteTitle: './src/components/MyHeader.astro',
ThemeSelect: './src/components/MyThemeSelect.astro',
Head: './src/components/HeadWithOGImage.astro',
},

social: {
Expand Down
Binary file not shown.
10 changes: 10 additions & 0 deletions template/blog/public/og-images/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Images stored here must follow the naming convention `<post-slug>.webp` and must always be .webp files, e.g. `2023-11-21-coverlettergpt.webp`.

This is because OG Image URLs are automatically generated for each blog post based on the logic in `src/components/HeadWithOGImage.astro`:

```tsx
const ogImageUrl = new URL(
`/og-images/${Astro.props.id.replace(/blog\//, '').replace(/\.\w+$/, '.webp')}`,
Astro.site,
)
```
19 changes: 19 additions & 0 deletions template/blog/src/components/HeadWithOGImage.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
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-images/${Astro.props.id.replace(/blog\//, '').replace(/\.\w+$/, '.webp')}`,
Astro.site,
)
---

<Default {...Astro.props}><slot /></Default>

<!-- Open Graph images. -->
<meta property="og:image" content={ogImageUrl} />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:image" content={ogImageUrl} />
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
title: How I Built & Grew CoverLetterGPT to 5,000 Users and $200 MRR
date: 2023-11-21
tags: ["indiehacker", "saas", "sideproject"]
cover:
image: ../../../../public/og-images/2023-11-21-coverlettergpt.webp
alt: CoverLetterGPT
---
## Hey, I’m Vince…

Expand Down

0 comments on commit e467048

Please sign in to comment.