common.ts
1 import type { Opt } from '@jet/environment/types/optional'; 2 import type { Organization } from 'schema-dts'; 3 import type { WebRenderablePage } from '@jet-app/app-store/api/models/web-renderable-page'; 4 5 import type I18N from '@amp/web-apps-localization'; 6 import type { SeoData } from '@amp/web-app-components/src/components/MetaTags/types'; 7 8 export const MAX_DESCRIPTION_LENGTH = 160; 9 10 export const AppleOrganization: Organization = { 11 '@type': 'Organization', 12 name: 'Apple Inc', 13 url: 'http://www.apple.com', 14 logo: { 15 '@type': 'ImageObject', 16 url: 'https://www.apple.com/ac/structured-data/images/knowledge_graph_logo.png', 17 }, 18 }; 19 20 export function updateCanonicalURL( 21 page: WebRenderablePage, 22 canonicalURL: string, 23 ): void { 24 const seoData = page.seoData as Opt<SeoData>; 25 26 if (!seoData) { 27 return; 28 } 29 30 seoData.url = canonicalURL; 31 } 32 33 export function seoDataForAnyPage( 34 page: WebRenderablePage, 35 i18n: I18N, 36 ): SeoData { 37 const pageTitle = 38 'title' in page 39 ? i18n.t('ASE.Web.AppStore.Meta.TitleWithPlatformAndSiteName', { 40 title: page.title, 41 platform: getPlatformFromPage(page), 42 }) 43 : i18n.t('ASE.Web.AppStore.Meta.SiteName'); 44 45 const description = i18n.t('ASE.Web.AppStore.Meta.Description'); 46 47 return { 48 url: page.canonicalURL ?? '', 49 siteName: i18n.t('ASE.Web.AppStore.Meta.SiteName'), 50 51 pageTitle, 52 socialTitle: pageTitle, 53 appleTitle: pageTitle, 54 55 description, 56 socialDescription: description, 57 appleDescription: description, 58 59 width: 1200, 60 height: 630, 61 twitterWidth: 1200, 62 twitterHeight: 630, 63 twitterCropCode: 'wa', 64 crop: 'wa', 65 fileType: 'jpg', 66 artworkUrl: '/assets/images/share/app-store.png', 67 68 twitterSite: '@AppStore', 69 }; 70 } 71 72 export function getPlatformFromPage(page: WebRenderablePage): Opt<string> { 73 return page.webNavigation?.platforms.find((platform) => platform.isActive) 74 ?.action.title; 75 }