feat: 支持过滤微博热搜中的广告(FILTER_WEIBO_ADVERTISEMENT=true)

This commit is contained in:
猪猪公主z
2025-10-17 14:00:48 +08:00
parent 10db165fc4
commit 0a3869f1a2
4 changed files with 28 additions and 14 deletions

View File

@@ -27,4 +27,7 @@ REQUEST_TIMEOUT=6000
USE_LOG_FILE=true
# RSS Mode
RSS_MODE=false
RSS_MODE=false
# Weibo
FILTER_WEIBO_ADVERTISEMENT=false

View File

@@ -17,6 +17,7 @@ export type Config = {
REDIS_PASSWORD: string;
REDIS_DB: number;
ZHIHU_COOKIE: string;
FILTER_WEIBO_ADVERTISEMENT: boolean;
};
// 验证并提取环境变量
@@ -55,4 +56,5 @@ export const config: Config = {
REDIS_PASSWORD: getEnvVariable("REDIS_PASSWORD") || "",
REDIS_DB: getNumericEnvVariable("REDIS_DB", 0),
ZHIHU_COOKIE: getEnvVariable("ZHIHU_COOKIE") || "",
FILTER_WEIBO_ADVERTISEMENT: getBooleanEnvVariable("FILTER_WEIBO_ADVERTISEMENT", false),
};

View File

@@ -92,6 +92,7 @@ export type RouterType = {
// num: number;
desc_extr: number;
onboard_time: number;
pic: string;
};
zhihu: {
target: {

View File

@@ -2,6 +2,7 @@ import type { RouterData } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js";
import { config } from "../config";
export const handleRoute = async (_: undefined, noCache: boolean) => {
const listData = await getList(noCache);
@@ -36,18 +37,25 @@ const getList = async (noCache: boolean) => {
const list = result.data.data.cards?.[0]?.card_group;
return {
...result,
data: list.map((v: RouterType["weibo"]) => {
const key = v.word_scheme ? v.word_scheme : `#${v.desc}`;
return {
id: v.itemid,
title: v.desc,
desc: key,
// author: v.flag_desc,
timestamp: getTime(v.onboard_time),
hot: v.desc_extr,
url: `https://s.weibo.com/weibo?q=${encodeURIComponent(key)}&t=31&band_rank=1&Refer=top`,
mobileUrl: v?.scheme,
};
}),
data: list
.filter(
(v: RouterType["weibo"]) =>
!(
v?.pic === "https://simg.s.weibo.com/20210408_search_point_orange.png" &&
config.FILTER_WEIBO_ADVERTISEMENT
),
)
.map((v: RouterType["weibo"]) => {
const key = v.word_scheme ?? `#${v.desc}`;
return {
id: v.itemid,
title: v.desc,
desc: key,
timestamp: getTime(v.onboard_time),
hot: v.desc_extr,
url: `https://s.weibo.com/weibo?q=${encodeURIComponent(key)}&t=31&band_rank=1&Refer=top`,
mobileUrl: v?.scheme,
};
}),
};
};