diff options
| author | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
|---|---|---|
| committer | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
| commit | bce557cc2dc767628bed6aac87301a1be7c5431b (patch) | |
| tree | b51a051228d01fe3306cd7626d4a96768aadb944 /src/utils/seo/search-results-page.ts | |
init commit
Diffstat (limited to 'src/utils/seo/search-results-page.ts')
| -rw-r--r-- | src/utils/seo/search-results-page.ts | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/utils/seo/search-results-page.ts b/src/utils/seo/search-results-page.ts new file mode 100644 index 0000000..48bcdce --- /dev/null +++ b/src/utils/seo/search-results-page.ts @@ -0,0 +1,56 @@ +import type { SearchResultsPage } from '@jet-app/app-store/api/models'; +import type { SeoData } from '@amp/web-app-components/src/components/MetaTags/types'; +import type I18N from '@amp/web-apps-localization'; +import { + isSearchResultShelf, + isRenderableInSearchResultsShelf, +} from '~/components/jet/shelf/SearchResultShelf.svelte'; +import { commaSeparatedList } from '../string-formatting'; + +export function seoDataForSearchResultsPage( + page: SearchResultsPage, + i18n: I18N, + language: string, +): SeoData { + const term = page?.searchTermContext?.term; + const pageTitle = i18n.t('ASE.Web.AppStore.Meta.TitleWithSiteName', { + title: page?.searchTermContext?.term, + }); + const shareTitle = i18n.t('ASE.Web.AppStore.Meta.TitleWithSiteName', { + title: i18n.t('ASE.Web.AppStore.Meta.SearchResults.Title', { + term: page?.searchTermContext?.term, + }), + }); + + const resultsShelf = page?.shelves?.find(isSearchResultShelf) ?? null; + + const renderableItems = (resultsShelf?.items ?? []).filter( + isRenderableInSearchResultsShelf, + ); + + const appNames = renderableItems + .slice(0, 3) + .map((item) => item.lockup.title); + + let description; + if (appNames.length) { + description = i18n.t( + 'ASE.Web.AppStore.Meta.SearchResults.Description', + { + term, + listOfApps: commaSeparatedList(appNames, language), + }, + ); + } + + return term + ? { + pageTitle, + socialTitle: shareTitle, + appleTitle: shareTitle, + description, + socialDescription: description, + appleDescription: description, + } + : {}; +} |
