feat: stable feed count
This commit is contained in:
parent
bd965bc757
commit
3be5ef4311
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"latest": [
|
||||
151, 53994, 54570, 54481, 54537, 54302, 53944, 55768, 55855, 56592, 54986,
|
||||
56875, 56873, 56666, 55996, 57407, 56249
|
||||
56875, 56873, 56666, 55996, 57407, 56249, 57858
|
||||
],
|
||||
"comment": [54986]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue