Files
wehub-resource-sync 9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

42 lines
1.3 KiB
JavaScript

import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError } from '@jackwener/opencli/errors';
import { mubuPost, nodesToMarkdown, nodesToText } from './utils.js';
cli({
site: 'mubu',
name: 'doc',
access: 'read',
description: '读取幕布文档内容(默认输出 Markdown,可用 --output text 输出纯文本)',
domain: 'mubu.com',
strategy: Strategy.COOKIE,
defaultFormat: 'plain',
args: [
{ name: 'id', positional: true, required: true, help: '文档 ID' },
{ name: 'output', default: 'md', help: '输出格式:md(默认,缩进列表 Markdown,适合导入 Obsidian)或 text(纯文本,适合终端阅读)' },
],
columns: ['content'],
func: async (page, kwargs) => {
const docId = kwargs.id;
const format = kwargs.output;
if (format !== 'md' && format !== 'text') {
throw new ArgumentError(`--output 只接受 md 或 text,收到:${format}`);
}
await page.goto('https://mubu.com/app');
const data = await mubuPost(page, '/document/edit/get', { docId });
let nodes = [];
try {
const def = JSON.parse(data.definition);
nodes = def.nodes ?? [];
} catch {
return [{ content: data.name }];
}
const output = format === 'md' ? nodesToMarkdown(nodes) : nodesToText(nodes);
return [{ content: output }];
},
});