Skip to content

Commit

Permalink
Merge pull request #38 from palladians/feat/add-sitemap
Browse files Browse the repository at this point in the history
feat(sitemap): add simple sitemap
  • Loading branch information
mrcnk committed Sep 13, 2023
2 parents 65dbfad + 0c54191 commit 2516b97
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
9 changes: 9 additions & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# *
User-agent: *
Allow: /

# Host
Host: https://minaverse.xyz

# Sitemaps
Sitemap: https://minaverse.xyz/sitemap.xml
75 changes: 75 additions & 0 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { MetadataRoute } from 'next'

import { fetchAccounts } from '@/data/accounts'
import { Network } from '@/data/api'
import { fetchStaking } from '@/data/staking'
import { env } from '@/env.mjs'

const APP_URL = env.NEXT_PUBLIC_APP_URL

const networks = [Network.MAINNET, Network.DEVNET, Network.BERKELEY]

const getAccountsRoutes = ({
network,
accountIds
}: {
network: Network
accountIds: string[]
}) =>
accountIds.map((id) => ({
url: `${APP_URL}/${network}/accounts/${id}`,
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 0.8
}))

const getNetworkRoutes = async (network: Network) => {
const { data: stakePools } = await fetchStaking({ search: null, network })
const { data: accounts } = await fetchAccounts({ search: null, network })
return [
{
url: `${APP_URL}/${network}/accounts`,
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 0.8
},
...getAccountsRoutes({
accountIds: accounts.map(({ public_key }) => public_key),
network
}),
{
url: `${APP_URL}/${network}/transactions`,
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 0.8
},
{
url: `${APP_URL}/${network}/staking`,
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 0.8
},
...getAccountsRoutes({
accountIds: stakePools.map(({ _id }) => _id.delegate),
network
})
]
}

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const routes = (await Promise.all(
networks.map(async (network) => await getNetworkRoutes(network))
)) as MetadataRoute.Sitemap[]

return [
{
url: APP_URL,
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 1
},
...routes.flat()
]
}

export const runtime = 'edge'

0 comments on commit 2516b97

Please sign in to comment.