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 d4d9be6..50477b6 100644 --- a/skills/baoyu-post-to-wechat/scripts/md-to-wechat.ts +++ b/skills/baoyu-post-to-wechat/scripts/md-to-wechat.ts @@ -121,8 +121,14 @@ export async function convertMarkdown(markdownPath: string, options?: { title?: let title = options?.title ?? frontmatter.title ?? ''; if (!title) { - const h1Match = body.match(/^#\s+(.+)$/m); - if (h1Match) title = h1Match[1]!; + 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]!; + break; + } } if (!title) title = path.basename(markdownPath, path.extname(markdownPath)); const author = frontmatter.author || ''; diff --git a/skills/baoyu-post-to-wechat/scripts/wechat-article.ts b/skills/baoyu-post-to-wechat/scripts/wechat-article.ts index e2d8ddb..b237156 100644 --- a/skills/baoyu-post-to-wechat/scripts/wechat-article.ts +++ b/skills/baoyu-post-to-wechat/scripts/wechat-article.ts @@ -184,11 +184,13 @@ function parseHtmlMeta(htmlPath: string): { title: string; author: string; summa if (titleMatch) title = titleMatch[1]!; let author = ''; - const authorMatch = content.match(/ { await evaluate(session, `document.querySelector('#author').value = ${JSON.stringify(effectiveAuthor)}; document.querySelector('#author').dispatchEvent(new Event('input', { bubbles: true }));`); } + if (effectiveSummary) { + console.log(`[wechat] Filling summary: ${effectiveSummary}`); + await evaluate(session, `document.querySelector('#js_description').value = ${JSON.stringify(effectiveSummary)}; document.querySelector('#js_description').dispatchEvent(new Event('input', { bubbles: true }));`); + } + + await sleep(500); + + if (effectiveTitle) { + const actualTitle = await evaluate(session, `document.querySelector('#title')?.value || ''`); + if (actualTitle === effectiveTitle) { + console.log('[wechat] Title verified OK.'); + } else { + console.warn(`[wechat] Title verification failed. Expected: "${effectiveTitle}", got: "${actualTitle}"`); + } + } + + if (effectiveSummary) { + const actualSummary = await evaluate(session, `document.querySelector('#js_description')?.value || ''`); + if (actualSummary === effectiveSummary) { + console.log('[wechat] Summary verified OK.'); + } else { + console.warn(`[wechat] Summary verification failed. Expected: "${effectiveSummary}", got: "${actualSummary}"`); + } + } + console.log('[wechat] Clicking on editor...'); await clickElement(session, '.ProseMirror'); await sleep(1000); @@ -395,6 +422,20 @@ export async function postArticle(options: ArticleOptions): Promise { await pasteFromClipboardInEditor(session); await sleep(3000); + const editorHasContent = await evaluate(session, ` + (function() { + const editor = document.querySelector('.ProseMirror'); + if (!editor) return false; + const text = editor.innerText?.trim() || ''; + return text.length > 0; + })() + `); + if (editorHasContent) { + console.log('[wechat] Body content verified OK.'); + } else { + console.warn('[wechat] Body content verification failed: editor appears empty after paste.'); + } + if (contentImages.length > 0) { console.log(`[wechat] Inserting ${contentImages.length} images...`); for (let i = 0; i < contentImages.length; i++) { @@ -437,11 +478,20 @@ export async function postArticle(options: ArticleOptions): Promise { console.log('[wechat] Typing content...'); await typeText(session, content); await sleep(1000); - } - if (effectiveSummary) { - console.log(`[wechat] Filling summary: ${effectiveSummary}`); - await evaluate(session, `document.querySelector('#js_description').value = ${JSON.stringify(effectiveSummary)}; document.querySelector('#js_description').dispatchEvent(new Event('input', { bubbles: true }));`); + const editorHasContent = await evaluate(session, ` + (function() { + const editor = document.querySelector('.ProseMirror'); + if (!editor) return false; + const text = editor.innerText?.trim() || ''; + return text.length > 0; + })() + `); + if (editorHasContent) { + console.log('[wechat] Body content verified OK.'); + } else { + console.warn('[wechat] Body content verification failed: editor appears empty after typing.'); + } } console.log('[wechat] Saving as draft...');