fix(wechat): reserve space for uploaded follow QR in draft body
Memind CI / Test, build, and release guards (push) Failing after 5m35s
Memind CI / Test, build, and release guards (push) Failing after 5m35s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -287,10 +287,18 @@ function resolveSectionCardLimit(section, sectionCardLimits) {
|
|||||||
return sectionCardLimits[section.id] ?? 3;
|
return sectionCardLimits[section.id] ?? 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function estimateQrcodeUrlForLayout(qrcodeImageUrl = '') {
|
||||||
|
const url = String(qrcodeImageUrl ?? '');
|
||||||
|
if (!url) return '';
|
||||||
|
if (url.length >= 180) return url;
|
||||||
|
return `${url}${'x'.repeat(180 - url.length)}`;
|
||||||
|
}
|
||||||
|
|
||||||
function estimateFixedLayoutLength({ publicUrl = '', qrcodeImageUrl = '', portalUrl = DEFAULT_PORTAL_URL } = {}) {
|
function estimateFixedLayoutLength({ publicUrl = '', qrcodeImageUrl = '', portalUrl = DEFAULT_PORTAL_URL } = {}) {
|
||||||
|
const qrcodeForEstimate = estimateQrcodeUrlForLayout(qrcodeImageUrl);
|
||||||
return (
|
return (
|
||||||
(publicUrl ? renderReadOriginalTop(publicUrl).length : 0)
|
(publicUrl ? renderReadOriginalTop(publicUrl).length : 0)
|
||||||
+ renderFollowMpSection(qrcodeImageUrl).length
|
+ renderFollowMpSection(qrcodeForEstimate).length
|
||||||
+ renderCreatePortalCTA(portalUrl).length
|
+ renderCreatePortalCTA(portalUrl).length
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -405,7 +413,7 @@ export function convertDailyNewsHtmlToWechatInlineArticle(html, {
|
|||||||
const allProfiles = [...TRIM_PROFILES, ...buildFallbackTrimProfiles()];
|
const allProfiles = [...TRIM_PROFILES, ...buildFallbackTrimProfiles()];
|
||||||
|
|
||||||
const fixedLayoutLength = estimateFixedLayoutLength({ publicUrl, qrcodeImageUrl, portalUrl });
|
const fixedLayoutLength = estimateFixedLayoutLength({ publicUrl, qrcodeImageUrl, portalUrl });
|
||||||
const trimTargetChars = Math.max(12000, MAX_WECHAT_CONTENT_CHARS - fixedLayoutLength - 600);
|
const trimTargetChars = Math.max(12000, MAX_WECHAT_CONTENT_CHARS - fixedLayoutLength - 800);
|
||||||
|
|
||||||
for (const [index, trimProfile] of allProfiles.entries()) {
|
for (const [index, trimProfile] of allProfiles.entries()) {
|
||||||
built = buildWechatInlineContent(html, {
|
built = buildWechatInlineContent(html, {
|
||||||
@@ -431,23 +439,36 @@ export function convertDailyNewsHtmlToWechatInlineArticle(html, {
|
|||||||
trimProfile: selectedProfile,
|
trimProfile: selectedProfile,
|
||||||
includeFixedLayout: true,
|
includeFixedLayout: true,
|
||||||
});
|
});
|
||||||
while (built.content.length > MAX_WECHAT_CONTENT_CHARS && (selectedProfile.maxBodyChars ?? 120) > 20) {
|
let tightenGuard = 0;
|
||||||
|
while (built.content.length > MAX_WECHAT_CONTENT_CHARS && tightenGuard < 24) {
|
||||||
|
tightenGuard += 1;
|
||||||
|
const limits = {
|
||||||
|
world: 2,
|
||||||
|
domestic: 2,
|
||||||
|
google: 1,
|
||||||
|
tech: 2,
|
||||||
|
sports: 1,
|
||||||
|
technews: 0,
|
||||||
|
hot: 0,
|
||||||
|
headlines: selectedProfile.sectionCardLimits?.headlines ?? 3,
|
||||||
|
finance: selectedProfile.sectionCardLimits?.finance ?? 2,
|
||||||
|
};
|
||||||
|
const maxBody = selectedProfile.maxBodyChars ?? 64;
|
||||||
|
if (maxBody > 16) {
|
||||||
|
selectedProfile.maxBodyChars = maxBody - 4;
|
||||||
|
} else if (limits.headlines > 2) {
|
||||||
|
limits.headlines -= 1;
|
||||||
|
} else if (limits.finance > 1) {
|
||||||
|
limits.finance -= 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
selectedProfile = {
|
selectedProfile = {
|
||||||
...selectedProfile,
|
...selectedProfile,
|
||||||
|
skipHistory: true,
|
||||||
skipWeather: true,
|
skipWeather: true,
|
||||||
maxBodyChars: Math.max(20, (selectedProfile.maxBodyChars ?? 64) - 8),
|
maxBodyChars: selectedProfile.maxBodyChars ?? maxBody,
|
||||||
sectionCardLimits: {
|
sectionCardLimits: limits,
|
||||||
...(selectedProfile.sectionCardLimits ?? {}),
|
|
||||||
headlines: Math.max(2, selectedProfile.sectionCardLimits?.headlines ?? 3),
|
|
||||||
world: Math.min(2, selectedProfile.sectionCardLimits?.world ?? 2),
|
|
||||||
domestic: Math.min(2, selectedProfile.sectionCardLimits?.domestic ?? 2),
|
|
||||||
google: 1,
|
|
||||||
finance: 2,
|
|
||||||
tech: 2,
|
|
||||||
sports: 1,
|
|
||||||
technews: 0,
|
|
||||||
hot: 0,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
built = buildWechatInlineContent(html, {
|
built = buildWechatInlineContent(html, {
|
||||||
publicUrl,
|
publicUrl,
|
||||||
|
|||||||
Reference in New Issue
Block a user