summaryrefslogtreecommitdiff
path: root/src/components/structure/MetaTags.svelte
blob: 11b94773401fb36c818b2ceeba2743a448585c59 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<script lang="ts">
    import type { Opt } from '@jet/environment/types/optional';
    import type { Organization, WithContext } from 'schema-dts';
    import type { WebRenderablePage } from '@jet-app/app-store/api/models/web-renderable-page';

    import MetaTags from '@amp/web-app-components/src/components/MetaTags/MetaTags.svelte';
    import type { SeoData } from '@amp/web-app-components/src/components/MetaTags/types';
    import { getLocale } from '@amp/web-app-components/src/utils/internal/locale';
    import { getPageDir } from '@amp/web-apps-localization/src';

    import { getI18n } from '~/stores/i18n';

    export let page: WebRenderablePage;

    const i18n = getI18n();
    const locale = getLocale();

    const organizationSchema: WithContext<Organization> = {
        '@context': 'https://schema.org',
        '@id': 'https://apps.apple.com/#organization',
        '@type': 'Organization',
        name: 'App Store',
        url: 'https://apps.apple.com',
        logo: 'https://apps.apple.com/assets/app-store.png',
        sameAs: [
            'https://www.wikidata.org/wiki/Q368215',
            'https://twitter.com/AppStore',
            'https://www.instagram.com/appstore/',
            'https://www.facebook.com/appstore/',
        ],
        parentOrganization: {
            '@type': 'Organization',
            name: 'Apple',
            '@id': 'https://www.apple.com/#organization',
            url: 'https://www.apple.com/',
        },
    };

    // This cast of `.seoData` is technically a little risky, but our app fully
    // defines this property, which should make it fairly safe. Whatever is returned
    // for the page from the `SEO` dependency on the Object Graph will be the value
    // reflected here.
    $: seoData = (page.seoData as Opt<SeoData>) ?? undefined;

    // Provide default title for pages not yet set up with SEO data
    $: defaultTitle = $i18n.t('ASE.Web.AppStore.Meta.SiteName');
    $: pageDir = getPageDir(locale.language) ?? 'ltr';
</script>

<MetaTags
    {defaultTitle}
    {locale}
    {pageDir}
    {seoData}
    origin={'https://apps.apple.com/'}
>
    <svelte:fragment slot="schemaOrganizationData">
        {#if import.meta.env.SSR}
            <svelte:element
                this="script"
                id="organization"
                type="application/ld+json"
            >
                {JSON.stringify(organizationSchema)}
            </svelte:element>
        {/if}
    </svelte:fragment>
</MetaTags>