From 78dc4cce44d1dcab5b268620811c92c5be34c842 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 7 Jun 2024 23:12:29 +0800 Subject: [PATCH] feat: enhanced filter --- data/filter.json | 5 +++-- src/models/home.model.ts | 8 +++++++- src/models/page.model.ts | 10 ++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/data/filter.json b/data/filter.json index 2fb6eb1f8f..ca5f3bd3f0 100644 --- a/data/filter.json +++ b/data/filter.json @@ -2,8 +2,9 @@ "latest": [ 151, 53994, 54570, 54481, 54537, 54302, 53944, 55768, 55855, 56592, 54986, 56875, 56873, 56666, 55996, 57407, 56249, 57858, 56973, 58600, 57399, 59737, - 61688, 69750, 62764, 70101, 70194, 70191, 70146, 70190, 70189, 70188, 70187, 70186, 70182 + 61688, 69750, 62764, 70101, 70146, 70188 ], "comment": [54986], - "comment_content": ["snowcherryblossom"] + "comment_content": ["snowcherryblossom"], + "post_content": ["R851UX3N", "BLBKKBVT", "biyijia"] } diff --git a/src/models/home.model.ts b/src/models/home.model.ts index 6f0f82bfbe..7b2351b038 100644 --- a/src/models/home.model.ts +++ b/src/models/home.model.ts @@ -83,6 +83,12 @@ export async function getFeed({ } ` + const contentFilterQuery = filter.post_content + .map((content) => { + return `{ content: { path: "content", string_contains: "${content}" } }` + }) + .join(",\n") + let resultAll: { list: ExpandedNote[] cursor?: string | null @@ -127,7 +133,7 @@ export async function getFeed({ path: "tags", array_starts_with: "short" # TODO: remove this } - }] + }, ${contentFilterQuery}] }, }, orderBy: [{ createdAt: desc }], diff --git a/src/models/page.model.ts b/src/models/page.model.ts index bb821707f4..82e0030341 100644 --- a/src/models/page.model.ts +++ b/src/models/page.model.ts @@ -30,6 +30,8 @@ import { } from "~/lib/types" import { client } from "~/queries/graphql" +import filter from "../../data/filter.json" + export const PINNED_PAGE_KEY = "xlog_pinned_page" export async function checkPageSlug(input: { @@ -175,6 +177,13 @@ export async function getPagesBySite(input: { }`, ) .join(", ") + + const contentFilterQuery = filter.post_content + .map((content) => { + return `{ content: { path: "content", string_contains: "${content}" } }` + }) + .join(",\n") + const whereQuery = ` { characterId: { @@ -189,6 +198,7 @@ export async function getPagesBySite(input: { equals: false, }, metadata: { + NOT: [${contentFilterQuery}], AND: [ { content: {