|
1 | 1 | <script setup lang="ts"> |
2 | | -import { ACCENT_COLOR_IDS, ACCENT_COLOR_TOKENS, type AccentColorId } from '#shared/utils/constants' |
| 2 | +import { type AccentColorId, ACCENT_COLOR_TOKENS } from '#shared/utils/constants' |
3 | 3 |
|
4 | 4 | // This page exists only as a rendering target for nuxt-og-image. |
5 | 5 | // Visiting it directly redirects to the package page. |
6 | 6 |
|
7 | | -const route = useRoute() |
8 | | -const org = (route.params as any).org as string | undefined |
9 | | -const name = (route.params as any).name as string |
| 7 | +const route = useRoute('share-card-org-name') |
| 8 | +const { org, name } = route.params |
10 | 9 | const packageName = org ? `${org}/${name}` : name |
11 | 10 | const theme = route.query.theme === 'light' ? 'light' : 'dark' |
12 | | -const colorParam = route.query.color as string | undefined |
13 | | -const color: AccentColorId = ACCENT_COLOR_IDS.includes(colorParam as AccentColorId) |
14 | | - ? (colorParam as AccentColorId) |
15 | | - : 'sky' |
16 | | -
|
17 | | -const primaryColor = ACCENT_COLOR_TOKENS[color][theme].hex |
| 11 | +const colorParam = route.query.color |
| 12 | +const color: AccentColorId = |
| 13 | + typeof colorParam === 'string' && colorParam in ACCENT_COLOR_TOKENS |
| 14 | + ? (colorParam as AccentColorId) |
| 15 | + : 'sky' |
18 | 16 |
|
19 | 17 | defineOgImageComponent( |
20 | 18 | 'ShareCard', |
21 | | - { name: packageName, theme, primaryColor }, |
| 19 | + { name: packageName, theme, color }, |
22 | 20 | { width: 1280, height: 520 }, |
23 | 21 | ) |
24 | 22 |
|
|
0 commit comments