From e1b5f4d3a6dcaa6f2cc7ae6313ef9503416340c3 Mon Sep 17 00:00:00 2001 From: zhuxiujuan28 <562873187@qq.com> Date: Wed, 30 Aug 2023 15:57:10 +0800 Subject: [PATCH] fix path error Signed-off-by: zhuxiujuan28 <562873187@qq.com> --- .netlify/edge-functions/manifest.json | 9 +++++-- .netlify/edge-functions/redirect.js | 24 +++++++++++++++++++ .../v3.4/introduction/what's-new-in-3.4.md | 2 +- netlify.toml | 24 ------------------- 4 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 .netlify/edge-functions/redirect.js diff --git a/.netlify/edge-functions/manifest.json b/.netlify/edge-functions/manifest.json index d667f6a40..4a6df4880 100644 --- a/.netlify/edge-functions/manifest.json +++ b/.netlify/edge-functions/manifest.json @@ -3,8 +3,13 @@ { "pattern": "^/[^l][^o][^g].*$", "function": "go-get", - "name": "go module" + "name": "go-get for go module" + }, + { + "pattern": "^(/zh/docs/|/docs/).*$", + "function": "redirect", + "name": "redirect" } ], "version": 1 -} +} \ No newline at end of file diff --git a/.netlify/edge-functions/redirect.js b/.netlify/edge-functions/redirect.js new file mode 100644 index 000000000..60eb5dd3a --- /dev/null +++ b/.netlify/edge-functions/redirect.js @@ -0,0 +1,24 @@ +export default async (req, context) => { + const { url } = req; + const parsedUrl = new URL(url); + const path = parsedUrl.pathname; + const regex = /^(\/zh\/docs|\/docs)\/v[0-9]+\.[0-9]+.*$/; + + if (regex.test(path)) { + return; + } else { + let hasContentAfterDocs = false; + const newPath = path.replace(/(\/docs\/)(.*)$/, (match, p1, p2) => { + if (p2.trim() === "") { + return `${p1}v3.4/`; + } else { + hasContentAfterDocs = true; + return `${p1}v3.4/${p2}`; + } + }); + + const redirectStatusCode = hasContentAfterDocs ? 301 : 302; + const redirectUrl = new URL(newPath, req.url); + return Response.redirect(redirectUrl, redirectStatusCode); + } +}; diff --git a/content/zh/docs/v3.4/introduction/what's-new-in-3.4.md b/content/zh/docs/v3.4/introduction/what's-new-in-3.4.md index f5468f494..36ddd3658 100644 --- a/content/zh/docs/v3.4/introduction/what's-new-in-3.4.md +++ b/content/zh/docs/v3.4/introduction/what's-new-in-3.4.md @@ -8,7 +8,7 @@ weight: 1400 2023 年 07 月 26 日,KubeSphere 3.4.0 已正式上线。该版本带来了值得大家关注的新功能以及增强:扩大对 Kubernetes 的支持范围,最新稳定性支持 1.26;重构告警策略架构,解耦为告警规则与规则组;提升集群别名展示权重,减少原集群名称不可修改导致的管理问题;升级 KubeEdge 组件到 v1.13 等。同时,还进行了多项修复、优化和增强,更进一步完善交互设计,并全面提升了用户体验。 -关于 3.4 新特性的详细解读,可参考博客 [KubeSphere 3.4.0 发布:支持 K8s v1.26](/../../news/kubesphere-3.4.0-ga-announcement/)。 +关于 3.4 新特性的详细解读,可参考博客 [KubeSphere 3.4.0 发布:支持 K8s v1.26](/../../../news/kubesphere-3.4.0-ga-announcement/)。 关于 3.4 的新功能及增强、Bug 修复、重要的技术调整,以及废弃或移除的功能,请参见 [3.4.0 版本说明](../../../v3.4/release/release-v340/)。 \ No newline at end of file diff --git a/netlify.toml b/netlify.toml index bffccd5ac..adad1a166 100644 --- a/netlify.toml +++ b/netlify.toml @@ -4,30 +4,6 @@ [context.deploy-preview.environment] HUGO_VERSION = "0.117.0" -[[redirects]] - from = "/docs" - to = "/docs/v3.3" - status = 302 - force = true - -[[redirects]] - from = "/zh/docs" - to = "/zh/docs/v3.3" - status = 302 - force = true - -[[redirects]] - from = "/docs/*" - to = "/docs/v3.4/:splat" - status = 301 - force = true - -[[redirects]] - from = "/zh/docs/*" - to = "/zh/docs/v3.4/:splat" - status = 301 - force = true - [[redirects]] from = "/log/*" to = "https://log.kubesphere.io/:splat"