Update WeChat draft follow template
Memind CI / Test, build, and release guards (push) Failing after 2m51s

This commit is contained in:
john
2026-09-14 15:36:40 +08:00
parent 64b5819978
commit b6d85d487a
13 changed files with 302 additions and 16 deletions
+38 -6
View File
@@ -14,6 +14,13 @@ import { WECHAT_DRAFT_PUBLICATION_STANDARD } from './wechat-draft-publication-st
const WECHAT_DRAFT_CONTENT_CHAR_LIMIT =
WECHAT_DRAFT_PUBLICATION_STANDARD.limits.maxContentChars;
const FOLLOW_QRCODE_SIZE_PX = 120;
const MP_FOLLOW_QRCODE_PUBLIC_PATH = '/assets/mp-follow-qrcode.png';
export function resolveMpFollowQrcodePublicUrl(env = process.env) {
const base = String(env.H5_PUBLIC_BASE_URL ?? 'https://m.tkmind.cn').replace(/\/$/, '');
return `${base}${MP_FOLLOW_QRCODE_PUBLIC_PATH}`;
}
export function clipWechatDraftBodyToFitFooter(
body,
@@ -35,9 +42,16 @@ export function clipWechatDraftBodyToFitFooter(
export function renderReadOriginalLink(publicUrl) {
if (!publicUrl) return '';
return [
'<p style="margin:18px 0 10px;text-align:center;line-height:1.6;">',
`<a href="${publicUrl}" style="display:inline-block;padding:5px 14px;border:1px solid #e2e8f0;border-radius:999px;color:#576b95;font-size:12px;text-decoration:none;background:#fafafa;">📖 阅读原文</a>`,
'<section style="text-align:center;margin:26px 0 14px;padding:20px 16px 18px;background:linear-gradient(180deg,#eef4ff 0%,#fff 100%);border:2px dashed #576b95;border-radius:16px;box-shadow:0 6px 18px rgba(87,107,149,.12);">',
'<p style="margin:0;font-size:14px;color:#4a5568;line-height:1.6;font-weight:600;">✨ 完整网页版更精彩</p>',
'<p style="margin:6px 0 0;font-size:12px;color:#718096;line-height:1.5;">动画 · 互动 · 高清大图 · 完整内容</p>',
'<p style="margin:14px 0 0;font-size:26px;line-height:1;color:#576b95;letter-spacing:6px;font-weight:700;">⬇ ⬇ ⬇</p>',
'<p style="margin:12px 0 0;">',
`<a href="${publicUrl}" style="display:inline-block;padding:12px 32px;border-radius:999px;background:linear-gradient(135deg,#576b95,#3d5a80);color:#fff;font-size:16px;font-weight:700;text-decoration:none;box-shadow:0 6px 16px rgba(87,107,149,.35);">📖 阅读原文</a>`,
'</p>',
'<p style="margin:12px 0 0;font-size:13px;color:#576b95;font-weight:700;line-height:1.5;">👆 点击上方按钮,查看完整精彩页面</p>',
'<p style="margin:8px 0 0;font-size:22px;line-height:1;color:#576b95;letter-spacing:4px;">➡️ ➡️ ➡️</p>',
'</section>',
].join('');
}
@@ -48,7 +62,7 @@ export function renderFollowTkMindSection({
qrcodeImageUrl = '',
} = {}) {
const qrcodeBlock = qrcodeImageUrl
? `<img src="${qrcodeImageUrl}" alt="TKMind 服务号二维码" style="width:168px;height:168px;display:block;margin:14px auto 0;border-radius:10px;border:1px solid #eee;" />`
? `<img src="${qrcodeImageUrl}" alt="TKMind 服务号二维码" style="width:${FOLLOW_QRCODE_SIZE_PX}px;height:${FOLLOW_QRCODE_SIZE_PX}px;display:block;margin:12px auto 0;border-radius:10px;border:1px solid #eee;" />`
: '';
return [
'<section style="text-align:center;padding:22px 16px 18px;margin:18px 0 8px;background:linear-gradient(180deg,#fff8f8,#fff);border:1px solid #ffcdd2;border-radius:12px;">',
@@ -84,23 +98,41 @@ export function resolveTkMindBrandIconPath(memindLibRoot = process.cwd()) {
return candidates.find((candidate) => fs.existsSync(candidate)) ?? null;
}
export function resolveMpFollowQrcodeAssetPath(memindLibRoot = process.cwd()) {
const fromHelper = resolveMpFollowQrcodePath(memindLibRoot);
if (fromHelper) return fromHelper;
const publicAsset = path.join(memindLibRoot, 'public', MP_FOLLOW_QRCODE_PUBLIC_PATH.replace(/^\//, ''));
if (fs.existsSync(publicAsset)) return publicAsset;
const cwdPublicAsset = path.join(process.cwd(), 'public', MP_FOLLOW_QRCODE_PUBLIC_PATH.replace(/^\//, ''));
return fs.existsSync(cwdPublicAsset) ? cwdPublicAsset : null;
}
export async function uploadWechatDraftBrandAssets({
accessToken,
wechatFetch = undiciFetch,
memindLibRoot = process.cwd(),
env = process.env,
} = {}) {
const qrcodePath = resolveMpFollowQrcodeAssetPath(memindLibRoot);
const publicFallbackUrl = resolveMpFollowQrcodePublicUrl(env);
let qrcodeImageUrl = '';
if (!accessToken) {
if (!qrcodePath) {
return { qrcodeImageUrl };
}
const qrcodePath = resolveMpFollowQrcodePath(memindLibRoot);
if (qrcodePath) {
if (!accessToken) {
return { qrcodeImageUrl: publicFallbackUrl };
}
try {
qrcodeImageUrl = await uploadWechatArticleContentImage(
accessToken,
fs.readFileSync(qrcodePath),
{ wechatFetch, filename: 'mp-follow-qrcode.png' },
);
} catch {
qrcodeImageUrl = publicFallbackUrl;
}
return { qrcodeImageUrl };