Skip to content

Commit

Permalink
Add redirects to vercel.json (#1722)
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Oct 7, 2021
1 parent fcdd6de commit dcf56e3
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 3 deletions.
164 changes: 163 additions & 1 deletion 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"
}
]
}
24 changes: 22 additions & 2 deletions website/prep.js
Expand Up @@ -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
})
Expand Down Expand Up @@ -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) {
Expand Down

1 comment on commit dcf56e3

@vercel
Copy link

@vercel vercel bot commented on dcf56e3 Oct 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

Please sign in to comment.