From 9ec5437779c1ac8e808bc472b80d48b025b32930 Mon Sep 17 00:00:00 2001 From: Theodorus Clarence Date: Thu, 20 Jan 2022 14:00:46 +0700 Subject: [PATCH] feat: add icon setting for tree --- src/lib/notion.ts | 8 +++++--- src/pages/index.tsx | 24 ++++++++++++++++++++++-- src/types/notion.ts | 21 +++++++++++++++++++-- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/lib/notion.ts b/src/lib/notion.ts index 0085f09..fb99218 100644 --- a/src/lib/notion.ts +++ b/src/lib/notion.ts @@ -1,6 +1,6 @@ import { Client } from '@notionhq/client'; -import { LinkResult, TreeResult } from '@/types/notion'; +import { LinkResult, PageIcon, TreeResult } from '@/types/notion'; const NOTION_LINK_DATABASE_ID = process.env.NEXT_PUBLIC_NOTION_LINK_DATABASE_ID; const NOTION_TREE_DATABASE_ID = process.env.NEXT_PUBLIC_NOTION_TREE_DATABASE_ID; @@ -133,6 +133,7 @@ export type Tree = { link: string; display: string; order: number; + icon: PageIcon; }; export const getSocialTree = async () => { @@ -149,9 +150,10 @@ export const getSocialTree = async () => { const tree: Tree[] = results .map((result) => ({ id: result.id, - link: result.properties.link.title[0]?.plain_text, - display: result.properties.display.rich_text[0]?.plain_text ?? '', + display: result.properties.display.title[0]?.plain_text, + link: result.properties.link.rich_text[0]?.plain_text ?? '', order: result.properties.order.number, + icon: result.icon, })) .sort((a, b) => a.order - b.order); diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 7c468c0..bcb45b6 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @next/next/no-img-element */ import clsx from 'clsx'; import { InferGetStaticPropsType } from 'next'; import * as React from 'react'; @@ -23,7 +24,7 @@ export default function IndexPage({ Notiolink
- {links.map(({ id, display, link }) => ( + {links.map(({ id, display, link, icon }) => (
+ {icon ? ( + icon.type === 'emoji' ? ( + icon.emoji + ' ' + ) : icon.type === 'external' ? ( + {`${display} + ) : ( + {`${display} + ) + ) : null} {display}
diff --git a/src/types/notion.ts b/src/types/notion.ts index d86849e..79bebd8 100644 --- a/src/types/notion.ts +++ b/src/types/notion.ts @@ -15,16 +15,33 @@ interface LinkProperties { export interface TreeResult { id: string; properties: TreeProperties; + icon: PageIcon; } interface TreeProperties { - link: TitleColumn; - display: TextColumn; + link: TextColumn; + display: TitleColumn; order: NumberColumn; } //#endregion //*======== Social Tree =========== //#region //*=========== Commons =========== +interface ExternalIcon { + type: 'external'; + external: { + url: string; + }; +} +interface EmojiIcon { + type: 'emoji'; + emoji: string; +} +interface FileIcon { + type: 'file'; + file: { url: string }; +} +export type PageIcon = ExternalIcon | EmojiIcon | FileIcon | null; + interface TitleColumn { id: string; type: 'title';