Commit 9d439e7f authored by eddie's avatar eddie Committed by GitHub

feat: organize sitemaps (#7475)

parent 6b608553
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>https://app.uniswap.org/</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://app.uniswap.org/tokens</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://app.uniswap.org/send</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
<url>
<loc>https://app.uniswap.org/swap</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.9</priority>
</url>
<url>
<loc>https://app.uniswap.org/pool/v2/find</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
<url>
<loc>https://app.uniswap.org/pool/v2</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
<url>
<loc>https://app.uniswap.org/pool</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
<url>
<loc>https://app.uniswap.org/pools/v2/find</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
<url>
<loc>https://app.uniswap.org/pools/v2</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
<url>
<loc>https://app.uniswap.org/pools</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
</url>
<url>
<loc>https://app.uniswap.org/add/v2</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
<url>
<loc>https://app.uniswap.org/add</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
<url>
<loc>https://app.uniswap.org/increase</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
<url>
<loc>https://app.uniswap.org/migrate/v2</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
<url>
<loc>https://app.uniswap.org/nfts</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
<url>
<loc>https://app.uniswap.org/nfts/profile</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
<url>
<loc>https://app.uniswap.org/create-proposal</loc>
<lastmod>2023-10-11T19:57:27.976Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
</urlset>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -29,8 +29,8 @@ const nftTopCollectionsQuery = `
}
`
fs.readFile('./public/sitemap.xml', 'utf8', async (err, data) => {
const sitemapURLs = {}
fs.readFile('./public/tokens-sitemap.xml', 'utf8', async (err, data) => {
const tokenURLs = {}
try {
const sitemap = await parseStringPromise(data)
if (sitemap.urlset.url) {
......@@ -39,7 +39,7 @@ fs.readFile('./public/sitemap.xml', 'utf8', async (err, data) => {
if (lastMod < Date.now() - weekMs) {
url.lastmod = nowISO
}
sitemapURLs[url.loc] = true
tokenURLs[url.loc] = true
})
}
......@@ -57,7 +57,7 @@ fs.readFile('./public/sitemap.xml', 'utf8', async (err, data) => {
tokenAddresses.forEach((address) => {
const tokenURL = `https://app.uniswap.org/tokens/${chainName.toLowerCase()}/${address}`
if (!(tokenURL in sitemapURLs)) {
if (!(tokenURL in tokenURLs)) {
sitemap.urlset.url.push({
loc: [tokenURL],
lastmod: [nowISO],
......@@ -67,6 +67,39 @@ fs.readFile('./public/sitemap.xml', 'utf8', async (err, data) => {
})
}
const builder = new Builder()
const xml = builder.buildObject(sitemap)
const path = './public/tokens-sitemap.xml'
fs.writeFile(path, xml, (error) => {
if (error) throw error
const stats = fs.statSync(path)
const fileSizeBytes = stats.size
const fileSizeMegabytes = fileSizeBytes / (1024 * 1024)
if (fileSizeMegabytes > 50) {
throw new Error('Generated tokens-sitemap.xml file size exceeds 50MB')
}
console.log('Tokens sitemap updated')
})
} catch (e) {
console.error(e)
}
})
fs.readFile('./public/nfts-sitemap.xml', 'utf8', async (err, data) => {
const collectionURLs = {}
try {
const sitemap = await parseStringPromise(data)
if (sitemap.urlset.url) {
sitemap.urlset.url.forEach((url) => {
const lastMod = new Date(url.lastmod).getTime()
if (lastMod < Date.now() - weekMs) {
url.lastmod = nowISO
}
collectionURLs[url.loc] = true
})
}
const nftResponse = await fetch('https://api.uniswap.org/v1/graphql', {
method: 'POST',
headers: {
......@@ -79,7 +112,7 @@ fs.readFile('./public/sitemap.xml', 'utf8', async (err, data) => {
const collectionAddresses = nftJSON.data.topCollections.edges.map((edge) => edge.node.nftContracts[0].address)
collectionAddresses.forEach((address) => {
const collectionURL = `https://app.uniswap.org/nfts/collection/${address}`
if (!(collectionURL in sitemapURLs)) {
if (!(collectionURL in collectionURLs)) {
sitemap.urlset.url.push({
loc: [collectionURL],
lastmod: [nowISO],
......@@ -90,7 +123,7 @@ fs.readFile('./public/sitemap.xml', 'utf8', async (err, data) => {
const builder = new Builder()
const xml = builder.buildObject(sitemap)
const path = './public/sitemap.xml'
const path = './public/nfts-sitemap.xml'
fs.writeFile(path, xml, (error) => {
if (error) throw error
const stats = fs.statSync(path)
......@@ -98,9 +131,9 @@ fs.readFile('./public/sitemap.xml', 'utf8', async (err, data) => {
const fileSizeMegabytes = fileSizeBytes / (1024 * 1024)
if (fileSizeMegabytes > 50) {
throw new Error('Generated sitemap file size exceeds 50MB')
throw new Error('Generated nfts-sitemap.xml file size exceeds 50MB')
}
console.log('Sitemap updated')
console.log('NFT collections sitemap updated')
})
} catch (e) {
console.error(e)
......
......@@ -6,7 +6,7 @@ import { routes } from './RouteDefinitions'
describe('Routes', () => {
it('sitemap URLs should exist as Router paths', async () => {
const pathNames: string[] = routes.map((routeDef) => routeDef.path)
const contents = fs.readFileSync('./public/sitemap.xml', 'utf8')
const contents = fs.readFileSync('./public/app-sitemap.xml', 'utf8')
const sitemap = await parseStringPromise(contents)
const sitemapPaths: string[] = sitemap.urlset.url.map((url: any) => new URL(url.loc).pathname)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment