fix(wechat): add fallback trim profiles for 20k content limit
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { extractPageTitle } from './wechat/verify/share-preview-repair.mjs';
|
||||
|
||||
const MAX_WECHAT_CONTENT_CHARS = 20000;
|
||||
const MAX_WECHAT_CONTENT_TARGET_CHARS = 19800;
|
||||
const MAX_WECHAT_CONTENT_TARGET_CHARS = 19600;
|
||||
|
||||
const CARD_VARIANTS = {
|
||||
'highlight-box': {
|
||||
@@ -221,6 +221,33 @@ const TRIM_PROFILES = [
|
||||
},
|
||||
];
|
||||
|
||||
function buildFallbackTrimProfiles() {
|
||||
const profiles = [];
|
||||
for (let headlines = 3; headlines >= 2; headlines -= 1) {
|
||||
for (let maxBodyChars = 56; maxBodyChars >= 24; maxBodyChars -= 8) {
|
||||
for (const skipWeather of [false, true]) {
|
||||
profiles.push({
|
||||
skipHistory: true,
|
||||
skipWeather,
|
||||
sectionCardLimits: {
|
||||
headlines,
|
||||
world: 2,
|
||||
domestic: 2,
|
||||
google: 1,
|
||||
finance: 2,
|
||||
tech: 2,
|
||||
sports: 1,
|
||||
technews: 0,
|
||||
hot: 0,
|
||||
},
|
||||
maxBodyChars,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return profiles;
|
||||
}
|
||||
|
||||
function resolveSectionCardLimit(section, sectionCardLimits) {
|
||||
if (!sectionCardLimits) return null;
|
||||
return sectionCardLimits[section.id] ?? 3;
|
||||
@@ -238,7 +265,9 @@ function buildWechatInlineContent(html, { publicUrl = '', trimProfile = TRIM_PRO
|
||||
continue;
|
||||
}
|
||||
if (section.id === 'weather') {
|
||||
parts.push(renderWeatherSection(section.html));
|
||||
if (!trimProfile.skipWeather) {
|
||||
parts.push(renderWeatherSection(section.html));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
parts.push(renderGenericSection(section.html, {
|
||||
@@ -318,10 +347,13 @@ export function convertDailyNewsHtmlToWechatInlineArticle(html, { publicUrl = ''
|
||||
const digest = (extractMetaDescription(html) || title).slice(0, 120);
|
||||
let built = null;
|
||||
let trimLevel = 0;
|
||||
let usedFallback = false;
|
||||
const allProfiles = [...TRIM_PROFILES, ...buildFallbackTrimProfiles()];
|
||||
|
||||
for (const trimProfile of TRIM_PROFILES) {
|
||||
for (const [index, trimProfile] of allProfiles.entries()) {
|
||||
built = buildWechatInlineContent(html, { publicUrl, trimProfile });
|
||||
trimLevel = TRIM_PROFILES.indexOf(trimProfile);
|
||||
trimLevel = index;
|
||||
usedFallback = index >= TRIM_PROFILES.length;
|
||||
if (built.content.length <= MAX_WECHAT_CONTENT_TARGET_CHARS) {
|
||||
break;
|
||||
}
|
||||
@@ -344,6 +376,7 @@ export function convertDailyNewsHtmlToWechatInlineArticle(html, { publicUrl = ''
|
||||
renderedSectionCount: built.renderedSectionCount,
|
||||
trimLevel,
|
||||
trimmed: trimLevel > 0,
|
||||
usedFallbackTrim: usedFallback,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user