Files
portfolio/app/composables/useSocialText.ts
2025-11-04 09:09:29 +03:30

41 lines
1.1 KiB
TypeScript

/**
* Social text utilities for localized, consistent labels.
* Generates LinkedIn button labels like:
* - en: "amir's linkedin" (lowercased first name with apostrophe)
* - fa: "لینکدین امیر"
*/
export function getFirstName(fullName: string): string {
if (!fullName) return ''
// Take first token, strip trailing punctuation and leading @
const first = (fullName.trim().split(/\s+/)[0] || '')
.replace(/[.,\-]+$/g, '')
.replace(/^@/, '')
return first
}
export function useSocialText() {
// i18n is auto-imported by Nuxt (via #imports)
const { locale } = useI18n()
/**
* Build a localized LinkedIn label using first name.
* - en: "{firstname}'s linkedin" all lowercase
* - fa: "لینکدین {firstname}"
*/
const linkedinText = (author: string): string => {
const first = getFirstName(author)
if (locale.value === 'fa') {
// Persian phrasing with provided first name as-is (data uses Latin names)
return `لینکدین ${first}`
}
// English lowercased per spec and with apostrophe
return `${first.toLowerCase()}'s linkedin`
}
return {
linkedinText
}
}