uniswap-interface-uncensored/scripts/generate-sitemap.js
eddie 3ced65b8a4
feat: add sitemap for app.uniswap.org (#7408)
* feat: add sitemap for app.uniswap.org

* feat: script to update lastmod

* fix: deps and snapshots

* fix: use xml2js

* fix: improve test and sitemap
2023-10-05 12:19:58 -07:00

26 lines
690 B
JavaScript

/* eslint-env node */
const fs = require('fs')
const { parseStringPromise, Builder } = require('xml2js')
fs.readFile('./public/sitemap.xml', 'utf8', async (err, data) => {
try {
const sitemap = await parseStringPromise(data)
const lastmodDate = new Date().toISOString()
if (sitemap.urlset.url) {
sitemap.urlset.url.forEach((url) => {
url['$'].lastmod = lastmodDate
})
}
const builder = new Builder()
const xml = builder.buildObject(sitemap)
fs.writeFile('./public/sitemap.xml', xml, (error) => {
if (error) throw error
console.log('Sitemap updated')
})
} catch {
throw new Error('Error parsing sitemap.xml')
}
})