diff --git a/components/BlogPostCard.js b/components/BlogPostCard.js index ae49f8d0..4be89176 100644 --- a/components/BlogPostCard.js +++ b/components/BlogPostCard.js @@ -26,7 +26,7 @@ const BlogPostCard = ({ post, tags }) => {
+ className='cursor-pointer dark:text-gray-200 text-gray-500 text-sm py-1.5 mr-1 hover:underline hover:scale-105 transform duration-200'> {post.category}
diff --git a/components/CategoryGroup.js b/components/CategoryGroup.js index 0b20eddc..8ce7f074 100644 --- a/components/CategoryGroup.js +++ b/components/CategoryGroup.js @@ -5,8 +5,9 @@ const CategoryGroup = ({ currentCategory, categories }) => { return
{Object.keys(categories).map(category => { + const selected = currentCategory === category return -
{category}({categories[category]})
+
{category}({categories[category]})
})}
diff --git a/components/LatestPosts.js b/components/LatestPostsGroup.js similarity index 52% rename from components/LatestPosts.js rename to components/LatestPostsGroup.js index ac8e94b9..c52b2fdd 100644 --- a/components/LatestPosts.js +++ b/components/LatestPostsGroup.js @@ -6,10 +6,11 @@ import { useGlobal } from '@/lib/global' /** * 最新文章列表 - * @param posts + * @param posts 所有文章数据 + * @param sliceCount 截取展示的数量 默认6 * @constructor */ -const LatestPosts = ({ posts }) => { +const LatestPostsGroup = ({ posts, sliceCount = 6 }) => { // 深拷贝 let postsSortByDate = Object.create(posts) @@ -21,28 +22,26 @@ const LatestPosts = ({ posts }) => { }) // 只取前五 - postsSortByDate = postsSortByDate.slice(0, 5) + postsSortByDate = postsSortByDate.slice(0, sliceCount) // 获取当前路径 const currentPath = useRouter().asPath - const { locale } = useGlobal() - return <> -
-
{locale.COMMON.LATEST_POSTS}
-
-
+ return
{postsSortByDate.map(post => { + const selected = currentPath === `${BLOG.path}/article/${post.slug}` return (
-
- {formatDateFmt(post.lastEditedTime, 'yyyy/MM/dd')} + className={(selected ? 'bg-gray-200 dark:bg-black ' : '') + ' text-xs leading-5 py-1.5 px-5 flex'}> +
+ {formatDateFmt(post.lastEditedTime, 'MM/dd')}
+ className={ + (selected ? 'dark:text-white text-black ' : 'text-gray-500 ') + + ' text-sm flex w-50 overflow-x-hidden whitespace-nowrap hover:text-black dark:hover:text-white cursor-pointer hover:underline' + }> {post.title}
@@ -50,6 +49,5 @@ const LatestPosts = ({ posts }) => { ) })}
- } -export default LatestPosts +export default LatestPostsGroup diff --git a/components/MenuButtonGroup.js b/components/MenuButtonGroup.js index d4b34c5d..07345f7e 100644 --- a/components/MenuButtonGroup.js +++ b/components/MenuButtonGroup.js @@ -19,20 +19,22 @@ const MenuButtonGroup = ({ allowCollapse = false }) => { // { id: 9, icon: 'fa-telegram', name: 'Telegram', to: 'https://t.me/tangly_1024', show: true } ] return } diff --git a/components/SearchInput.js b/components/SearchInput.js index c9462b59..22a27e69 100644 --- a/components/SearchInput.js +++ b/components/SearchInput.js @@ -47,9 +47,9 @@ const SearchInput = ({ currentTag, currentSearch }) => { /> { (searchKey && searchKey.length && )} -
{ handleSearch(searchKey) }}> - +
} diff --git a/components/SideBar.js b/components/SideBar.js index 78885bcb..6da41cd2 100644 --- a/components/SideBar.js +++ b/components/SideBar.js @@ -2,7 +2,7 @@ import React from 'react' import MenuButtonGroup from '@/components/MenuButtonGroup' import InfoCard from '@/components/InfoCard' import TagGroups from '@/components/TagGroups' -import LatestPosts from '@/components/LatestPosts' +import LatestPostsGroup from '@/components/LatestPostsGroup' import CategoryGroup from '@/components/CategoryGroup' import Toc from '@/components/Toc' import SearchInput from '@/components/SearchInput' @@ -44,29 +44,32 @@ const SideBar = ({ tags, currentTag, post, posts, categories, currentCategory, c {/* 分类 */} {categories && (
-
-
{locale.COMMON.CATEGORY}
-
+
+
{locale.COMMON.CATEGORY}
+
{locale.COMMON.MORE} 》
+
)} {/* 最新文章 */} {posts && ( -
- +
+
+
{locale.COMMON.LATEST_POSTS}
+
{locale.COMMON.MORE} 》
+
+
)} {/* 标签云 */} {tags && ( -
-
-
{locale.COMMON.TAGS}
-
{locale.COMMON.MORE}
-
+
+
+
{locale.COMMON.TAGS}
+
{locale.COMMON.MORE} 》
+
diff --git a/pages/blogs/index.js b/pages/blogs/index.js new file mode 100644 index 00000000..0fbbc5f5 --- /dev/null +++ b/pages/blogs/index.js @@ -0,0 +1,57 @@ +import { getAllCategories, getAllPosts, getAllTags } from '@/lib/notion' +import BLOG from '@/blog.config' +import BaseLayout from '@/layouts/BaseLayout' +import BlogPostListScroll from '@/components/BlogPostListScroll' +import { getNotionPageData } from '@/lib/notion/getNotionData' +import StickyBar from '@/components/StickyBar' +import React from 'react' +import { useGlobal } from '@/lib/global' + +export async function getStaticProps () { + const from = 'index' + const notionPageData = await getNotionPageData({ from }) + const allPosts = await getAllPosts({ notionPageData, from }) + const categories = await getAllCategories(allPosts) + const tagOptions = notionPageData.tagOptions + const tags = await getAllTags({ allPosts, tagOptions }) + return { + props: { + allPosts, + tags, + categories + }, + revalidate: 1 + } +} + +const Index = ({ allPosts, tags, categories }) => { + const { locale } = useGlobal() + // 深拷贝 + const postsSortByDate = Object.create(allPosts) + + // 时间排序 + postsSortByDate.sort((a, b) => { + const dateA = new Date(a?.lastEditedTime || a.createdTime) + const dateB = new Date(b?.lastEditedTime || b.createdTime) + return dateB - dateA + }) + + const meta = { + title: `${BLOG.title} | ${locale.COMMON.LATEST_POSTS} `, + description: BLOG.description, + type: 'website' + } + + return ( + +
+ +
{locale.COMMON.LATEST_POSTS}
+
+ +
+
+ ) +} + +export default Index diff --git a/pages/category/[category].js b/pages/category/[category].js index ce29dfc2..2354ca21 100644 --- a/pages/category/[category].js +++ b/pages/category/[category].js @@ -15,7 +15,7 @@ export default function Category ({ tags, allPosts, filteredPosts, category, cat } return
- + diff --git a/pages/category/index.js b/pages/category/index.js new file mode 100644 index 00000000..3dc6c443 --- /dev/null +++ b/pages/category/index.js @@ -0,0 +1,48 @@ +import { getAllCategories, getAllPosts, getAllTags } from '@/lib/notion' +import BLOG from '@/blog.config' +import BaseLayout from '@/layouts/BaseLayout' +import TagItem from '@/components/TagItem' +import { getNotionPageData } from '@/lib/notion/getNotionData' +import { useGlobal } from '@/lib/global' +import CategoryGroup from '@/components/CategoryGroup' +import React from 'react' +import Link from 'next/link' + +export default function Category ({ tags, allPosts, categories }) { + const { locale } = useGlobal() + const meta = { + title: `${BLOG.title} | ${locale.COMMON.CATEGORY}`, + description: BLOG.description, + type: 'website' + } + return +
+
+
{locale.COMMON.TAGS}:
+
+ {Object.keys(categories).map(category => { + return +
{category}({categories[category]})
+ + })}
+
+
+
+} + +export async function getStaticProps () { + const from = 'tag-index-props' + const notionPageData = await getNotionPageData({ from }) + const allPosts = await getAllPosts({ notionPageData, from }) + const categories = await getAllCategories(allPosts) + const tagOptions = notionPageData.tagOptions + const tags = await getAllTags({ allPosts, sliceCount: 12, tagOptions }) + return { + props: { + tags, + allPosts, + categories + }, + revalidate: 1 + } +} diff --git a/pages/tag/index.js b/pages/tag/index.js index 4b19f810..d400adde 100644 --- a/pages/tag/index.js +++ b/pages/tag/index.js @@ -6,16 +6,16 @@ import { getNotionPageData } from '@/lib/notion/getNotionData' import { useGlobal } from '@/lib/global' export default function Tag ({ tags, allPosts, categories }) { + const { locale } = useGlobal() const meta = { - title: `${BLOG.title} | 标签`, + title: `${BLOG.title} | ${locale.COMMON.TAGS}`, description: BLOG.description, type: 'website' } - const { locale } = useGlobal() return -
-
-
{locale.COMMON.TAGS}:
+
+
+
{locale.COMMON.TAGS}:
{ tags.map(tag => {