Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(apps/web): sitemap #1731

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ out/
build
dist
robots.txt
sitemap*.xml
analyze/

# misc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ interface DifficultyLabel {
export function DifficultyLabel({ article, isCard }: DifficultyLabel) {
const difficulty = article.difficulty

if (!difficulty) return <></>

const slug = difficulty.slug as keyof typeof DIFFICULTY_ELEMENTS
if (!slug) return <></>

Expand Down
44 changes: 44 additions & 0 deletions apps/web/src/app/(cms)/academy/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { getAcademyArticles } from '@sushiswap/graph-client/strapi'
import type { MetadataRoute } from 'next'

const products = ['bentobox', 'furo', 'onsen', 'sushixswap']

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
try {
const { articles } = await getAcademyArticles({
pagination: { pageSize: 10000 },
})

return [
{
url: 'https://sushi.com/academy',
lastModified: new Date(),
changeFrequency: 'yearly',
},
{
url: 'https://sushi.com/academy/explore',
lastModified: new Date(),
changeFrequency: 'yearly',
},
...products.map(
(product) =>
({
url: `https://sushi.com/academy/products/${product}`,
lastModified: new Date(),
changeFrequency: 'yearly',
}) as const,
),
...articles.map(
(article) =>
({
url: `https://sushi.com/academy/${article.slug}`,
lastModified: new Date(article.updatedAt),
changeFrequency: 'weekly',
}) as const,
),
]
} catch {
console.error('sitemap: Error fetching academy articles')
return []
}
}
29 changes: 29 additions & 0 deletions apps/web/src/app/(cms)/blog/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { getBlogArticles } from '@sushiswap/graph-client/strapi'
import type { MetadataRoute } from 'next'

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
try {
const { articles } = await getBlogArticles({
pagination: { pageSize: 10000 },
})

return [
{
url: 'https://sushi.com/blog',
lastModified: new Date(),
changeFrequency: 'yearly',
},
...articles.map(
(article) =>
({
url: `https://sushi.com/blog/${article.slug}`,
lastModified: new Date(article.updatedAt),
changeFrequency: 'weekly',
}) as const,
),
]
} catch {
console.error('sitemap: Error fetching blog articles')
return []
}
}
14 changes: 14 additions & 0 deletions apps/web/src/app/(networks)/(non-evm)/aptos/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { MetadataRoute } from 'next'

const aptosChainPaths = ['/pool', '/explore/pools', '/pool/add', '/swap']

export default function sitemap(): MetadataRoute.Sitemap {
return aptosChainPaths.map(
(path) =>
({
url: `https://sushi.com/aptos/${path}`,
lastModified: new Date(),
changeFrequency: 'weekly',
}) as const,
)
}
14 changes: 14 additions & 0 deletions apps/web/src/app/(networks)/(non-evm)/tron/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { MetadataRoute } from 'next'

const tronChainPaths = ['/pool', '/explore/pools', '/pool/add', '/swap']

export default function sitemap(): MetadataRoute.Sitemap {
return tronChainPaths.map(
(path) =>
({
url: `https://sushi.com/tron/${path}`,
lastModified: new Date(),
changeFrequency: 'weekly',
}) as const,
)
}
15 changes: 5 additions & 10 deletions apps/web/src/app/legal/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,30 @@ import { Container, Separator } from '@sushiswap/ui'
import { unstable_cache } from 'next/cache'
import React from 'react'
import { getGhostBody } from 'src/app/(cms)/lib/ghost/ghost'
import { legalPages } from '../_config'

export const revalidate = 86400

export const dynamicParams = false

const pages = {
['privacy-policy']: { title: 'Privacy Policy' },
['terms-of-service']: { title: 'Terms of Service' },
['cookie-policy']: { title: 'Cookie Policy' },
}

export async function generateStaticParams() {
return Object.keys(pages).map((slug) => ({ slug: slug }))
return Object.keys(legalPages).map((slug) => ({ slug: slug }))
}

type Props = {
params: { slug: keyof typeof pages }
params: { slug: keyof typeof legalPages }
}

export async function generateMetadata({ params }: Props) {
const page = pages[params.slug]
const page = legalPages[params.slug]

return {
title: page.title,
}
}

export default async function Page({ params }: Props) {
const page = pages[params.slug]
const page = legalPages[params.slug]

const {
title,
Expand Down
5 changes: 5 additions & 0 deletions apps/web/src/app/legal/_config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const legalPages = {
['privacy-policy']: { title: 'Privacy Policy' },
['terms-of-service']: { title: 'Terms of Service' },
['cookie-policy']: { title: 'Cookie Policy' },
}
13 changes: 13 additions & 0 deletions apps/web/src/app/legal/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { MetadataRoute } from 'next'
import { legalPages } from './_config'

export default function sitemap(): MetadataRoute.Sitemap {
return Object.keys(legalPages).map(
(page) =>
({
url: `https://sushi.com/legal/${page}`,
lastModified: new Date(),
changeFrequency: 'weekly',
}) as const,
)
}
11 changes: 11 additions & 0 deletions apps/web/src/app/robots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MetadataRoute } from 'next'

export default function robots(): MetadataRoute.Robots {
return {
rules: {
userAgent: '*',
allow: ['/'],
},
sitemap: 'https://sushi.com/sitemap-index.xml',
}
}
25 changes: 25 additions & 0 deletions apps/web/src/app/sitemap-index.xml/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { CHAIN_IDS } from 'src/config'
import { getNetworkKey } from 'src/lib/network'

const networkKeys = [...CHAIN_IDS.map(getNetworkKey), 'aptos', 'tron']

const sitemapFiles = [
'/academy/sitemap.xml',
'/blog/sitemap.xml',
...networkKeys.map((key) => `/sitemap.xml/${key}`),
'/legal/sitemap.xml',
]

const generateSitemapLink = (url: string) =>
`<sitemap><loc>https://sushi.com${url}</loc></sitemap>`

export async function GET() {
const sitemapIndexXML = `<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${sitemapFiles.map((file) => generateSitemapLink(file)).join('')}
</sitemapindex>`

return new Response(sitemapIndexXML, {
headers: { 'Content-Type': 'text/xml' },
})
}
36 changes: 36 additions & 0 deletions apps/web/src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { MetadataRoute } from 'next'
import { CHAIN_IDS } from 'src/config'
import { getNetworkKey } from 'src/lib/network'

const evmChainPaths = [
'/migrate',
'/pool',
'/rewards',
'/cross-chain-swap',
'/dca',
'/limit',
'/swap',
'/explore/pools',
'/explore/smart-pools',
'/pool/incentivize',
'/pool/v2/add',
'/pool/v3/add',
'/pool/v3/fees',
]

export async function generateSitemaps() {
return CHAIN_IDS.map((chainId) => ({
id: getNetworkKey(chainId),
}))
}

export default function sitemap({ id }: { id: string }): MetadataRoute.Sitemap {
return evmChainPaths.map(
(path) =>
({
url: `https://sushi.com/${id}${path}`,
lastModified: new Date(),
changeFrequency: 'weekly',
}) as const,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ export async function getAcademyArticles(
id: topic.id,
name: topic.attributes.name,
})),
difficulty: {
id: article.attributes.difficulty!.data!.id,
name: article.attributes.difficulty!.data!.attributes.name,
label: article.attributes.difficulty!.data!.attributes.label,
slug: article.attributes.difficulty!.data!.attributes.slug,
},
difficulty: article.attributes.difficulty.data
? {
id: article.attributes.difficulty.data.id,
name: article.attributes.difficulty.data.attributes.name,
label: article.attributes.difficulty.data.attributes.label,
slug: article.attributes.difficulty.data.attributes.slug,
}
: null,
cover: transformImage(article.attributes.cover.data!),
authors: article.attributes.authors!.data.map((author) => ({
name: author.attributes.name,
Expand Down
Loading