78b7d546c2
Let users bind their own official account credentials in M 配置 and push MindSpace pages to the WeChat draft box during or after publish, reusing the existing draft conversion pipeline. Co-authored-by: Cursor <cursoragent@cursor.com>
44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import {
|
|
convertGenericPageHtmlToWechatArticle,
|
|
convertPageHtmlToWechatArticle,
|
|
mindspaceWechatPageDraftInternals,
|
|
} from './mindspace-wechat-page-draft.mjs';
|
|
|
|
const SAMPLE_HTML = `<!DOCTYPE html>
|
|
<html><head><title>测试页面</title>
|
|
<meta name="description" content="页面摘要"></head>
|
|
<body><h1>标题</h1><p>正文内容</p></body></html>`;
|
|
|
|
test('convertGenericPageHtmlToWechatArticle extracts title and body', () => {
|
|
const article = convertGenericPageHtmlToWechatArticle(SAMPLE_HTML, {
|
|
publicUrl: 'https://m.tkmind.cn/u/demo/pages/test.html',
|
|
pageTitle: '测试页面',
|
|
pageSummary: '页面摘要',
|
|
});
|
|
assert.equal(article.title, '测试页面');
|
|
assert.equal(article.digest, '页面摘要');
|
|
assert.match(article.content, /正文内容/);
|
|
assert.match(article.content, /阅读原文/);
|
|
});
|
|
|
|
test('convertPageHtmlToWechatArticle falls back to generic converter', () => {
|
|
const article = convertPageHtmlToWechatArticle(SAMPLE_HTML, {
|
|
publicUrl: 'https://example.com/page.html',
|
|
pageTitle: '测试页面',
|
|
pageSummary: '页面摘要',
|
|
});
|
|
assert.equal(article.title, '测试页面');
|
|
assert.match(article.content, /正文内容/);
|
|
});
|
|
|
|
test('convertGenericPageHtmlToWechatArticle truncates long content', () => {
|
|
const longBody = `<p>${'很长'.repeat(12000)}</p>`;
|
|
const article = mindspaceWechatPageDraftInternals.convertGenericPageHtmlToWechatArticle(
|
|
`<html><body>${longBody}</body></html>`,
|
|
{ pageTitle: '长文' },
|
|
);
|
|
assert.ok(article.content.length <= 20000);
|
|
});
|