manifold/web/pages/server-sitemap.xml.tsx

25 lines
874 B
TypeScript
Raw Normal View History

2022-03-24 16:52:13 +00:00
import { GetServerSideProps } from 'next'
import { getServerSideSitemap, ISitemapField } from 'next-sitemap'
2022-08-22 16:52:05 +00:00
import { listAllContracts } from 'web/lib/firebase/contracts'
2022-03-24 16:52:13 +00:00
export const getServerSideProps: GetServerSideProps = async (ctx) => {
2022-08-22 16:52:05 +00:00
const contracts = await listAllContracts(1000, undefined)
2022-03-24 16:52:13 +00:00
2022-08-22 16:52:05 +00:00
const score = (popularity: number) => Math.tanh(Math.log10(popularity + 1))
const fields = contracts
.sort((x) => x.popularityScore ?? 0)
.map((market) => ({
loc: `https://manifold.markets/${market.creatorUsername}/${market.slug}`,
changefreq: market.volume24Hours > 10 ? 'hourly' : 'daily',
priority: score(market.popularityScore ?? 0),
lastmod: market.lastUpdatedTime,
})) as ISitemapField[]
return await getServerSideSitemap(ctx, fields)
2022-03-24 16:52:13 +00:00
}
// Default export to prevent next.js errors
export default function Sitemap() {}