Setup doc redirects for old routes (#1501)

This commit is contained in:
Justin Starry 2020-08-18 10:46:46 +08:00 committed by GitHub
parent 0220506b74
commit e6406190c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 23 deletions

View File

@ -1,11 +1,41 @@
{
"hosting": {
"site": "yew-rs",
"public": "website/build/yew",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"redirects": [ {
"source": "/",
"destination": "/docs/en/intro/",
"type": 301
}, {
"source": "/docs",
"destination": "/docs/en/intro/",
"type": 301
}, {
"regex": "/(docs/)?(?P<lang>en|ja|zh-TW|zh-CN)",
"destination": "/docs/:lang/intro/",
"type": 301
}, {
"source": "/docs/v/zh_cn",
"destination": "/docs/zh-CN/intro/",
"type": 301
}, {
"source": "/docs/v/zh_tw",
"destination": "/docs/zh-TW/intro/",
"type": 301
}, {
"regex": "/docs/v/zh_cn/(.*)",
"destination": "/docs/zh-CN/:1",
"type": 301
}, {
"regex": "/docs/v/zh_tw/(.*)",
"destination": "/docs/zh-TW/:1",
"type": 301
} ],
"rewrites": [
{
"source": "**",

View File

@ -7,29 +7,7 @@
content="0; url=/docs/en/intro"
/>
<script type="text/javascript">
// Redirect old translated paths
if (window.location.pathname.includes('/v/')) {
var pathname = window.location.pathname.replace('/v/zh_cn', '/zh-CN').replace('/v/zh_tw', '/zh-TW');
if (pathname === window.location.pathname) {
window.location.href = '/docs/en/intro';
} else {
if (pathname.endsWith('/')) {
pathname = pathname.substring(0, pathname.length - 1);
}
if (pathname.endsWith('zh-CN') || pathname.endsWith('zh-TW')) {
pathname += '/intro';
}
window.location.href = pathname;
}
// Redirect broken links
} else if (window.location.pathname.includes('/zh-TW')) {
window.location.href = '/docs/zh-TW/intro';
// Redirect broken links
} else if (window.location.pathname.includes('/zh-CN')) {
window.location.href = '/docs/zh-CN/intro';
} else {
window.location.href = '/docs/en/intro';
}
</script>
<title>Yew Docs</title>
</head>