Skip to content

Commit

Permalink
redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
sunwu51 committed Jun 8, 2024
1 parent 7617c6a commit 33c59da
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/blog/[month]/[slug]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
19 changes: 19 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion rehypePlugins/rehype-image-src-modifier.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 33c59da

Please sign in to comment.