Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(playground): add import notion zip entry #8527

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/blocks/src/root-block/widgets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export { AffineImageToolbarWidget } from './image-toolbar/index.js';
export { AffineInnerModalWidget } from './inner-modal/inner-modal.js';
export { LinkedWidgetUtils } from './linked-doc/config.js';
export {
importNotion,
// It's used in the AFFiNE!
showImportModal,
} from './linked-doc/import-doc/index.js';
Expand Down
57 changes: 44 additions & 13 deletions packages/playground/apps/_common/components/debug-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ExportManager,
FontFamilyVariables,
HtmlTransformer,
importNotion,
MarkdownAdapter,
MarkdownTransformer,
NotionHtmlAdapter,
Expand Down Expand Up @@ -255,18 +256,40 @@ export class DebugMenu extends ShadowlessElement {
}

private async _importNotionHTML() {
const file = await openFileOrFiles({ acceptType: 'Html', multiple: false });
if (!file) return;
const job = new Job({
collection: this.collection,
middlewares: [defaultImageProxyMiddleware],
});
const htmlAdapter = new NotionHtmlAdapter(job);
await htmlAdapter.toDoc({
file: await file.text(),
pageId: this.collection.idGenerator(),
assets: job.assetsManager,
});
try {
const file = await openFileOrFiles({
acceptType: 'Html',
multiple: false,
});
if (!file) return;
const job = new Job({
collection: this.collection,
middlewares: [defaultImageProxyMiddleware],
});
const htmlAdapter = new NotionHtmlAdapter(job);
await htmlAdapter.toDoc({
file: await file.text(),
pageId: this.collection.idGenerator(),
assets: job.assetsManager,
});
} catch (error) {
console.error('Failed to import Notion HTML:', error);
}
}

private async _importNotionHTMLZip() {
try {
const file = await openFileOrFiles({ acceptType: 'Zip' });
if (!file) return;
const result = await importNotion(this.collection, file);
if (!this.editor.host) return;
toast(
this.editor.host,
`Successfully imported ${result.pageIds.length} Notion HTML pages.`
);
} catch (error) {
console.error('Failed to import Notion HTML Zip:', error);
}
}

private _importSnapshot() {
Expand Down Expand Up @@ -620,8 +643,16 @@ export class DebugMenu extends ShadowlessElement {
<sl-menu-item @click="${this._importSnapshot}">
Import Snapshot
</sl-menu-item>
<sl-menu-item @click="${this._importNotionHTML}">
<sl-menu-item>
Import Notion HTML
<sl-menu slot="submenu">
<sl-menu-item @click="${this._importNotionHTML}">
Single Notion HTML Page
</sl-menu-item>
<sl-menu-item @click="${this._importNotionHTMLZip}">
Notion HTML Zip
</sl-menu-item>
</sl-menu>
</sl-menu-item>
<sl-menu-item @click="${this._importMarkdown}">
Import Markdown
Expand Down
Loading