Skip to content

Commit db49414

Browse files
committed
feat: notion renderer
1 parent 3a4221d commit db49414

21 files changed

+485
-10
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true

.eslintrc.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module.exports = {
1212
ignorePatterns: ['*.cjs'],
1313
rules: {
1414
'prettier/prettier': 'error',
15-
'@typescript-eslint/no-non-null-assertion': 'off'
15+
'@typescript-eslint/no-non-null-assertion': 'off',
16+
'svelte/no-at-html-tags': 'off'
1617
},
1718
parserOptions: {
1819
sourceType: 'module',

.prettierrc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@
33
"singleQuote": true,
44
"trailingComma": "none",
55
"printWidth": 100,
6-
"plugins": [
7-
"prettier-plugin-svelte",
8-
"prettier-plugin-tailwindcss"
9-
],
10-
"pluginSearchDirs": [
11-
"."
12-
],
6+
"plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
7+
"pluginSearchDirs": ["."],
138
"overrides": [
149
{
1510
"files": "*.svelte",
@@ -18,4 +13,4 @@
1813
}
1914
}
2015
]
21-
}
16+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"prettier-plugin-tailwindcss": "^0.2.1",
3636
"svelte": "^3.44.0",
3737
"svelte-check": "^2.7.1",
38+
"svelte-highlight": "^7.1.2",
3839
"svelte-icons": "^2.1.0",
3940
"svelte-preprocess": "^4.10.7",
4041
"tailwindcss": "^3.1.5",
@@ -48,4 +49,4 @@
4849
"clsx": "^1.2.1",
4950
"nprogress": "^0.2.0"
5051
}
51-
}
52+
}

src/app.postcss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ body {
3333
.icon.sm {
3434
@apply h-[24px] w-[24px];
3535
}
36+
37+
/* TODO: Add all notion styles here */
38+
.notion-code-inline {
39+
@apply rounded-md bg-neutral-800 p-1 font-mono text-sm text-red-400 !important;
40+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script lang="ts">
2+
import type { NotionBlock } from '../index';
3+
import { NOTION_BLOCK_RENDERERS } from '../notion.renderer';
4+
5+
// Pass in the
6+
export let block: NotionBlock;
7+
8+
const renderer = NOTION_BLOCK_RENDERERS[block.type];
9+
</script>
10+
11+
{#if renderer}
12+
<svelte:component this={renderer()} {...$$restProps} {block} data={block[block.type]} />
13+
{:else}
14+
<p class="text-red-400">Unknown block type: {block.type}</p>
15+
<pre>{JSON.stringify(block, null, 2)}</pre>
16+
{/if}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<script lang="ts">
2+
import clsx from 'clsx';
3+
import type { NotionRichTextData } from '../notion.types';
4+
import NotionBlock from './NotionBlock.svelte';
5+
import NotionRichText from './NotionRichText.svelte';
6+
7+
export let block: NotionBlock;
8+
export let data: {
9+
rich_text: NotionRichTextData[];
10+
};
11+
12+
// Indentation
13+
export let level = 0;
14+
const levels: {
15+
ul: string;
16+
li: string;
17+
}[] = [
18+
{
19+
ul: 'list-disc',
20+
li: 'ml-0'
21+
},
22+
{
23+
ul: '[list-style-type:circle]',
24+
li: 'ml-8'
25+
},
26+
{
27+
ul: '[list-style-type:square]',
28+
li: 'ml-16'
29+
}
30+
];
31+
</script>
32+
33+
<ul class={clsx('list-inside', levels[level]?.ul)}>
34+
<li class={levels[level]?.li || 'ml-0'}>
35+
<NotionRichText text={data.rich_text} />
36+
37+
{#if block.children && block.children.length}
38+
{#each block.children as child}
39+
<NotionBlock block={child} level={level + 1} />
40+
{/each}
41+
{/if}
42+
</li>
43+
</ul>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script lang="ts">
2+
import NotionRichText from '$lib/notion/blocks/NotionRichText.svelte';
3+
import type { NotionColor, NotionEmoji, NotionRichTextData } from '$lib/notion/notion.types';
4+
5+
export let data: {
6+
rich_text: NotionRichTextData[];
7+
icon: NotionEmoji; // TODO: File support
8+
color: NotionColor; // TODO: Handle
9+
};
10+
</script>
11+
12+
<div class="my-4 rounded-md bg-neutral-700 p-4">
13+
{#if data.icon && data.icon.emoji}
14+
<span class="mr-2">{data.icon.emoji}</span>
15+
{/if}
16+
17+
<NotionRichText text={data.rich_text} />
18+
</div>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script lang="ts">
2+
import { HighlightAuto } from 'svelte-highlight';
3+
import type { RichTextDataText } from '../notion.types';
4+
5+
export let data: {
6+
caption: RichTextDataText[]; // TODO: Implement
7+
rich_text: RichTextDataText[];
8+
language?: string;
9+
};
10+
11+
// Map code
12+
const code = data.rich_text.map((text) => text.plain_text).join('');
13+
</script>
14+
15+
<div class="py-2">
16+
<div class="overflow-clip rounded-lg">
17+
<HighlightAuto {code} />
18+
</div>
19+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script lang="ts">
2+
import type { NotionBlock, NotionColor, NotionRichTextData } from '../notion.types';
3+
import NotionRichText from './NotionRichText.svelte';
4+
5+
export let block: NotionBlock;
6+
export let data: {
7+
rich_text: NotionRichTextData[];
8+
color: NotionColor; // TODO: Handle
9+
is_toggleable: boolean; // TODO: Handle
10+
};
11+
</script>
12+
13+
{#if block.type == 'heading_1'}
14+
<h3 class="my-6 text-4xl font-semibold">
15+
<NotionRichText text={data.rich_text} />
16+
</h3>
17+
{:else if block.type == 'heading_2'}
18+
<h4 class="my-4 text-3xl font-semibold">
19+
<NotionRichText text={data.rich_text} />
20+
</h4>
21+
{:else if block.type == 'heading_3'}
22+
<h5 class="my-3 text-2xl font-semibold">
23+
<NotionRichText text={data.rich_text} />
24+
</h5>
25+
{/if}

0 commit comments

Comments
 (0)