Skip to content

Commit 722ce3c

Browse files
timothejoubertTimothe Joubert
andauthored
feat: update social link handling (#602)
Co-authored-by: Timothe Joubert <timothejoubert26@gmail.com>
1 parent 4bd415f commit 722ce3c

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

app/composables/use-common-content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface CommonContent {
1616
footers?: Partial<CommonContentFooters>
1717
errorPage?: RoadizWalker
1818
accessibility?: RoadizNodesSources
19-
urls?: Record<`${string}_url`, unknown>
19+
urls?: Record<`${string}_url` | `${string}Url`, unknown>
2020
}
2121

2222
export const COMMON_CONTENT_KEY = 'commonContent'

app/composables/use-roadiz-head-socials.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,38 @@ export interface SocialLink {
66
}
77

88
export function getSocialLinks({ key, url }: { key: string, url: string }) {
9-
const _key = key.toLowerCase()
9+
// Remove trailing "url" and convert to lowercase for better matching
10+
// For example, "twitterUrl" becomes "twitter", "linkedin_url" becomes "linkedin"
11+
const formattedKey = key.toLowerCase().replace(/_?url$/, '')
1012

11-
if (_key.startsWith('mastodon')) {
13+
if (formattedKey.startsWith('mastodon')) {
1214
return { url: url, name: 'Mastodon', icon: 'social-mastodon' }
1315
}
14-
if (_key.startsWith('pinterest')) {
16+
if (formattedKey.startsWith('pinterest')) {
1517
return { url: url, name: 'Pinterest', icon: 'social-pinterest' }
1618
}
17-
if (_key.startsWith('snapchat')) {
19+
if (formattedKey.startsWith('snapchat')) {
1820
return { url: url, name: 'Snapchat', icon: 'social-snapchat' }
1921
}
20-
if (_key.startsWith('instagram')) {
22+
if (formattedKey.startsWith('instagram')) {
2123
return { url: url, name: 'Instagram', icon: 'social-instagram' }
2224
}
23-
if (_key.startsWith('youtube')) {
25+
if (formattedKey.startsWith('youtube')) {
2426
return { url: url, name: 'Youtube', icon: 'social-youtube' }
2527
}
26-
if (_key.startsWith('linkedin')) {
28+
if (formattedKey.startsWith('linkedin')) {
2729
return { url: url, name: 'LinkedIn', icon: 'social-linkedin' }
2830
}
29-
if (_key.startsWith('facebook')) {
31+
if (formattedKey.startsWith('facebook')) {
3032
return { url: url, name: 'Facebook', icon: 'social-facebook' }
3133
}
32-
if (_key.startsWith('tiktok')) {
34+
if (formattedKey.startsWith('tiktok')) {
3335
return { url: url, name: 'Tiktok', icon: 'social-tiktok' }
3436
}
35-
if (_key.startsWith('spotify')) {
37+
if (formattedKey.startsWith('spotify')) {
3638
return { url: url, name: 'Spotify', icon: 'social-spotify' }
3739
}
38-
if (_key.startsWith('twitter') || _key.startsWith('x_')) {
40+
if (formattedKey.startsWith('twitter') || formattedKey === 'x') {
3941
return { url: url, name: 'X', icon: 'social-x' }
4042
}
4143

0 commit comments

Comments
 (0)