From 3fcbb8a420a88cd8acac6fdfe2f89281854fe73b Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 3 Nov 2021 15:48:37 +0800 Subject: [PATCH] =?UTF-8?q?feature:=E5=8A=A0=E5=85=A5=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E6=96=87=E7=AB=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/MenuButtonGroup.js | 16 +++++----- components/SideBar.js | 56 +++++++++++++++++++++++++++-------- components/TagList.js | 2 +- layouts/BaseLayout.js | 4 +-- pages/article/[slug].js | 6 ++-- pages/index.js | 2 +- 6 files changed, 60 insertions(+), 26 deletions(-) diff --git a/components/MenuButtonGroup.js b/components/MenuButtonGroup.js index 5a17e9b5..d74ad82f 100644 --- a/components/MenuButtonGroup.js +++ b/components/MenuButtonGroup.js @@ -1,17 +1,19 @@ import React from 'react' import { useLocale } from '@/lib/locale' import Link from 'next/link' +import { useRouter } from 'next/router' const MenuButtonGroup = ({ allowCollapse = false }) => { const locale = useLocale() + const router = useRouter() const links = [ { id: 0, icon: 'fa-home', name: locale.NAV.INDEX, to: '/' || '/', show: true }, - { id: 1, icon: 'fa-info-circle', name: locale.NAV.ABOUT, to: '/article/about', show: true }, - { id: 7, icon: 'fa-github', name: 'Github', to: 'https://github.com/tangly1024', show: true }, - { id: 5, icon: 'fa-weibo', name: '微博', to: 'https://weibo.com/tangly1024', show: true }, - { id: 4, icon: 'fa-envelope', name: locale.NAV.MAIL, to: 'mailto:tlyong1992@hotmail.com', show: true }, - { id: 2, icon: 'fa-rss-square', name: locale.NAV.RSS, to: '/feed', show: true }, - { id: 3, icon: 'fa-compass', name: '发现', to: 'https://search.tangly1024.com/', show: true } + { id: 1, icon: 'fa-info-circle', name: locale.NAV.ABOUT, to: '/article/about', show: true } + // { id: 7, icon: 'fa-github', name: 'Github', to: 'https://github.com/tangly1024', show: true }, + // { id: 5, icon: 'fa-weibo', name: '微博', to: 'https://weibo.com/tangly1024', show: true }, + // { id: 4, icon: 'fa-envelope', name: locale.NAV.MAIL, to: 'mailto:tlyong1992@hotmail.com', show: true } + // { id: 2, icon: 'fa-rss-square', name: locale.NAV.RSS, to: '/feed', show: true }, + // { id: 3, icon: 'fa-compass', name: '发现', to: 'https://search.tangly1024.com/', show: true } // { id: 6, icon: 'fa-map-marker', name: 'Fuzhou', to: '#', show: true }, // { id: 8, icon: 'fa-twitter', name: 'Twitter', to: 'https://twitter.com/troy1024_1', show: true }, // { id: 9, icon: 'fa-telegram', name: 'Telegram', to: 'https://t.me/tangly_1024', show: true } @@ -22,7 +24,7 @@ const MenuButtonGroup = ({ allowCollapse = false }) => { link => link.show && ( - +
diff --git a/components/SideBar.js b/components/SideBar.js index b82ed45e..562525a4 100644 --- a/components/SideBar.js +++ b/components/SideBar.js @@ -2,28 +2,60 @@ import React from 'react' import MenuButtonGroup from '@/components/MenuButtonGroup' import InfoCard from '@/components/InfoCard' import TagList from '@/components/TagList' +import BLOG from '@/blog.config' +import Link from 'next/link' + +const SideBar = ({ tags, currentTag, post, posts }) => { + // 按时间排序 + if (posts) { + posts = posts.sort((a, b) => { + const dateA = new Date(a?.date?.start_date || a.createdTime) + const dateB = new Date(b?.date?.start_date || b.createdTime) + return dateB - dateA + }).slice(0, 5) + } -const SideBar = ({ tags, currentTag, post }) => { return