Skip to content

Commit

Permalink
feat(playground): add import notion zip entry (#8527)
Browse files Browse the repository at this point in the history
  • Loading branch information
donteatfriedrice authored Oct 15, 2024
1 parent 0695ac5 commit 1e0529e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
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

0 comments on commit 1e0529e

Please sign in to comment.