diff --git a/pages/[prefix]/[slug].js b/pages/[prefix]/[slug].js index 65d025c1..cf249228 100644 --- a/pages/[prefix]/[slug].js +++ b/pages/[prefix]/[slug].js @@ -3,7 +3,7 @@ import { getPostBlocks } from '@/lib/notion' import { getGlobalData } from '@/lib/notion/getNotionData' import { idToUuid } from 'notion-utils' import { getNotion } from '@/lib/notion/getNotion' -import Slug from '.' +import Slug, { getRecommendPost } from '.' /** * 根据notion的slug访问页面 @@ -84,39 +84,4 @@ export async function getStaticProps({ params: { prefix, slug } }) { } } -/** - * 获取文章的关联推荐文章列表,目前根据标签关联性筛选 - * @param post - * @param {*} allPosts - * @param {*} count - * @returns - */ -function getRecommendPost(post, allPosts, count = 6) { - let recommendPosts = [] - const postIds = [] - const currentTags = post?.tags || [] - for (let i = 0; i < allPosts.length; i++) { - const p = allPosts[i] - if (p.id === post.id || p.type.indexOf('Post') < 0) { - continue - } - - for (let j = 0; j < currentTags.length; j++) { - const t = currentTags[j] - if (postIds.indexOf(p.id) > -1) { - continue - } - if (p.tags && p.tags.indexOf(t) > -1) { - recommendPosts.push(p) - postIds.push(p.id) - } - } - } - - if (recommendPosts.length > count) { - recommendPosts = recommendPosts.slice(0, count) - } - return recommendPosts -} - export default PrefixSlug diff --git a/pages/[prefix]/index.js b/pages/[prefix]/index.js index da351672..8c10b063 100644 --- a/pages/[prefix]/index.js +++ b/pages/[prefix]/index.js @@ -96,7 +96,6 @@ export async function getStaticPaths() { } export async function getStaticProps({ params: { prefix } }) { - // let fullSlug = slug.join('/') let fullSlug = prefix if (JSON.parse(BLOG.PSEUDO_STATIC)) { if (!fullSlug.endsWith('.html')) { @@ -161,7 +160,7 @@ export async function getStaticProps({ params: { prefix } }) { * @param {*} count * @returns */ -function getRecommendPost(post, allPosts, count = 6) { +export function getRecommendPost(post, allPosts, count = 6) { let recommendPosts = [] const postIds = [] const currentTags = post?.tags || []