Merge pull request #36 from NantesCheval/fix/wechat-title-and-list-duplication

fix(baoyu-post-to-wechat): fix title and list number duplication in WeChat articles
This commit is contained in:
Jim Liu 宝玉
2026-02-05 23:09:17 -06:00
committed by GitHub
2 changed files with 10 additions and 4 deletions
@@ -120,22 +120,28 @@ export async function convertMarkdown(markdownPath: string, options?: { title?:
const { frontmatter, body } = parseFrontmatter(content);
let title = options?.title ?? frontmatter.title ?? '';
let bodyWithoutTitle = body;
if (!title) {
const lines = body.split('\n');
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed) continue;
const headingMatch = trimmed.match(/^#{1,2}\s+(.+)$/);
if (headingMatch) title = headingMatch[1]!;
if (headingMatch) {
title = headingMatch[1]!;
bodyWithoutTitle = body.replace(/^#{1,2}\s+.+\r?\n?/, '');
}
break;
}
} else {
bodyWithoutTitle = body.replace(/^#{1,2}\s+.+\r?\n?/, '');
}
if (!title) title = path.basename(markdownPath, path.extname(markdownPath));
const author = frontmatter.author || '';
let summary = frontmatter.description || frontmatter.summary || '';
if (!summary) {
const lines = body.split('\n');
const lines = bodyWithoutTitle.split('\n');
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed) continue;
@@ -161,7 +167,7 @@ export async function convertMarkdown(markdownPath: string, options?: { title?:
const images: Array<{ src: string; placeholder: string }> = [];
let imageCounter = 0;
const modifiedBody = body.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (match, alt, src) => {
const modifiedBody = bodyWithoutTitle.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (match, alt, src) => {
const placeholder = `WECHATIMGPH_${++imageCounter}`;
images.push({ src, placeholder });
return placeholder;
@@ -374,7 +374,7 @@ export function initRenderer(opts: IOpts = {}): RendererAPI {
listCounters[listCounters.length - 1] = idx + 1;
const prefix = ordered ? `${idx}. ` : "• ";
const prefix = ordered ? "" : "• ";
let content: string;
try {