diff --git a/vercel.json b/vercel.json index 1ac7ad18..82cb0891 100644 --- a/vercel.json +++ b/vercel.json @@ -1,4 +1,166 @@ { "public": true, - "trailingSlash": true + "trailingSlash": true, + "redirects": [ + { + "source": "/about/", + "destination": "/community/about/" + }, + { + "source": "/advanced/", + "destination": "/guides/" + }, + { + "source": "/advanced/api/", + "destination": "/packages/mdx/#api" + }, + { + "source": "/advanced/ast/", + "destination": "/packages/remark-mdx/#syntax-tree" + }, + { + "source": "/advanced/components/", + "destination": "/using-mdx/" + }, + { + "source": "/advanced/contributing/", + "destination": "/community/contribute/" + }, + { + "source": "/advanced/custom-loader/", + "destination": "/guides/frontmatter/" + }, + { + "source": "/advanced/retext-plugins/", + "destination": "/extending-mdx/#using-plugins" + }, + { + "source": "/advanced/plugins/", + "destination": "/extending-mdx/" + }, + { + "source": "/advanced/runtime/", + "destination": "/packages/mdx/#evaluatefile-options" + }, + { + "source": "/advanced/specification/", + "destination": "/packages/remark-mdx/#syntax-tree" + }, + { + "source": "/advanced/sync-api/", + "destination": "/packages/mdx/#api" + }, + { + "source": "/advanced/transform-content/", + "destination": "/packages/remark-mdx/" + }, + { + "source": "/advanced/typescript/", + "destination": "/getting-started/#types" + }, + { + "source": "/advanced/writing-a-plugin/", + "destination": "/guides/frontmatter/" + }, + { + "source": "/contributing/", + "destination": "/community/contribute/" + }, + { + "source": "/editor-plugins/", + "destination": "/getting-started/#editor" + }, + { + "source": "/editors/", + "destination": "/getting-started/#editor" + }, + { + "source": "/getting-started/create-react-app/", + "destination": "/getting-started/#create-react-app-cra" + }, + { + "source": "/getting-started/gatsby/", + "destination": "/getting-started/#gatsby" + }, + { + "source": "/getting-started/next/", + "destination": "/getting-started/#nextjs" + }, + { + "source": "/getting-started/parcel/", + "destination": "/getting-started/#parcel" + }, + { + "source": "/getting-started/react-static/", + "destination": "/getting-started/#react-static" + }, + { + "source": "/getting-started/table-of-components/", + "destination": "/table-of-components/" + }, + { + "source": "/getting-started/typescript/", + "destination": "/getting-started/#types" + }, + { + "source": "/getting-started/webpack/", + "destination": "/getting-started/#webpack" + }, + { + "source": "/guides/custom-loader/", + "destination": "/guides/frontmatter/" + }, + { + "source": "/guides/live-code/", + "destination": "/guides/syntax-highlighting/#syntax-highlighting-with-the-meta-field" + }, + { + "source": "/guides/markdown-in-components/", + "destination": "/mdx/" + }, + { + "source": "/guides/math-blocks/", + "destination": "/guides/math/" + }, + { + "source": "/guides/mdx-embed/", + "destination": "/guides/embed/#embeds-at-run-time" + }, + { + "source": "/guides/table-of-contents/", + "destination": "/extending-mdx/" + }, + { + "source": "/guides/terminal/", + "destination": "/getting-started/#ink" + }, + { + "source": "/guides/vue/", + "destination": "/getting-started/#vue" + }, + { + "source": "/guides/wrapper-customization/", + "destination": "/using-mdx/#layout" + }, + { + "source": "/guides/writing-a-plugin/", + "destination": "/extending-mdx/#creating-plugins" + }, + { + "source": "/plugins/", + "destination": "/extending-mdx/#using-plugins" + }, + { + "source": "/projects/", + "destination": "/community/projects/" + }, + { + "source": "/support/", + "destination": "/community/support/" + }, + { + "source": "/syntax/", + "destination": "/getting-started/#syntax" + } + ] } diff --git a/website/prep.js b/website/prep.js index f4b2982a..4b8ff7f7 100644 --- a/website/prep.js +++ b/website/prep.js @@ -12,6 +12,8 @@ import rehypeMinifyUrl from 'rehype-minify-url' import rehypeStringify from 'rehype-stringify' import {config, redirect} from '../docs/_config.js' +const own = {}.hasOwnProperty + main().catch((error) => { throw error }) @@ -57,12 +59,30 @@ async function main() { file.value = processor.stringify(tree) await fs.mkdir(file.dirname, {recursive: true}) await fs.writeFile(file.path, String(file)) - console.log(' redirect: `%s` -> `%s`', from, to) }), {concurrency: 6} ) - console.log('✔ Redirect') + console.log('✔ %d redirects', Object.keys(redirect).length) + + const vercelRedirects = [] + let redirectFrom + + for (redirectFrom in redirect) { + if (own.call(redirect, redirectFrom)) { + const source = redirectFrom.replace(/\/index.html$/, '/') + const destination = redirect[redirectFrom] + vercelRedirects.push({source, destination}) + } + } + + const vercelInfo = JSON.parse(await fs.readFile('vercel.json')) + await fs.writeFile( + 'vercel.json', + JSON.stringify({...vercelInfo, redirects: vercelRedirects}, null, 2) + '\n' + ) + + console.log('✔ `vercel.json` redirects') } function buildRedirect(to) {