feat: stable feed count
This commit is contained in:
@@ -19,8 +19,6 @@ import { ExpandedNote } from "~/lib/types"
|
||||
import type { FeedType, SearchType } from "~/models/home.model"
|
||||
import { useGetFeed } from "~/queries/home"
|
||||
|
||||
import topics from "../../../data/topics.json"
|
||||
|
||||
export const HomeFeed = ({ type }: { type?: FeedType }) => {
|
||||
const { t } = useTranslation("common")
|
||||
const searchParams = useSearchParams()
|
||||
@@ -53,7 +51,6 @@ export const HomeFeed = ({ type }: { type?: FeedType }) => {
|
||||
}
|
||||
break
|
||||
case "topic":
|
||||
const info = topics.find((t) => t.name === params.topic)
|
||||
feedConfig = {
|
||||
type,
|
||||
topic: params.topic,
|
||||
|
||||
+37
-10
@@ -785,22 +785,49 @@ export async function getFeed({
|
||||
}
|
||||
}
|
||||
|
||||
let isFiltered = false
|
||||
resultAll.list = resultAll.list
|
||||
.filter(
|
||||
(post) =>
|
||||
countCharacters(post?.metadata?.content?.content || "") >
|
||||
(post?.metadata?.content?.tags?.[0] === "comment"
|
||||
? 6
|
||||
: post?.metadata?.content?.tags?.[0] === "portfolio"
|
||||
? -1
|
||||
: 300) &&
|
||||
!(new Date(post.metadata?.content?.date_published || "") > new Date()),
|
||||
)
|
||||
.filter((post) => {
|
||||
let limit = 300
|
||||
switch (post?.metadata?.content?.tags?.[0]) {
|
||||
case "comment":
|
||||
limit = 6
|
||||
break
|
||||
case "portfolio":
|
||||
limit = -1
|
||||
break
|
||||
}
|
||||
const pass =
|
||||
countCharacters(post?.metadata?.content?.content || "") > limit &&
|
||||
!(new Date(post.metadata?.content?.date_published || "") > new Date())
|
||||
if (!pass) {
|
||||
isFiltered = true
|
||||
}
|
||||
return pass
|
||||
})
|
||||
.map((post) => {
|
||||
delete post.metadata?.content.content
|
||||
return post
|
||||
})
|
||||
|
||||
if (isFiltered && resultAll.list.length < limit && resultAll.cursor) {
|
||||
const next = await getFeed({
|
||||
type,
|
||||
cursor: resultAll.cursor,
|
||||
limit: limit - resultAll.list.length,
|
||||
characterId,
|
||||
daysInterval,
|
||||
searchKeyword,
|
||||
searchType,
|
||||
tag,
|
||||
useHTML,
|
||||
topic,
|
||||
})
|
||||
resultAll.list = resultAll.list.concat(next.list)
|
||||
resultAll.cursor = next.cursor
|
||||
resultAll.count = next.count
|
||||
}
|
||||
|
||||
return resultAll
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user