Skip to content

Commit ad3dfb2

Browse files
committed
fix: ogImage base url
1 parent 17abfeb commit ad3dfb2

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

app/composables/useBlogImages.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,21 @@ export const useBlogImages = () => {
1919
* Get the generated OG image URL for a blog post path
2020
*/
2121
const getOgImageUrl = (path: string): string => {
22-
// Convert path like '/blog/2.og-image-test' to 'blog/og-image-test'
23-
return `http://localhost:3000/__og-image__/static${path}/og.png`
22+
const config = useRuntimeConfig()
23+
const siteConfig = useSiteConfig()
24+
25+
// Get the base URL from site config or construct it
26+
const baseUrl = siteConfig.url || 'http://localhost:3000'
27+
28+
// Get the app base URL (e.g., '/litestar.dev-v2/')
29+
const appBase = config.app.baseURL || '/'
30+
31+
// Construct the full URL
32+
// Remove trailing slash from baseUrl and leading slash from appBase if needed
33+
const cleanBaseUrl = baseUrl.replace(/\/$/, '')
34+
const cleanAppBase = appBase === '/' ? '' : appBase.replace(/\/$/, '')
35+
36+
return `${cleanBaseUrl}${cleanAppBase}/__og-image__/static${path}/og.png`
2437
}
2538

2639
/**

nuxt.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export default defineNuxtConfig({
4848
'motion-v/nuxt',
4949
'@nuxtjs/google-fonts',
5050
],
51+
site: {
52+
url: process.env.NUXT_PUBLIC_SITE_URL || 'https://litestar-org.github.io',
53+
},
5154
$development: {
5255
site: {
5356
url: 'http://localhost:3000',

0 commit comments

Comments
 (0)