From a406e0c418036f70a3eb2457aac505cfb064a1e6 Mon Sep 17 00:00:00 2001 From: Duyet Le Date: Fri, 1 Nov 2024 21:45:25 +0700 Subject: [PATCH] chore(blog): update ui, latest post, new flag --- .../_posts/2024/11/clickhouse-rust-udf.md | 5 +- apps/blog/app/page.tsx | 4 + apps/blog/components/latest.tsx | 60 +++++ apps/blog/components/year-post.tsx | 11 +- packages/components/Menu.tsx | 3 +- packages/components/Thumb.tsx | 3 + packages/interfaces/src/post.ts | 7 +- packages/libs/getPost.ts | 221 +++++++++--------- 8 files changed, 198 insertions(+), 116 deletions(-) create mode 100644 apps/blog/components/latest.tsx diff --git a/apps/blog/_posts/2024/11/clickhouse-rust-udf.md b/apps/blog/_posts/2024/11/clickhouse-rust-udf.md index 0c5df4f7..3b99a597 100644 --- a/apps/blog/_posts/2024/11/clickhouse-rust-udf.md +++ b/apps/blog/_posts/2024/11/clickhouse-rust-udf.md @@ -29,7 +29,6 @@ SELECT customTransform(data) FROM raw_events; - [More examples](#more-examples) - [References](#references) - For example, if you are using [dbt](https://www.getdbt.com), it can move and process data from tables to tables without data leaving the cluster. ![ClickHouse UDF dbt](/media/2024/11/udf/clickhouse-rust-udf-dbt.png) @@ -260,7 +259,7 @@ SELECT extractUrl("from https://example.org") as extracted ```sql -- Extract from a table -SELECT +SELECT id, extractUrl(content) as extracted_url FROM raw.events; @@ -269,7 +268,7 @@ FROM raw.events; ```sql -- Extract and insert to another table INSERT INTO dwh.fact_click -SELECT +SELECT id, extractUrl(content) as extracted_url FROM raw.events; diff --git a/apps/blog/app/page.tsx b/apps/blog/app/page.tsx index e3b67948..e26a521b 100644 --- a/apps/blog/app/page.tsx +++ b/apps/blog/app/page.tsx @@ -3,6 +3,7 @@ import Link from 'next/link' import Container from '@duyet/components/Container' import Header from '@duyet/components/Header' import { getPostsByAllYear } from '@duyet/libs/getPost' +import { Latest } from '../components/latest' import { YearPost } from '../components/year-post' export default async function Page() { @@ -19,6 +20,8 @@ export default async function Page() { <>
+ +
Lists all {postCount} posts of the past {pastYears} years of blogging. You can jump straight to the{' '} @@ -31,6 +34,7 @@ export default async function Page() { .
+
{Object.keys(postsByYear) .sort((a: string, b: string) => parseInt(b) - parseInt(a)) diff --git a/apps/blog/components/latest.tsx b/apps/blog/components/latest.tsx new file mode 100644 index 00000000..b776fe42 --- /dev/null +++ b/apps/blog/components/latest.tsx @@ -0,0 +1,60 @@ +import Link from 'next/link' + +import { Thumb } from '@duyet/components/Thumb' +import type { Post } from '@duyet/interfaces' +import { getAllPosts } from '@duyet/libs/getPost' +import { cn } from '@duyet/libs/utils' + +export interface LatestProps { + className?: string +} + +async function getPosts(limit = 3) { + return getAllPosts( + [ + 'date', + 'slug', + 'title', + 'excerpt', + 'thumbnail', + 'category', + 'category_slug', + ], + limit, + ) +} + +export async function Latest({ className }: LatestProps) { + const posts = await getPosts() + + if (!posts.length) { + return null + } + + return ( +
+ {posts.map((post: Post) => ( + +
+ + {post.title} + + {post.thumbnail ? ( + + ) : null} +
+ + ))} +
+ ) +} diff --git a/apps/blog/components/year-post.tsx b/apps/blog/components/year-post.tsx index 677245c3..7bbafbbd 100644 --- a/apps/blog/components/year-post.tsx +++ b/apps/blog/components/year-post.tsx @@ -39,6 +39,7 @@ export function YearPost({ year, className }: YearPostProps) { > {post.title} +