Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d475087d2 |
@@ -1,5 +1,6 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
@@ -196,12 +197,20 @@ test('convertRichMindSpacePageHtmlToWechatArticle extracts blog and startup temp
|
||||
});
|
||||
|
||||
test('collectPageImageCandidates adds sidecar thumbnail when hero image missing', () => {
|
||||
const publishDir = path.join(process.cwd(), 'MindSpace', '1c99b83b-0454-474f-a5d2-129d34506a32');
|
||||
const html = fs.readFileSync(path.join(publishDir, 'public/qiuting-xiaoxi.html'), 'utf8');
|
||||
const candidates = mindspaceWechatPageDraftInternals.collectPageImageCandidates(html, {
|
||||
publishDir,
|
||||
htmlRelativePath: 'public/qiuting-xiaoxi.html',
|
||||
});
|
||||
const publishDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mindspace-wechat-draft-'));
|
||||
const htmlRelativePath = 'public/no-hero-page.html';
|
||||
const htmlPath = path.join(publishDir, htmlRelativePath);
|
||||
fs.mkdirSync(path.dirname(htmlPath), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
htmlPath,
|
||||
'<!doctype html><html><head><title>无封面页</title></head><body><h1>无封面页</h1><p>正文</p></body></html>',
|
||||
'utf8',
|
||||
);
|
||||
fs.writeFileSync(htmlPath.replace(/\.html$/i, '.thumbnail.png'), Buffer.from('png'), 'utf8');
|
||||
const candidates = mindspaceWechatPageDraftInternals.collectPageImageCandidates(
|
||||
fs.readFileSync(htmlPath, 'utf8'),
|
||||
{ publishDir, htmlRelativePath },
|
||||
);
|
||||
assert.ok(candidates.some((item) => /\.thumbnail\.(png|svg)$/i.test(item.ref ?? '')));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user