Nuxt/docs/scripts/map-redirects.js
Yaël Guilloux dc47c64f14
docs: use nuxt 3 and website theme (#5479)
Co-authored-by: Daniel Roe <daniel@roe.dev>
Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>
Co-authored-by: Pooya Parsa <pooya@pi0.io>
Co-authored-by: pooya parsa <pyapar@gmail.com>
Co-authored-by: Clément Ollivier <clement.o2p@gmail.com>
2022-10-06 11:15:30 +02:00

31 lines
884 B
JavaScript

const { readFile, writeFile } = require('node:fs/promises')
const netlifyToVercel = (redirects) => {
return JSON.stringify(
{
redirects: redirects.split('\n')
.filter(s => s !== '' && !s.startsWith('#'))
.map((line) => {
const [source, destination] = line.split(' /')
return {
source: source.replace('*', ':path').trim(),
destination: `/${destination.replace(' 302!', '').replace(':splat', ':path').trim()}`,
permanent: false
}
})
}, null, 2)
}
async function transformRedirects () {
try {
const redirectsFile = await readFile('../public/_redirects', 'utf-8')
const vercelConfig = netlifyToVercel(redirectsFile)
console.log(vercelConfig)
await writeFile('../public/vercel.json', vercelConfig)
} catch (e) {
console.error(e)
}
}
transformRedirects()