- Published on
博客迁移
- Authors
- Name
- Foolgry
- @foolgryw
迁移了博客,从自己 node 写的静态博客,迁移到 nextjs 模版,部署在 vercel 上
使用的是这个模版 https://github.com/timlrx/tailwind-nextjs-starter-blog
自己写的比较简陋,样式也不太好看,所以进行了迁移。
迁移过程还是比较简单的,按照链接中的步骤部署就行了,唯一比较麻烦的是以前的 url 已经被 google 收录了,新的链接和之前不一样
所以需要做一个重定向
加了一个 middleware.ts
大概逻辑如下
//middleware.ts
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function middleware(request: NextRequest) {
// 注意这里是旧的 url 的集合,需要 urlencode
const urls = [
'/%E9%97%AE%E9%A2%98%E8%BD%AC%E5%8C%96',
]
const pathname = request.nextUrl.pathname
if (urls.includes(pathname)) {
return NextResponse.redirect(new URL(`/blog/${pathname}`, request.url))
}
return NextResponse.next()
}