From ffc29d8bc54d8781d63c8a03488e4894d11be2f4 Mon Sep 17 00:00:00 2001 From: Lumither Tao Date: Fri, 16 Aug 2024 23:10:59 +0800 Subject: [PATCH] feat(global) several major updates: - delete page `tag`, `archive` - add page `friends` - implement page `about` *partially* --- backend/src/api/post/refresh.rs | 9 ++- frontend/app/about/layout.tsx | 15 ++++ frontend/app/about/me/page.tsx | 15 ++++ frontend/app/about/page.tsx | 57 +++++++++++-- frontend/app/about/website/page.tsx | 14 ++++ frontend/app/archive/page.tsx | 12 --- frontend/app/blog/layout.tsx | 5 +- frontend/app/blog/post/[id]/ButtonGoBack.tsx | 21 +++++ frontend/app/blog/post/[id]/PostCard.tsx | 59 ++------------ frontend/app/blog/post/[id]/page.tsx | 4 + frontend/app/fetch.ts | 17 ++++ frontend/app/friends/layout.tsx | 15 ++++ frontend/app/friends/page.tsx | 85 ++++++++++++++++++++ frontend/app/page.tsx | 8 +- frontend/app/public/MarkdownRenderer.tsx | 64 +++++++++++++++ frontend/app/public/css/article.css | 0 frontend/app/tags/page.tsx | 12 --- frontend/components/Navbar.tsx | 24 ++---- 18 files changed, 323 insertions(+), 113 deletions(-) create mode 100644 frontend/app/about/layout.tsx create mode 100644 frontend/app/about/me/page.tsx create mode 100644 frontend/app/about/website/page.tsx delete mode 100644 frontend/app/archive/page.tsx create mode 100644 frontend/app/blog/post/[id]/ButtonGoBack.tsx create mode 100644 frontend/app/fetch.ts create mode 100644 frontend/app/friends/layout.tsx create mode 100644 frontend/app/friends/page.tsx create mode 100644 frontend/app/public/MarkdownRenderer.tsx create mode 100644 frontend/app/public/css/article.css delete mode 100644 frontend/app/tags/page.tsx diff --git a/backend/src/api/post/refresh.rs b/backend/src/api/post/refresh.rs index dae22f7..65d7be3 100644 --- a/backend/src/api/post/refresh.rs +++ b/backend/src/api/post/refresh.rs @@ -1,6 +1,6 @@ -use std::{env, fs}; use std::path::Path; use std::str::FromStr; +use std::{env, fs}; use axum::extract::{Query, State}; use axum::http::StatusCode; @@ -9,7 +9,7 @@ use futures::{stream, StreamExt}; use serde::Deserialize; use serde_json::{json, Map, Value}; use sha2::{Digest, Sha256}; -use sqlx::{PgPool, query}; +use sqlx::{query, PgPool}; use tracing::error; use uuid::Uuid; @@ -42,6 +42,7 @@ pub async fn refresh( )); } }; + let post_dir = Path::new(&data_repo_dir).join("posts"); if is_force_refresh { if let Err(e) = query("DROP TABLE IF EXISTS hash, meta, post, tag;") @@ -60,9 +61,9 @@ pub async fn refresh( } // generate post idx - let md_path = search_md(Path::new(&data_repo_dir)); + let post_path = search_md(&post_dir); - let post_list_with_hash: Vec<(Map<_, _>, Vec<_>)> = md_path + let post_list_with_hash: Vec<(Map<_, _>, Vec<_>)> = post_path .into_iter() .filter_map(|post_path| match post::from_path(&post_path) { Ok(post) => match fs::read(&post_path) { diff --git a/frontend/app/about/layout.tsx b/frontend/app/about/layout.tsx new file mode 100644 index 0000000..ccc425b --- /dev/null +++ b/frontend/app/about/layout.tsx @@ -0,0 +1,15 @@ +import React from 'react'; + +function Layout({ + children +}: { + children: React.ReactNode; +}) { + return ( +
+ { children } +
+ ); +} + +export default Layout; diff --git a/frontend/app/about/me/page.tsx b/frontend/app/about/me/page.tsx new file mode 100644 index 0000000..86cccf5 --- /dev/null +++ b/frontend/app/about/me/page.tsx @@ -0,0 +1,15 @@ +import React from 'react'; +import MarkdownRenderer from '@/app/public/MarkdownRenderer'; +import { fetchText } from '@/app/fetch'; + +const Me = async () => { + return ( +
+ + { await fetchText('https://raw.githubusercontent.com/lumither/blog-posts/master/about/me.md') } + +
+ ); +}; + +export default Me; diff --git a/frontend/app/about/page.tsx b/frontend/app/about/page.tsx index 84fb7c4..272823d 100644 --- a/frontend/app/about/page.tsx +++ b/frontend/app/about/page.tsx @@ -1,13 +1,58 @@ +import { Card } from '@nextui-org/react'; import React from 'react'; -import ConstructionPlaceHolder from '@/components/ConstructionPlaceHolder'; +import { CardBody } from '@nextui-org/card'; +import Link from 'next/link'; -function About() { +const About = () => { return ( -
- +
+
+
+

{ '讷,远道而来的' }旅人 +

+

{ '愿意坐下来听个故事吗...' }

+

{ '一个关于一位' }{ '█' }{ '追寻' }{ '█' }{ ',探索' }{ '█' }{ '的故事' } +

+
+
+
+
+ + +
+

关于我

+
+
+
+ + +
+

关于这个网站

+
+
+
+
+
+

*目前还没想到如何设计这一页,先摸鱼会(笑)

- ); -} +}; export default About; diff --git a/frontend/app/about/website/page.tsx b/frontend/app/about/website/page.tsx new file mode 100644 index 0000000..0fc5d5a --- /dev/null +++ b/frontend/app/about/website/page.tsx @@ -0,0 +1,14 @@ +import React from 'react'; +import MarkdownRenderer from '@/app/public/MarkdownRenderer'; +import { fetchText } from '@/app/fetch'; + +const Website = async () => { + return ( +
+ + { await fetchText('https://raw.githubusercontent.com/lumither/blog-posts/master/about/website.md') } + +
+ ); +}; +export default Website; diff --git a/frontend/app/archive/page.tsx b/frontend/app/archive/page.tsx deleted file mode 100644 index 9991bdd..0000000 --- a/frontend/app/archive/page.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import React from 'react'; -import ConstructionPlaceHolder from '@/components/ConstructionPlaceHolder'; - -const Archive = () => { - return ( -
- -
- ); -}; - -export default Archive; diff --git a/frontend/app/blog/layout.tsx b/frontend/app/blog/layout.tsx index 058d39a..2c3ea28 100644 --- a/frontend/app/blog/layout.tsx +++ b/frontend/app/blog/layout.tsx @@ -6,9 +6,10 @@ function Layout({ children: React.ReactNode; }) { return ( - //
- { children } +
+ { children } +
); } diff --git a/frontend/app/blog/post/[id]/ButtonGoBack.tsx b/frontend/app/blog/post/[id]/ButtonGoBack.tsx new file mode 100644 index 0000000..924e2f8 --- /dev/null +++ b/frontend/app/blog/post/[id]/ButtonGoBack.tsx @@ -0,0 +1,21 @@ +'use client'; + +import React from 'react'; +import { useRouter } from 'next/navigation'; +import { Button } from '@nextui-org/react'; +import { IoArrowBackOutline } from 'react-icons/io5'; + +const ButtonGoBack = () => { + const router = useRouter(); + + return ( + + ); +}; +export default ButtonGoBack; diff --git a/frontend/app/blog/post/[id]/PostCard.tsx b/frontend/app/blog/post/[id]/PostCard.tsx index 817c28e..056f3d1 100644 --- a/frontend/app/blog/post/[id]/PostCard.tsx +++ b/frontend/app/blog/post/[id]/PostCard.tsx @@ -1,16 +1,9 @@ import React from 'react'; -import Markdown from 'react-markdown'; import { Card, CardBody } from '@nextui-org/card'; -import remarkGfm from 'remark-gfm'; -import remarkToc from 'remark-toc'; -import remarkFrontmatter from 'remark-frontmatter'; -import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; -import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism'; -import rehypeRaw from 'rehype-raw'; -import rehypeSanitize from 'rehype-sanitize'; import Headers from '@/app/blog/post/[id]/Headers'; import Footer from '@/app/blog/post/[id]/Footer'; import { fetchNocturneApi } from '@/app/blog/api'; +import MarkdownRenderer from '@/app/public/MarkdownRenderer'; type Props = { id: string @@ -31,55 +24,15 @@ async function PostCard(props: Props) { {/* card body */ } - - - { - String((children as any)['props']['children']).replace(/\n$/, '') - } - - - ); - } else { - return ( -
-                                            
-                                                { children }
-                                            
-                                        
- ); - } - } - } } - >{ ret['content'] }
+
+ + { ret['content'] } + +
{/* card footer */ } -