From 1d3a688131ac884490486bbad50aab67e3f80e5d Mon Sep 17 00:00:00 2001 From: LufyCZ Date: Wed, 13 Nov 2024 16:43:13 +0100 Subject: [PATCH] feat(apps/web): fix sitemaps (#1748) --- apps/web/src/app/(cms)/academy/sitemap.ts | 6 ++-- apps/web/src/app/(cms)/blog/sitemap.ts | 2 +- apps/web/src/app/(cms)/faq/sitemap.ts | 35 +++++++++++++++++++ apps/web/src/app/sitemap-index.xml/route.ts | 1 + .../strapi/queries/faq-answer-search.ts | 6 ++-- 5 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 apps/web/src/app/(cms)/faq/sitemap.ts diff --git a/apps/web/src/app/(cms)/academy/sitemap.ts b/apps/web/src/app/(cms)/academy/sitemap.ts index ca16e4ddb1..12d1a3630e 100644 --- a/apps/web/src/app/(cms)/academy/sitemap.ts +++ b/apps/web/src/app/(cms)/academy/sitemap.ts @@ -15,19 +15,19 @@ export default async function sitemap(): Promise { { url: 'https://www.sushi.com/academy', lastModified: new Date(), - changeFrequency: 'yearly', + changeFrequency: 'weekly', }, { url: 'https://www.sushi.com/academy/explore', lastModified: new Date(), - changeFrequency: 'yearly', + changeFrequency: 'weekly', }, ...products.map( (product) => ({ url: `https://www.sushi.com/academy/products/${product}`, lastModified: new Date(), - changeFrequency: 'yearly', + changeFrequency: 'monthly', }) as const, ), ...articles.map( diff --git a/apps/web/src/app/(cms)/blog/sitemap.ts b/apps/web/src/app/(cms)/blog/sitemap.ts index a5a3b4be2d..0af5ba12f3 100644 --- a/apps/web/src/app/(cms)/blog/sitemap.ts +++ b/apps/web/src/app/(cms)/blog/sitemap.ts @@ -13,7 +13,7 @@ export default async function sitemap(): Promise { { url: 'https://www.sushi.com/blog', lastModified: new Date(), - changeFrequency: 'yearly', + changeFrequency: 'daily', }, ...articles.map( (article) => diff --git a/apps/web/src/app/(cms)/faq/sitemap.ts b/apps/web/src/app/(cms)/faq/sitemap.ts new file mode 100644 index 0000000000..9876c7d03f --- /dev/null +++ b/apps/web/src/app/(cms)/faq/sitemap.ts @@ -0,0 +1,35 @@ +import { getFaqAnswerSearch } from '@sushiswap/graph-client/strapi' +import type { MetadataRoute } from 'next' + +export const revalidate = 0 + +export default async function sitemap(): Promise { + try { + const { answers, answerGroups } = await getFaqAnswerSearch({ + search: '', + pagination: { + limit: 10000, + }, + }) + + const combined = answers.concat(answerGroups) + + return [ + { + url: 'https://www.sushi.com/faq', + lastModified: new Date(), + changeFrequency: 'weekly', + }, + ...combined.map( + (answer) => + ({ + url: `https://www.sushi.com/faq/${answer.slug}`, + changeFrequency: 'weekly', + }) as const, + ), + ] + } catch { + console.error('sitemap: Error fetching faq articles') + return [] + } +} diff --git a/apps/web/src/app/sitemap-index.xml/route.ts b/apps/web/src/app/sitemap-index.xml/route.ts index 290c54bc90..24a83a1e7d 100644 --- a/apps/web/src/app/sitemap-index.xml/route.ts +++ b/apps/web/src/app/sitemap-index.xml/route.ts @@ -4,6 +4,7 @@ import { getNetworkKey } from 'src/lib/network' const sitemapFiles = [ '/academy/sitemap.xml', '/blog/sitemap.xml', + '/faq/sitemap.xml', ...CHAIN_IDS.map(getNetworkKey).map((key) => `/sitemap/${key}.xml`), '/aptos/sitemap.xml', '/tron/sitemap.xml', diff --git a/packages/graph-client/src/subgraphs/strapi/queries/faq-answer-search.ts b/packages/graph-client/src/subgraphs/strapi/queries/faq-answer-search.ts index a4a95ef4c7..709318390f 100644 --- a/packages/graph-client/src/subgraphs/strapi/queries/faq-answer-search.ts +++ b/packages/graph-client/src/subgraphs/strapi/queries/faq-answer-search.ts @@ -5,8 +5,8 @@ import { graphql } from '../graphql' import { STRAPI_GRAPHQL_URL } from 'src/subgraphs/strapi/constants' export const StrapiFaqAnswerSearchQuery = graphql( - `query FaqAnswerSearch($search: String!) { - faqAnswers(filters: { name: { containsi: $search } }) { + `query FaqAnswerSearch($search: String!, $pagination: PaginationArg = {}) { + faqAnswers(filters: { name: { containsi: $search } }, pagination: $pagination) { data { attributes { name @@ -29,7 +29,7 @@ export const StrapiFaqAnswerSearchQuery = graphql( } } - faqAnswerGroups(filters: { name: { containsi: $search } }) { + faqAnswerGroups(filters: { name: { containsi: $search } }, pagination: $pagination) { data { attributes { name