From a3849af0cf4d2d40c96491fe42c52b63d86f5831 Mon Sep 17 00:00:00 2001 From: AlexCheval Date: Thu, 5 Feb 2026 10:04:34 +0800 Subject: [PATCH] fix(baoyu-post-to-wechat): fix title and list number duplication in WeChat articles - Remove title from body content when extracting it for WeChat title field to prevent duplicate title display (one in header, one in content) - Remove manual ordered list prefix since HTML
    already provides numbering, preventing "1.1.", "2.2.", "3.3." duplication Co-Authored-By: Claude Opus 4.5 --- skills/baoyu-post-to-wechat/scripts/md-to-wechat.ts | 12 +++++++++--- skills/baoyu-post-to-wechat/scripts/md/render.ts | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/skills/baoyu-post-to-wechat/scripts/md-to-wechat.ts b/skills/baoyu-post-to-wechat/scripts/md-to-wechat.ts index 50477b6..53b1600 100644 --- a/skills/baoyu-post-to-wechat/scripts/md-to-wechat.ts +++ b/skills/baoyu-post-to-wechat/scripts/md-to-wechat.ts @@ -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; diff --git a/skills/baoyu-post-to-wechat/scripts/md/render.ts b/skills/baoyu-post-to-wechat/scripts/md/render.ts index 69dc1aa..f879bef 100644 --- a/skills/baoyu-post-to-wechat/scripts/md/render.ts +++ b/skills/baoyu-post-to-wechat/scripts/md/render.ts @@ -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 {