diff --git a/.eslintrc b/.eslintrc index 7fc4818..95f0753 100755 --- a/.eslintrc +++ b/.eslintrc @@ -37,6 +37,7 @@ "unused-imports/no-unused-imports": "error", "simple-import-sort/imports": "error", "simple-import-sort/exports": "error", - "prettier/prettier": 2 + "prettier/prettier": 2, + "tailwindcss/classnames-order": "off" } } diff --git a/.prettierignore b/.prettierignore index d29ade0..e270486 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,5 @@ # Ignore artifacts: build coverage -.eslintrc \ No newline at end of file +.eslintrc +pnpm-lock.yaml \ No newline at end of file diff --git a/.prettierrc b/.prettierrc index eae99c1..f9b5943 100644 --- a/.prettierrc +++ b/.prettierrc @@ -4,6 +4,5 @@ "trailingComma": "all", "bracketSpacing": true, "bracketSameLine": false, - "plugins": ["prettier-plugin-tailwindcss"], - "tailwindFunctions": ["clsx", "tv"] + "plugins": ["prettier-plugin-tailwindcss"] } diff --git a/src/app/watch/dto/watchResource.dto.ts b/src/app/watch/dto/watchResource.dto.ts index 8fea0b5..69603a7 100644 --- a/src/app/watch/dto/watchResource.dto.ts +++ b/src/app/watch/dto/watchResource.dto.ts @@ -1,10 +1,12 @@ +import { WatchResource } from '../types' + export const transformWatchResourceToDTO = (resource: any): WatchResource => { const { id, properties } = resource return { id, title: properties.Name.title?.[0].plain_text, - tldr: properties['tl;dr'].rich_text?.[0]?.plain_text, + tldr: properties['tl;dr'].rich_text, done: properties.Done.checkbox, url: properties.URL.url, type: properties.Type.select.name, diff --git a/src/app/watch/types/index.ts b/src/app/watch/types/index.ts index 29524e2..ad1407c 100644 --- a/src/app/watch/types/index.ts +++ b/src/app/watch/types/index.ts @@ -1,7 +1,9 @@ -type WatchResource = { +import { RichTextPart } from '@/lib/notion' + +export type WatchResource = { id: string title: string - tldr?: string + tldr?: RichTextPart[] done: boolean url: string type: string diff --git a/src/app/watch/watchResource.tsx b/src/app/watch/watchResource.tsx index e6200f0..619be56 100644 --- a/src/app/watch/watchResource.tsx +++ b/src/app/watch/watchResource.tsx @@ -3,6 +3,8 @@ import { tv } from 'tailwind-variants' import Badge from '@/components/badge/Badge' +import type { WatchResource } from './types' + type Props = { resource: WatchResource query?: string @@ -23,6 +25,18 @@ const resourceTldr = tv({ }, }) +const tldr = tv({ + variants: { + code: { + true: 'm-0 whitespace-break-spaces rounded-sm bg-code-light px-1 py-px text-[90%] dark:bg-code', + }, + bold: { true: 'font-bold' }, + italic: { true: 'italic' }, + underline: { true: 'underline' }, + strikethrough: { true: 'line-through' }, + }, +}) + const highlightQuery = (str: string, query: string): ReactNode => { if (!query) return str @@ -64,10 +78,37 @@ const ResourceType: FC<{ type: WatchResource['type'] }> = ({ type }) => { ) } +const Tldr: FC<{ parts: WatchResource['tldr']; query?: string }> = ({ + parts, + query, +}) => { + return ( + + {parts?.map((part, index) => { + const isLast = index + 1 === parts.length + const needsDot = isLast && !part.plain_text.endsWith('.') + return ( + + {query ? highlightQuery(part.plain_text, query) : part.plain_text} + {needsDot && '.'} + + ) + })} + + ) +} + const WatchResource: FC = ({ resource, query, truncate = true }) => { const { title, tldr, source, subSource, url, type } = resource - const trimedTldr = tldr?.trim() - const tldrWithDot = trimedTldr?.endsWith('.') ? trimedTldr : `${trimedTldr}.` return ( = ({ resource, query, truncate = true }) => {
- {query ? highlightQuery(tldrWithDot, query) : tldrWithDot} +
diff --git a/src/lib/notion.ts b/src/lib/notion.ts index c97c7e3..e952f89 100644 --- a/src/lib/notion.ts +++ b/src/lib/notion.ts @@ -50,3 +50,39 @@ export const searchWatchPage = cache((query: string) => { }, }) }) + +type Color = + | 'default' + | 'gray' + | 'brown' + | 'orange' + | 'yellow' + | 'green' + | 'blue' + | 'purple' + | 'pink' + | 'red' + | 'gray_background' + | 'brown_background' + | 'orange_background' + | 'yellow_background' + | 'green_background' + | 'blue_background' + | 'purple_background' + | 'pink_background' + | 'red_background' + +export type RichTextPart = { + type: 'text' + text: { content: string; link: null } + annotations: { + bold: boolean + italic: boolean + strikethrough: boolean + underline: boolean + code: boolean + color: Color + } + plain_text: string + href: string | null +} diff --git a/tailwind.config.ts b/tailwind.config.ts index 3b9b2d8..f2dc63d 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -54,6 +54,10 @@ export default { DEFAULT: '#153040', light: '#ECECEC', }, + code: { + DEFAULT: '#6e768166', + light: '#e4e4e4', + }, }, screens: { sm: '640px',