mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
feat: init @affine/docs (#2849)
This commit is contained in:
26
apps/docs/src/app.tsx
Normal file
26
apps/docs/src/app.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
'use server';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
import type { ReactElement } from 'react';
|
||||
import { lazy } from 'react';
|
||||
|
||||
const Editor = lazy(() =>
|
||||
import('./components/editor.js').then(({ Editor }) => ({ default: Editor }))
|
||||
);
|
||||
|
||||
const markdown = await fs.readFile(path.join('./src/pages/index.md'), {
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
|
||||
const App = (): ReactElement => {
|
||||
return (
|
||||
<div>
|
||||
<div className="mt-5">
|
||||
<Editor text={markdown} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
54
apps/docs/src/components/editor.tsx
Normal file
54
apps/docs/src/components/editor.tsx
Normal file
@@ -0,0 +1,54 @@
|
||||
'use client';
|
||||
import '@blocksuite/editor/themes/affine.css';
|
||||
|
||||
import { BlockSuiteEditor } from '@affine/component/block-suite-editor';
|
||||
import { ContentParser } from '@blocksuite/blocks/content-parser';
|
||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||
import { assertExists, Workspace } from '@blocksuite/store';
|
||||
import type { ReactElement } from 'react';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
const workspace = new Workspace({
|
||||
id: 'local-workspace',
|
||||
})
|
||||
.register(AffineSchemas)
|
||||
.register(__unstableSchemas);
|
||||
|
||||
const page = workspace.createPage({
|
||||
id: 'example-page',
|
||||
});
|
||||
|
||||
export type EditorProps = {
|
||||
text: string;
|
||||
};
|
||||
|
||||
export const Editor = (props: EditorProps): ReactElement => {
|
||||
return (
|
||||
<BlockSuiteEditor
|
||||
page={page}
|
||||
mode="page"
|
||||
onInit={useCallback(
|
||||
async page => {
|
||||
const text = props.text;
|
||||
await page.waitForLoaded();
|
||||
const metadata = text.split('---\n')[1];
|
||||
assertExists(metadata);
|
||||
|
||||
// find title
|
||||
const title = metadata.split('title: ')[1]?.split('\n')[0];
|
||||
const pageBlockId = page.addBlock('affine:page', {
|
||||
title: new page.Text(title),
|
||||
});
|
||||
page.addBlock('affine:surface', {}, pageBlockId);
|
||||
const noteBlockId = page.addBlock('affine:note', {}, pageBlockId);
|
||||
const contentParser = new ContentParser(page);
|
||||
const content = text.split('---\n')[2];
|
||||
assertExists(content);
|
||||
console.log('metadata', title, content);
|
||||
await contentParser.importMarkdown(content, noteBlockId);
|
||||
},
|
||||
[props.text]
|
||||
)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
3
apps/docs/src/index.css
Normal file
3
apps/docs/src/index.css
Normal file
@@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
14
apps/docs/src/index.tsx
Normal file
14
apps/docs/src/index.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import './index.css';
|
||||
|
||||
import { StrictMode } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { serve } from 'waku/client';
|
||||
|
||||
const App = serve('App');
|
||||
const rootElement = (
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>
|
||||
);
|
||||
|
||||
createRoot(document.getElementById('root') as HTMLElement).render(rootElement);
|
||||
9
apps/docs/src/pages/index.md
Normal file
9
apps/docs/src/pages/index.md
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
title: AFFiNE Developer Documentation
|
||||
---
|
||||
|
||||
```shell
|
||||
corepack enable
|
||||
yarn install
|
||||
nx dev @affine/docs
|
||||
```
|
||||
Reference in New Issue
Block a user