Update nextjs to 12.1

* update modify post save to db
* Update concurrent fectures
* Update exist post
This commit is contained in:
DefectingCat
2022-02-18 11:21:05 +08:00
parent 7f66c3eade
commit 1cf58e9f9b
9 changed files with 177 additions and 102 deletions

View File

@ -6,11 +6,8 @@ import remarkRehype from 'remark-rehype';
import rehypeRaw from 'rehype-raw';
import rehypeSlug from 'rehype-slug';
import rehypeReact from 'rehype-react';
import dynamic from 'next/dynamic';
import cn from 'classnames';
const Link = dynamic(() => import('components/RUA/RUALink'));
interface Props {
content: string;
}

View File

@ -13,7 +13,8 @@ module.exports = withMDX({
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
swcMinify: true,
experimental: {
// concurrentFeatures: true,
// serverComponents: true,
concurrentFeatures: true,
// runtime: 'nodejs',
outputStandalone: true,
},
});

View File

@ -20,7 +20,7 @@
"date-fns": "^2.28.0",
"gray-matter": "^4.0.3",
"highlight.js": "^11.4.0",
"next": "^12.0.9",
"next": "^12.1.0",
"react": "^18.0.0-rc.0",
"react-dom": "^18.0.0-rc.0",
"react-icons": "^4.3.1",

View File

@ -8,6 +8,7 @@ import Head from 'next/head';
import { MDXProvider } from '@mdx-js/react';
import dynamic from 'next/dynamic';
import RUAStore from 'lib/store';
import Script from 'next/script';
const H2 = dynamic(() => import('components/MDX/MDXH2'));

View File

@ -1,13 +0,0 @@
import { Html, Head, Main, NextScript } from 'next/document';
export default function Document() {
return (
<Html lang="en">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}

View File

@ -9,8 +9,6 @@ export default async function handler(
res: NextApiResponse
) {
const search = async () => {
const searchBody = req.query;
const totalNum = await prisma.posts.count();
const posts = await prisma.posts.findMany({
orderBy: {

View File

@ -1,6 +1,6 @@
---
title: 我的开发环境
date: 2021-12-03 23:14:42
date: 2022-02-18 11:42:33
tags: [Linux, Server]
categories: 实践
url: my-development-environment
@ -169,6 +169,38 @@ registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
对于 Windows 环境,则需要 `C:\Users\{username}\.cargo` 目录下的 `config` 文件,添加对应的源地址。
### Go mod
Go mod 支持 proxy 设置:
```bash
go env -w GO111MODULE=on
# 1. 七牛 CDN
go env -w GOPROXY=https://goproxy.cn,direct
# 2. 阿里云
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
# 3. 官方
go env -w GOPROXY=https://goproxy.io,direct
```
### pypi
同样清华大学的源pypi 镜像每 5 分钟同步一次。
```bash
pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
```
如果到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip
```bash
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
```
## 对于本机
目前主要是使用 WSL2 中的 Ubuntu 作为开发环境的WSL2 目前比较大的问题就是每次其 IP 地址都会变动,宿主机的地址,也就是它的网关也会一直变。

View File

@ -74,6 +74,8 @@ async function saveTagsToDB(posts) {
});
const allTags = Array.from(allTagsSet);
let newTagsNum = 0;
// Find tag in DB by name
for (const tag of allTags) {
const tagInDB = await prisma.tags.findFirst({
@ -93,13 +95,14 @@ async function saveTagsToDB(posts) {
},
});
newTagsNum++;
console.log(
`Save tag ${tagReadToDB.name} sucessfuly! id: ${tagReadToDB.id}`
);
}
}
console.log('Save tag to DB done!');
if (newTagsNum) console.log(`Save ${newTagsNum} tags to DB done!`);
}
async function saveCategoryToDB(posts) {
@ -108,6 +111,8 @@ async function saveCategoryToDB(posts) {
if (post.categories) allCategoies.push(post.categories);
});
let newCateNum = 0;
for (const category of allCategoies) {
const categoryInDB = await prisma.category.findFirst({
select: {
@ -126,13 +131,14 @@ async function saveCategoryToDB(posts) {
},
});
newCateNum++;
console.log(
`Save category ${categoryReadToDB.name} sucessfuly! id: ${categoryReadToDB.id}`
);
}
}
console.log('Save category to DB done!');
if (newCateNum) console.log(`Save ${newCateNum} categories to DB done!`);
}
async function savePostToDB(posts) {
@ -146,30 +152,35 @@ async function savePostToDB(posts) {
},
});
let newPostNum = 0;
let updatePostNum = 0;
for (const post of posts) {
const postInDB = await prisma.posts.findFirst({
select: {
file_name: true,
date: true,
id: true,
},
where: {
file_name: post.file_name,
},
});
const {
title,
date,
tags,
categories,
url,
index_img,
content,
desc,
file_name,
} = post;
// If don't exist, insert tag to DB.
if (postInDB == null) {
const {
title,
date,
tags,
categories,
url,
index_img,
content,
desc,
file_name,
} = post;
const categoryId = await prisma.category.findFirst({
select: {
id: true,
@ -206,13 +217,61 @@ async function savePostToDB(posts) {
},
});
newPostNum++;
console.log(
`Save post ${postReadToDB.title} sucessfuly! id: ${postReadToDB.id}`
`Save new post ${postReadToDB.title} sucessfully! id: ${postReadToDB.id}`
);
} else {
const postDate = new Date(post.date);
const postInDBDate = new Date(postInDB.date);
// Update exist post.
if (postDate.getTime() !== postInDBDate.getTime()) {
const categoryId = await prisma.category.findFirst({
select: {
id: true,
},
where: {
name: categories,
},
});
const postUpdateRes = await prisma.posts.update({
select: {
title: true,
},
where: {
id: postInDB.id,
},
data: {
title,
date,
url,
index_img: index_img ?? null,
content,
desc,
file_name,
tags: tags
? {
connect: await findPostTag(tags),
}
: {},
categories: {
connect: {
id: categoryId.id,
},
},
},
});
updatePostNum++;
console.log(`Update post ${postUpdateRes.title} sucessfully!`);
}
}
}
console.log('Save post to DB done!');
if (newPostNum) console.log(`Save new ${newPostNum} post(s) to DB done!`);
if (updatePostNum) console.log(`Update ${updatePostNum} post(s) to DB done!`);
}
async function findPostTag(tags) {

128
yarn.lock
View File

@ -727,10 +727,10 @@
resolved "https://registry.nlark.com/@mdx-js/util/download/@mdx-js/util-1.6.22.tgz#219dfd89ae5b97a8801f015323ffa4b62f45718b"
integrity sha1-IZ39ia5bl6iAHwFTI/+kti9FcYs=
"@next/env@12.0.9":
version "12.0.9"
resolved "https://registry.npmmirror.com/@next/env/download/@next/env-12.0.9.tgz#4c9e9eef00226145d9629a846b8cc31878e1328c"
integrity sha512-oBlkyDop0Stf7MPIzETGv5r0YT/G/weBrknoPOUTaa5qwOeGjuy6gsOVc/SBtrBkOoBmRpD+fFhQJPvmo1mS+g==
"@next/env@12.1.0":
version "12.1.0"
resolved "https://registry.npmmirror.com/@next/env/-/env-12.1.0.tgz#73713399399b34aa5a01771fb73272b55b22c314"
integrity sha512-nrIgY6t17FQ9xxwH3jj0a6EOiQ/WDHUos35Hghtr+SWN/ntHIQ7UpuvSi0vaLzZVHQWaDupKI+liO5vANcDeTQ==
"@next/eslint-plugin-next@12.0.9":
version "12.0.9"
@ -744,60 +744,60 @@
resolved "https://registry.npmmirror.com/@next/mdx/download/@next/mdx-12.0.9.tgz#9a3036e6b95371301a503dd7992ced7e10dfc712"
integrity sha512-BVAUT5VVHrmztpeYnvt1S5Afq42oxl1uz49QyUHPfXfqCgrXM+SHVGnTZ76XnuSz4TTqJZdVpHdhgB8Qjnt46A==
"@next/swc-android-arm64@12.0.9":
version "12.0.9"
resolved "https://registry.npmmirror.com/@next/swc-android-arm64/download/@next/swc-android-arm64-12.0.9.tgz#2cdbcc1814471044ea0e057b475090d25654833c"
integrity sha512-aVqgsEn5plmUH2X58sjzhHsH/6majucWTMaaBEs7hHO2+GCwCZc7zaLH4XCBMKPES9Yaja8/pYUbvZQE9DqgFw==
"@next/swc-android-arm64@12.1.0":
version "12.1.0"
resolved "https://registry.npmmirror.com/@next/swc-android-arm64/-/swc-android-arm64-12.1.0.tgz#865ba3a9afc204ff2bdeea49dd64d58705007a39"
integrity sha512-/280MLdZe0W03stA69iL+v6I+J1ascrQ6FrXBlXGCsGzrfMaGr7fskMa0T5AhQIVQD4nA/46QQWxG//DYuFBcA==
"@next/swc-darwin-arm64@12.0.9":
version "12.0.9"
resolved "https://registry.npmmirror.com/@next/swc-darwin-arm64/download/@next/swc-darwin-arm64-12.0.9.tgz#ea200929d7116de12c6f3b13ff75f9522c2153e3"
integrity sha512-uAgRKm4a2nVdyBiPPJokvmDD1saugOvxljz9ld2ih0CCg5S9vBhqaj3kPGCQBj9hSu3q+Lng2CHnQqG3ga1jzA==
"@next/swc-darwin-arm64@12.1.0":
version "12.1.0"
resolved "https://registry.npmmirror.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-12.1.0.tgz#08e8b411b8accd095009ed12efbc2f1d4d547135"
integrity sha512-R8vcXE2/iONJ1Unf5Ptqjk6LRW3bggH+8drNkkzH4FLEQkHtELhvcmJwkXcuipyQCsIakldAXhRbZmm3YN1vXg==
"@next/swc-darwin-x64@12.0.9":
version "12.0.9"
resolved "https://registry.npmmirror.com/@next/swc-darwin-x64/download/@next/swc-darwin-x64-12.0.9.tgz#32800a7a9aff4bfd2038b0bce3657ece8708a87b"
integrity sha512-fDOs2lZIyrAdU18IxMA5orBPn9qLbOdu55gXSTNZOhyRJ8ugtbUAejsK7OL0boJy0CCHPAdVRXm01Mwk8tZ9RQ==
"@next/swc-darwin-x64@12.1.0":
version "12.1.0"
resolved "https://registry.npmmirror.com/@next/swc-darwin-x64/-/swc-darwin-x64-12.1.0.tgz#fcd684497a76e8feaca88db3c394480ff0b007cd"
integrity sha512-ieAz0/J0PhmbZBB8+EA/JGdhRHBogF8BWaeqR7hwveb6SYEIJaDNQy0I+ZN8gF8hLj63bEDxJAs/cEhdnTq+ug==
"@next/swc-linux-arm-gnueabihf@12.0.9":
version "12.0.9"
resolved "https://registry.npmmirror.com/@next/swc-linux-arm-gnueabihf/download/@next/swc-linux-arm-gnueabihf-12.0.9.tgz#da012dfb69ad2abc3d4045395581b650048bdd7c"
integrity sha512-/ni0p9DBvATUML9RQ1ycQuf05uOYKdzA6iI8+eRsARjpGbFVUFbge7XPzlj9g2Q9YWgoN8CSjFGnKRlyky5uHA==
"@next/swc-linux-arm-gnueabihf@12.1.0":
version "12.1.0"
resolved "https://registry.npmmirror.com/@next/swc-linux-arm-gnueabihf/-/swc-linux-arm-gnueabihf-12.1.0.tgz#9ec6380a27938a5799aaa6035c205b3c478468a7"
integrity sha512-njUd9hpl6o6A5d08dC0cKAgXKCzm5fFtgGe6i0eko8IAdtAPbtHxtpre3VeSxdZvuGFh+hb0REySQP9T1ttkog==
"@next/swc-linux-arm64-gnu@12.0.9":
version "12.0.9"
resolved "https://registry.npmmirror.com/@next/swc-linux-arm64-gnu/download/@next/swc-linux-arm64-gnu-12.0.9.tgz#fe704c0a1cb048ef19d4a24b2c990574c96c933b"
integrity sha512-AphxilJDf95rUxJDHgM9Ww1DaYXZWqTvoKwXeej/0SgSvICcRZrLaFDrkojdXz0Rxr4igX2OdYR1S4/Hj1jWOQ==
"@next/swc-linux-arm64-gnu@12.1.0":
version "12.1.0"
resolved "https://registry.npmmirror.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-12.1.0.tgz#7f4196dff1049cea479607c75b81033ae2dbd093"
integrity sha512-OqangJLkRxVxMhDtcb7Qn1xjzFA3s50EIxY7mljbSCLybU+sByPaWAHY4px97ieOlr2y4S0xdPKkQ3BCAwyo6Q==
"@next/swc-linux-arm64-musl@12.0.9":
version "12.0.9"
resolved "https://registry.npmmirror.com/@next/swc-linux-arm64-musl/download/@next/swc-linux-arm64-musl-12.0.9.tgz#b2bb68940903cd64f7875979ed9907e946dc4f3e"
integrity sha512-K5jbvNNzF3mRjWmPdxP5Bg87i7FHivfBj/L0KJlxpkLSC8sffBJDmB6jtMnI7wiPj9J6vmLkbGtSosln78xAlQ==
"@next/swc-linux-arm64-musl@12.1.0":
version "12.1.0"
resolved "https://registry.npmmirror.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-12.1.0.tgz#b445f767569cdc2dddee785ca495e1a88c025566"
integrity sha512-hB8cLSt4GdmOpcwRe2UzI5UWn6HHO/vLkr5OTuNvCJ5xGDwpPXelVkYW/0+C3g5axbDW2Tym4S+MQCkkH9QfWA==
"@next/swc-linux-x64-gnu@12.0.9":
version "12.0.9"
resolved "https://registry.npmmirror.com/@next/swc-linux-x64-gnu/download/@next/swc-linux-x64-gnu-12.0.9.tgz#b700ba095551d4f6e830b92d4593a3b6e73bba82"
integrity sha512-bJZ9bkMkQzsY+UyWezEZ77GWQ4TzwKeXdayX3U3+aEkL8k5C6eKBXlidWdrhu0teLmaUXIyWerWrLnJzwGXdfw==
"@next/swc-linux-x64-gnu@12.1.0":
version "12.1.0"
resolved "https://registry.npmmirror.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-12.1.0.tgz#67610e9be4fbc987de7535f1bcb17e45fe12f90e"
integrity sha512-OKO4R/digvrVuweSw/uBM4nSdyzsBV5EwkUeeG4KVpkIZEe64ZwRpnFB65bC6hGwxIBnTv5NMSnJ+0K/WmG78A==
"@next/swc-linux-x64-musl@12.0.9":
version "12.0.9"
resolved "https://registry.npmmirror.com/@next/swc-linux-x64-musl/download/@next/swc-linux-x64-musl-12.0.9.tgz#678460266f544b52f1190ef0c3494e436608591e"
integrity sha512-SR9p0R+v1T32DTXPVAXZw31pmJAkSDotC6Afy+mfC0xrEL3pp95R8sGXYAAUCEPkQp0MEeUOVy2LrToe92X7hQ==
"@next/swc-linux-x64-musl@12.1.0":
version "12.1.0"
resolved "https://registry.npmmirror.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-12.1.0.tgz#ea19a23db08a9f2e34ac30401f774cf7d1669d31"
integrity sha512-JohhgAHZvOD3rQY7tlp7NlmvtvYHBYgY0x5ZCecUT6eCCcl9lv6iV3nfu82ErkxNk1H893fqH0FUpznZ/H3pSw==
"@next/swc-win32-arm64-msvc@12.0.9":
version "12.0.9"
resolved "https://registry.npmmirror.com/@next/swc-win32-arm64-msvc/download/@next/swc-win32-arm64-msvc-12.0.9.tgz#f70e5bd0821ca168aeef117e51ab870265ceeeb1"
integrity sha512-mzQ1A8vfHhJrvEy5KJZGZWEByXthyKfWofvFaf+oo/5nJl/0Bz1ODP2ajSmbLG++77Eo2AROgbm9pkW1ucvG2A==
"@next/swc-win32-arm64-msvc@12.1.0":
version "12.1.0"
resolved "https://registry.npmmirror.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-12.1.0.tgz#eadf054fc412085659b98e145435bbba200b5283"
integrity sha512-T/3gIE6QEfKIJ4dmJk75v9hhNiYZhQYAoYm4iVo1TgcsuaKLFa+zMPh4056AHiG6n9tn2UQ1CFE8EoybEsqsSw==
"@next/swc-win32-ia32-msvc@12.0.9":
version "12.0.9"
resolved "https://registry.npmmirror.com/@next/swc-win32-ia32-msvc/download/@next/swc-win32-ia32-msvc-12.0.9.tgz#0b853793754642cde9f9099087d4a86b6a99a24d"
integrity sha512-MpD2vj1zjo1u3J3wiz3pEKse19Etz+P0GL6XfQkB/9a84vJQ1JWMaWBjmIdivzZv718Il2pRSSx8hymwPfguYQ==
"@next/swc-win32-ia32-msvc@12.1.0":
version "12.1.0"
resolved "https://registry.npmmirror.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-12.1.0.tgz#68faeae10c89f698bf9d28759172b74c9c21bda1"
integrity sha512-iwnKgHJdqhIW19H9PRPM9j55V6RdcOo6rX+5imx832BCWzkDbyomWnlzBfr6ByUYfhohb8QuH4hSGEikpPqI0Q==
"@next/swc-win32-x64-msvc@12.0.9":
version "12.0.9"
resolved "https://registry.npmmirror.com/@next/swc-win32-x64-msvc/download/@next/swc-win32-x64-msvc-12.0.9.tgz#f7d3b59000082cf65c84fdc61930b708aa5446e5"
integrity sha512-1c/sxp/4Qz4F6rCxiYqAnrmghCOFt5hHZ9Kd+rXFW5Mqev4C4XDOUMHdBH55HgnJZqngYhOE0r/XNkCtsIojig==
"@next/swc-win32-x64-msvc@12.1.0":
version "12.1.0"
resolved "https://registry.npmmirror.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-12.1.0.tgz#d27e7e76c87a460a4da99c5bfdb1618dcd6cd064"
integrity sha512-aBvcbMwuanDH4EMrL2TthNJy+4nP59Bimn8egqv6GHMVj0a44cU6Au4PjOhLNqEh9l+IpRGBqMTzec94UdC5xg==
"@nodelib/fs.scandir@2.1.5":
version "2.1.5"
@ -4660,28 +4660,28 @@ natural-compare@^1.4.0:
resolved "https://registry.nlark.com/natural-compare/download/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
next@^12.0.9:
version "12.0.9"
resolved "https://registry.npmmirror.com/next/download/next-12.0.9.tgz#4eb3006b63bb866f5c2918ca0003e98f4259e063"
integrity sha512-omfYqoR/DvbdOIJ6SS1unKJ4mGIxUPs0RPa7wr/Mft22OCKgJhuG+aI9KFYi5ZJBwoFQk1vqaMKpWz5qr+dN0Q==
next@^12.1.0:
version "12.1.0"
resolved "https://registry.npmmirror.com/next/-/next-12.1.0.tgz#c33d753b644be92fc58e06e5a214f143da61dd5d"
integrity sha512-s885kWvnIlxsUFHq9UGyIyLiuD0G3BUC/xrH0CEnH5lHEWkwQcHOORgbDF0hbrW9vr/7am4ETfX4A7M6DjrE7Q==
dependencies:
"@next/env" "12.0.9"
"@next/env" "12.1.0"
caniuse-lite "^1.0.30001283"
postcss "8.4.5"
styled-jsx "5.0.0"
use-subscription "1.5.1"
optionalDependencies:
"@next/swc-android-arm64" "12.0.9"
"@next/swc-darwin-arm64" "12.0.9"
"@next/swc-darwin-x64" "12.0.9"
"@next/swc-linux-arm-gnueabihf" "12.0.9"
"@next/swc-linux-arm64-gnu" "12.0.9"
"@next/swc-linux-arm64-musl" "12.0.9"
"@next/swc-linux-x64-gnu" "12.0.9"
"@next/swc-linux-x64-musl" "12.0.9"
"@next/swc-win32-arm64-msvc" "12.0.9"
"@next/swc-win32-ia32-msvc" "12.0.9"
"@next/swc-win32-x64-msvc" "12.0.9"
"@next/swc-android-arm64" "12.1.0"
"@next/swc-darwin-arm64" "12.1.0"
"@next/swc-darwin-x64" "12.1.0"
"@next/swc-linux-arm-gnueabihf" "12.1.0"
"@next/swc-linux-arm64-gnu" "12.1.0"
"@next/swc-linux-arm64-musl" "12.1.0"
"@next/swc-linux-x64-gnu" "12.1.0"
"@next/swc-linux-x64-musl" "12.1.0"
"@next/swc-win32-arm64-msvc" "12.1.0"
"@next/swc-win32-ia32-msvc" "12.1.0"
"@next/swc-win32-x64-msvc" "12.1.0"
node-abi@^3.3.0:
version "3.5.0"