summaryrefslogtreecommitdiff
path: root/src/utils/seo/editorial-shelf-collection-page.ts
blob: dd152dfa1ff5d6288ca394bbcf7a7252334a8f72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type I18N from '@amp/web-apps-localization';
import type { GenericPage } from '@jet-app/app-store/api/models';
import type { SeoData } from '@amp/web-app-components/src/components/MetaTags/types';
import { isPageHeaderShelf } from '~/components/jet/shelf/PageHeaderShelf.svelte';
import { getPlatformFromPage } from '~/utils/seo/common';
import { commaSeparatedList } from '../string-formatting';

export function seoDataForEditorialShelfCollectionPage(
    page: GenericPage,
    i18n: I18N,
): SeoData {
    let title = page.title;
    let description;
    const headerShelf = page.shelves.find(isPageHeaderShelf);

    if (headerShelf) {
        title = headerShelf.items[0].title;
        description = headerShelf.items[0].subtitle;
    }

    if (!description) {
        const platform = getPlatformFromPage(page);
        const titles = page.shelves
            .filter((shelf) => !isPageHeaderShelf(shelf))
            .flatMap(({ items }) => items)
            .slice(0, 3)
            .map((item) => item.title);

        description = i18n.t(
            'ASE.Web.AppStore.Meta.EditorialShelfCollection.Description',
            {
                platform,
                listOfApps: commaSeparatedList(titles),
            },
        );
    }

    const titleWithSiteName = i18n.t(
        'ASE.Web.AppStore.Meta.TitleWithSiteName',
        { title },
    );

    return {
        pageTitle: titleWithSiteName,
        socialTitle: titleWithSiteName,
        appleTitle: titleWithSiteName,
        description,
        socialDescription: description,
        appleDescription: description,
    };
}