From a282d2394525e19b322e50d6fb0e36123c07d7cc Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Thu, 24 Feb 2022 10:35:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8D=87=E7=BA=A7notion-client\util\react-?= =?UTF-8?q?notion-x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 172ff5778e5..aa2c37a4d2f 100644 --- a/package.json +++ b/package.json @@ -33,15 +33,15 @@ "lodash.throttle": "^4.1.1", "memory-cache": "^0.2.0", "next": "^12.0.5", - "notion-client": "4.14.1", - "notion-utils": "4.14.1", + "notion-client": "4.16.0", + "notion-utils": "4.16.0", "preact": "^10.5.15", "qrcode.react": "^1.0.1", "react": "17.0.2", "react-cookies": "^0.1.1", "react-cusdis": "^2.1.3", "react-dom": "17.0.2", - "react-notion-x": "4.14.2", + "react-notion-x": "4.16.0", "smoothscroll-polyfill": "^0.4.4", "typed.js": "^2.0.12", "use-ackee": "^3.0.0" From bebde04f1581f072832b84f653f884839331ff8d Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Sat, 26 Feb 2022 20:37:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=BC=96=E8=AF=91=EF=BC=9A=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=8E=A8=E8=8D=90=E6=96=87=E7=AB=A0=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/article/[slug].js | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/pages/article/[slug].js b/pages/article/[slug].js index bdc6d7069b3..d20cf97a05a 100644 --- a/pages/article/[slug].js +++ b/pages/article/[slug].js @@ -68,22 +68,25 @@ export async function getStaticProps ({ params: { slug } }) { } /** - * + * 获取文章的关联推荐文章列表,目前根据标签关联性筛选 * @param post * @param {*} allPosts * @param {*} count * @returns */ function getRecommendPost (post, allPosts, count = 5) { - let filteredPosts = Object.create(allPosts) - // 筛选同标签 + let filteredPosts = [] + for (const i in allPosts) { + const p = allPosts[i] + filteredPosts.push(Object.assign(p)) + } + if (post.tags && post.tags.length) { const currentTag = post.tags[0] filteredPosts = filteredPosts.filter( - p => p && p.tags && p.tags.includes(currentTag) && p.slug !== post.slug && p.type === 'post' + p => p && p.slug !== post.slug && p.tags && p.tags?.includes(currentTag) && p.type === ['Post'] ) } - shuffleSort(filteredPosts) // 筛选前5个 if (filteredPosts.length > count) { @@ -92,21 +95,4 @@ function getRecommendPost (post, allPosts, count = 5) { return filteredPosts } -/** - * 洗牌乱序:从数组的最后位置开始,从前面随机一个位置,对两个数进行交换,直到循环完毕 - * @param arr - * @returns {*} - */ -function shuffleSort (arr) { - let i = arr.length - 1 - while (i > 0) { - const rIndex = Math.floor(Math.random() * i) - const temp = arr[rIndex] - arr[rIndex] = arr[i] - arr[i] = temp - i-- - } - return arr -} - export default Slug