/ src / utils / seo / reviews-page.ts
reviews-page.ts
 1  import type {
 2      ReviewsPage,
 3      ShelfBasedProductPage,
 4  } from '@jet-app/app-store/api/models';
 5  import type { SeoData } from '@amp/web-app-components/src/components/MetaTags/types';
 6  import type { AppStoreObjectGraph } from '@jet-app/app-store/foundation/runtime/app-store-object-graph';
 7  import type I18N from '@amp/web-apps-localization';
 8  
 9  import { truncateAroundLimit } from '~/utils/string-formatting';
10  import { MAX_DESCRIPTION_LENGTH } from '~/utils/seo/common';
11  import { isProductBadgeShelf } from '~/components/jet/shelf/ProductBadgeShelf.svelte';
12  
13  export function seoDataForReviewsPage(
14      i18n: I18N,
15      page: ReviewsPage,
16      productPage: ShelfBasedProductPage,
17      objectGraph: AppStoreObjectGraph,
18  ): SeoData {
19      const appName = productPage.lockup.title;
20      const artworkUrl = productPage.lockup.icon?.template;
21      const badgeShelf = Object.values(productPage.shelfMapping).find(
22          isProductBadgeShelf,
23      );
24      const developerName = badgeShelf?.items.find(
25          ({ key }) => key === 'developer',
26      )?.caption;
27  
28      const title = i18n.t('ASE.Web.AppStore.Meta.TitleWithSiteName', {
29          title: i18n.t('ASE.Web.AppStore.Meta.Reviews.Title', {
30              appName,
31          }),
32      });
33  
34      const descriptionLocKey = developerName
35          ? 'ASE.Web.AppStore.Meta.Product.Description'
36          : 'ASE.Web.AppStore.Meta.Product.DescriptionWithoutDeveloperName';
37  
38      const description = truncateAroundLimit(
39          i18n.t(descriptionLocKey, {
40              appName,
41              developerName,
42          }),
43          MAX_DESCRIPTION_LENGTH,
44          objectGraph.locale.activeLanguage,
45      );
46  
47      return {
48          artworkUrl,
49          pageTitle: title,
50          socialTitle: title,
51          appleTitle: title,
52          description,
53          socialDescription: description,
54          appleDescription: description,
55      };
56  }