diff --git a/src/pages/uxcg/[slug].tsx b/src/pages/uxcg/[slug].tsx index 0b6ec79e..9a9856ae 100644 --- a/src/pages/uxcg/[slug].tsx +++ b/src/pages/uxcg/[slug].tsx @@ -11,6 +11,7 @@ import { generateQuestionsSeo, getAdjacentUXCGTitles, mergeQuestionsLocalization, + slimUXCGQuestions, } from '@uxcore/lib/helpers'; import { getUXCGSlugPaths } from '@uxcore/lib/paths'; import { @@ -289,17 +290,15 @@ export const getStaticProps: GetStaticProps = async ({ params, locale }) => { currentSlug: slug, languageSwitchSlugs, tags, - questionsTest: questions, questionsSeo, title: question?.attributes?.title || '', mainSeo, modalData: uxcgData || null, answerRelatedQuestions: answerRelatedQuestions || null, questionsLength: sortedQuestions?.length, - questions: sortedQuestions, - allQuestions: questions, + allQuestions: slimUXCGQuestions(questions, locale), id: question?.attributes.number || null, - biases, + biases: { [locale]: biases[locale as 'en' | 'ru' | 'hy'] ?? [] }, }, revalidate: 5, }; diff --git a/src/pages/uxcg/index.tsx b/src/pages/uxcg/index.tsx index 22132d9d..c07e62d6 100644 --- a/src/pages/uxcg/index.tsx +++ b/src/pages/uxcg/index.tsx @@ -1,25 +1,19 @@ -import { GetStaticProps } from 'next'; -import { useRouter } from 'next/router'; -import React, { FC, useMemo, useState } from 'react'; - -import { QuestionType, TagType } from '@uxcore/local-types/data'; -import { TRouter } from '@uxcore/local-types/global'; - -import { - generateQuestionsSeo, - mergeBiasesLocalization, - mergeQuestionsLocalization, -} from '@uxcore/lib/helpers'; - -import { getStrapiBiases } from '@uxcore/api/biases'; import { getUXCGSeo } from '@uxcore/api/mainPageSeo'; import { getStrapiQuestions } from '@uxcore/api/questions'; import { getTags } from '@uxcore/api/tags'; - import SeoGenerator from '@uxcore/components/SeoGenerator'; import Spinner from '@uxcore/components/Spinner'; - import UXCGLayout from '@uxcore/layouts/UXCGLayout'; +import { + generateQuestionsSeo, + mergeQuestionsLocalization, + slimUXCGQuestions, +} from '@uxcore/lib/helpers'; +import { QuestionType, TagType } from '@uxcore/local-types/data'; +import { TRouter } from '@uxcore/local-types/global'; +import { GetStaticProps } from 'next'; +import { useRouter } from 'next/router'; +import React, { FC, useMemo, useState } from 'react'; interface UxcgProps { tags: TagType[]; @@ -72,12 +66,6 @@ export default Index; export const getStaticProps: GetStaticProps = async ({ locale }) => { const tags = getTags(); const questions = await getStrapiQuestions(); - const biases = await getStrapiBiases(); - const sortedBiases = mergeBiasesLocalization( - biases.en, - biases.ru, - biases.hy, - ).sort((a, b) => a.number - b.number); // HYTranslation TODO const sortedQuestions = mergeQuestionsLocalization( questions.en, @@ -91,11 +79,10 @@ export const getStaticProps: GetStaticProps = async ({ locale }) => { return { props: { - biases: sortedBiases, tags, questionsSeo, mainSeo, - allQuestions: questions, + allQuestions: slimUXCGQuestions(questions, locale), }, revalidate: 5, }; diff --git a/src/uxcore/lib/helpers.ts b/src/uxcore/lib/helpers.ts index 34f05658..4cfa3b1d 100644 --- a/src/uxcore/lib/helpers.ts +++ b/src/uxcore/lib/helpers.ts @@ -525,3 +525,24 @@ export const getAdjacentUXCGTitles = (locale, uxcgDats, activeQuestion) => { next: nextQuestion ? `${nextQuestion.slug}` : null, }; }; + +// UXCG pages ship every locale's questions so search can match aliases in any +// language. Only the current locale is rendered; the others keep the fields +// search reads, which cuts each page's data by several hundred KB. +export const slimUXCGQuestions = ( + questions: Record<'en' | 'ru' | 'hy', any[]>, + locale: string, +) => + Object.fromEntries( + Object.entries(questions).map(([key, list]) => [ + key, + key === locale + ? list + : (list || []).map(({ attributes }) => ({ + attributes: { + number: attributes?.number ?? null, + aliases: attributes?.aliases ?? null, + }, + })), + ]), + );