Skip to content

Commit

Permalink
feat: ✨ add divider component
Browse files Browse the repository at this point in the history
  • Loading branch information
peelar committed Feb 25, 2023
1 parent a75d233 commit 22c42b2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/fixtures/notion-renderer/astro/blog-post.astro
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ const blocks = Astro.props.blocks;
// * problem: when I get images from Notion, there is no width & height
return <img src={block.url} alt={block.caption} />;
}

if (block.type === "divider") {
return <hr />;
}
})
}
</article>
17 changes: 15 additions & 2 deletions src/fixtures/notion-renderer/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ type Image = {
caption: string;
};

type Divider = {
type: "divider";
};

export type Block =
| Paragraph
| Heading
Expand All @@ -72,14 +76,16 @@ export type Block =
| TodoListItem
| TodoList
| Quote
| Image;
| Image
| Divider;

export const getBlockStyleProps = (block: Block): StyleProps | undefined => {
if (
block.type !== "unorderedList" &&
block.type !== "orderedList" &&
block.type !== "todoList" &&
block.type !== "image"
block.type !== "image" &&
block.type !== "divider"
) {
return block.style;
}
Expand Down Expand Up @@ -164,6 +170,12 @@ const imageFactory = (url: string, caption: string): Image => {
};
};

const dividerFactory = (): Divider => {
return {
type: "divider",
};
};

const factory = {
paragraph: paragraphFactory,
heading1: (text: string, style: StyleProps) => headingFactory(1, text, style),
Expand All @@ -177,6 +189,7 @@ const factory = {
todoList: todoListFactory,
quote: quoteFactory,
image: imageFactory,
divider: dividerFactory,
};

export default factory;
9 changes: 4 additions & 5 deletions src/fixtures/notion-renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,16 @@ export const mapNotionBlocks = (

case "image": {
const b = block.image;

if (!b) {
return prev;
}

const url = b.type === "external" ? b.external.url : b.file.url;
const caption = b.caption?.[0]?.plain_text;

return [...prev, factory.image(url, caption)];
}

case "divider": {
return [...prev, factory.divider()];
}

default: {
notionRendererLogger.error({ block }, "Unsupported block type");
throw new Error("Unsupported block type");
Expand Down
3 changes: 2 additions & 1 deletion todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [x] - image
- [x] - todolist
- [x] - numbered list
- [x] - quote
- [x] - divider
- [ ] - code
- [ ] - toggle list
- [ ] - quote

0 comments on commit 22c42b2

Please sign in to comment.