From 33c59dac5a83a8761f2bf8291e6e59785435160f Mon Sep 17 00:00:00 2001 From: frank Date: Sat, 8 Jun 2024 20:47:42 +0800 Subject: [PATCH] redirect --- app/blog/[month]/[slug]/page.js | 6 +++--- next.config.mjs | 19 +++++++++++++++++++ rehypePlugins/rehype-image-src-modifier.mjs | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/blog/[month]/[slug]/page.js b/app/blog/[month]/[slug]/page.js index 9389a0cf..e6ca66f1 100644 --- a/app/blog/[month]/[slug]/page.js +++ b/app/blog/[month]/[slug]/page.js @@ -22,9 +22,9 @@ export default async function Post({ params }) { let { month, slug } = params; slug = querystring.unescape(slug); - if (slug.endsWith(".md") || slug.endsWith(".mdx") || slug.endsWith(".html")) { - slug = slug.replace(/\.(md|mdx|html)$/, ''); - } + // if (slug.endsWith(".md") || slug.endsWith(".mdx") || slug.endsWith(".html")) { + // slug = slug.replace(/\.(md|mdx|html)$/, ''); + // } var mdxPath = path.join(process.cwd(), month, `${slug}.mdx`); var mdPath = path.join(process.cwd(), month, `${slug}.md`); diff --git a/next.config.mjs b/next.config.mjs index 8b01ad1f..69e575b3 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,5 +1,24 @@ /** @type {import('next').NextConfig} */ const nextConfig = { + redirects: () => { + return [ + { + source: '/blog/:month/:slug.html', + destination: '/blog/:month/:slug', + permanent: true, + }, + { + source: '/blog/:month/:slug.md', + destination: '/blog/:month/:slug', + permanent: true, + }, + { + source: '/blog/:month/:slug.mdx', + destination: '/blog/:month/:slug', + permanent: true, + }, + ] + } } export default nextConfig \ No newline at end of file diff --git a/rehypePlugins/rehype-image-src-modifier.mjs b/rehypePlugins/rehype-image-src-modifier.mjs index 186244e3..c0a6612f 100644 --- a/rehypePlugins/rehype-image-src-modifier.mjs +++ b/rehypePlugins/rehype-image-src-modifier.mjs @@ -41,7 +41,7 @@ function rehypeImageSrcModifier() { } // 如果本地启动无法翻墙,请注释掉下面imgur这段代码 - else if (src.startsWith('https://i.imgur.com/')) { + else if (process.env.NODE_ENV ==='production' && src.startsWith('https://i.imgur.com/')) { let picName = src.replace('https://i.imgur.com/', ''); fetch(src, {agent: undefined, headers :{ "user-agent": "curl/7.84.0",