From c764a3a26f98a9e21091468869cf8a8481bd8aa9 Mon Sep 17 00:00:00 2001 From: sunface Date: Fri, 5 Mar 2021 18:00:00 +0800 Subject: [PATCH] update --- layouts/nav/nav.tsx | 29 ++++++------ layouts/nav/post-nav.tsx | 69 ++++++++++------------------- layouts/nav/vertical-nav.tsx | 42 ++++++------------ layouts/sidebar/sidebar-link.tsx | 6 +-- layouts/sidebar/sidebar.tsx | 2 +- next-redirect.js | 4 +- pages/[username]/[post_id].tsx | 2 +- pages/[username]/index.tsx | 6 +-- pages/bookmarks.tsx | 2 +- pages/courses.tsx | 24 ---------- pages/search/[type].tsx | 42 ++++++++++++++++++ pages/settings/profile.tsx | 6 +-- pages/tags/index.tsx | 2 +- server/pkg/common/reserve_urls.go | 14 +++++- src/components/comments/comment.tsx | 2 +- src/components/comments/reply.tsx | 2 +- src/components/logo.tsx | 38 +++++++++------- src/components/svg-icon.tsx | 6 +++ src/data/links.tsx | 47 ++++++++++++++++++-- src/data/reserve-urls.ts | 1 + theme.ts | 15 +++++++ 21 files changed, 212 insertions(+), 149 deletions(-) delete mode 100644 pages/courses.tsx create mode 100644 pages/search/[type].tsx diff --git a/layouts/nav/nav.tsx b/layouts/nav/nav.tsx index 070100d7..454fef10 100644 --- a/layouts/nav/nav.tsx +++ b/layouts/nav/nav.tsx @@ -21,20 +21,8 @@ import { ReserveUrls } from "src/data/reserve-urls" import Link from "next/link" import DarkMode from "components/dark-mode" import AccountMenu from "components/user-menu" - -const navLinks = [{ - title: '主页', - url: '/', -}, -{ - title: '标签', - url: ReserveUrls.Tags, -}, -{ - title: '学习资料', - url: ReserveUrls.Courses, -}, -] +import { navLinks } from "src/data/links" +import { getSvgIcon } from "components/svg-icon" function HeaderContent() { @@ -75,6 +63,7 @@ function HeaderContent() { maxW="600px" align="center" color={useColorModeValue("gray.500", "gray.400")} + spacing="1" > {/* */} } /> + + + {/* { @@ -48,59 +53,33 @@ function PostNav(props:Props) { > - - Sunface的博客 - {followed !== null && } - + - alert('search in this blog')} - icon={} - aria-label="search in this blog" - /> + + + + + - - Home - Badges - - - - } - /> - } - /> - + {post.creator.nickname}的博客 + {followed !== null && } diff --git a/layouts/nav/vertical-nav.tsx b/layouts/nav/vertical-nav.tsx index a540fe28..71f8797a 100644 --- a/layouts/nav/vertical-nav.tsx +++ b/layouts/nav/vertical-nav.tsx @@ -25,24 +25,9 @@ import { import DarkMode from "components/dark-mode" import AccountMenu from "components/user-menu" import { getSvgIcon } from "components/svg-icon" +import { navLinks } from "src/data/links" - const navLinks = [{ - title: '主页', - url: '/', - icon: getSvgIcon("home","1.4rem") - }, - { - title: '标签', - url: ReserveUrls.Tags, - icon: getSvgIcon("tags","1.2rem") - }, - { - title: '学习资料', - url: ReserveUrls.Courses, - icon: getSvgIcon("explore","1.4rem") - }, - ] - + function HeaderContent() { const router = useRouter() @@ -55,7 +40,15 @@ import { getSvgIcon } from "components/svg-icon" useUpdateEffect(() => { mobileNavBtnRef.current?.focus() }, [mobileNav.isOpen]) - + + const isActive = url => { + if (url === '/') { + return asPath === url + } + + console.log(asPath,url) + return asPath.startsWith(url) + } return ( <> @@ -70,8 +63,8 @@ import { getSvgIcon } from "components/svg-icon" {navLinks.map(link => - - {link.icon}{link.title} + + {link.icon}{link.title} )} @@ -83,15 +76,6 @@ import { getSvgIcon } from "components/svg-icon" align="center" color={useColorModeValue("gray.500", "gray.400")} > - } - /> - {icon} {children} + >{icon} {children} ) }) @@ -40,8 +40,8 @@ type SidebarLinkProps = PropsOf & { const SidebarLink = (props: SidebarLinkProps) => { const { href, icon, children, ...rest } = props - const { pathname } = useRouter() - const isActive = pathname === href + const { asPath } = useRouter() + const isActive = asPath.indexOf(href) > -1 return ( { return ( - {title} + {title} { - {post.title} + {post.title} diff --git a/pages/[username]/index.tsx b/pages/[username]/index.tsx index f7eb62a0..0f687ede 100644 --- a/pages/[username]/index.tsx +++ b/pages/[username]/index.tsx @@ -92,7 +92,7 @@ const UserPage = () => { - {user.nickname} + {user.nickname} {user.tagline && {user.tagline}} Followers @@ -141,7 +141,7 @@ const UserPage = () => { } {user.rawSkills.length > 0 && - 擅长技能 + 擅长技能 { user.rawSkills.map(skill => @@ -156,7 +156,7 @@ const UserPage = () => { } {tags.length > 0 && - 博客标签 + 博客标签 { tags.map(tag => diff --git a/pages/bookmarks.tsx b/pages/bookmarks.tsx index 084ac082..5d0e31f1 100644 --- a/pages/bookmarks.tsx +++ b/pages/bookmarks.tsx @@ -89,7 +89,7 @@ import Empty from "components/empty" - Bookmarks + Bookmarks All the discussions, stories and comments you have bookmarked on {config.appName}. diff --git a/pages/courses.tsx b/pages/courses.tsx deleted file mode 100644 index 2b21f684..00000000 --- a/pages/courses.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { chakra } from "@chakra-ui/react" -import Container from "components/container" -import SEO from "components/seo" -import siteConfig from "configs/site-config" -import Nav from "layouts/nav/nav" -import PageContainer from "layouts/page-container" -import React from "react" - -const CoursesPage = () => ( - <> - -