2022-05-22 08:36:05 +00:00
|
|
|
import { sortBy } from 'lodash'
|
2022-03-24 16:52:13 +00:00
|
|
|
import { GetServerSideProps } from 'next'
|
2022-04-27 17:40:02 +00:00
|
|
|
import { getServerSideSitemap, ISitemapField } from 'next-sitemap'
|
|
|
|
|
2022-05-09 13:04:36 +00:00
|
|
|
import { DOMAIN } from 'common/envs/constants'
|
2022-04-27 17:40:02 +00:00
|
|
|
import { LiteMarket } from './api/v0/_types'
|
2022-03-24 16:52:13 +00:00
|
|
|
|
|
|
|
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
2022-04-27 17:40:02 +00:00
|
|
|
// Fetching data from https://manifold.markets/api
|
2022-03-24 16:52:13 +00:00
|
|
|
const response = await fetch(`https://${DOMAIN}/api/v0/markets`)
|
|
|
|
|
2022-04-27 17:40:02 +00:00
|
|
|
const liteMarkets = (await response.json()) as LiteMarket[]
|
2022-05-22 08:36:05 +00:00
|
|
|
const sortedMarkets = sortBy(liteMarkets, (m) => -m.volume24Hours)
|
2022-04-27 17:40:02 +00:00
|
|
|
|
|
|
|
const fields = sortedMarkets.map((market) => ({
|
2022-03-24 16:52:13 +00:00
|
|
|
// See https://www.sitemaps.org/protocol.html
|
2022-04-27 17:40:02 +00:00
|
|
|
loc: market.url,
|
2022-04-27 17:47:51 +00:00
|
|
|
changefreq: market.volume24Hours > 10 ? 'hourly' : 'daily',
|
2022-04-27 17:40:02 +00:00
|
|
|
priority: market.volume24Hours + market.volume7Days > 100 ? 0.7 : 0.1,
|
2022-03-24 16:52:13 +00:00
|
|
|
// TODO: Add `lastmod` aka last modified time
|
2022-04-27 17:40:02 +00:00
|
|
|
})) 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() {}
|