export.js
1 import * as fs from 'node:fs'; 2 import { cli, Strategy } from '@jackwener/opencli/registry'; 3 export const exportCommand = cli({ 4 site: 'notion', 5 name: 'export', 6 description: 'Export the current Notion page as Markdown', 7 domain: 'localhost', 8 strategy: Strategy.UI, 9 browser: true, 10 args: [ 11 { name: 'output', required: false, help: 'Output file (default: /tmp/notion-export.md)' }, 12 ], 13 columns: ['Status', 'File'], 14 func: async (page, kwargs) => { 15 const outputPath = kwargs.output || '/tmp/notion-export.md'; 16 const result = await page.evaluate(` 17 (function() { 18 const titleEl = document.querySelector('[data-block-id] [placeholder="Untitled"], h1.notion-title, [class*="title"]'); 19 const title = titleEl ? (titleEl.textContent || '').trim() : document.title; 20 21 const frame = document.querySelector('.notion-page-content, [class*="page-content"], main'); 22 const content = frame ? (frame.innerText || '').trim() : document.body.innerText; 23 24 return { title, content }; 25 })() 26 `); 27 const md = `# ${result.title}\n\n${result.content}`; 28 fs.writeFileSync(outputPath, md); 29 return [{ Status: 'Success', File: outputPath }]; 30 }, 31 });