最新文章组件,按修改时间倒序

This commit is contained in:
tangly1024
2022-04-07 17:00:10 +08:00
parent 7c63f7a5d6
commit cab1c2da68
7 changed files with 44 additions and 49 deletions

View File

@@ -9,14 +9,13 @@ import { useRouter } from 'next/router'
* @param sliceCount 截取展示的数量 默认6
* @constructor
*/
const LatestPostsGroup = ({ posts, siteInfo }) => {
if (!posts) {
const LatestPostsGroup = ({ latestPosts, siteInfo }) => {
if (!latestPosts) {
return <></>
}
// 获取当前路径
const currentPath = useRouter().asPath
const { locale } = useGlobal()
return (
<>
<div className="font-sans mb-2 px-1 flex flex-nowrap justify-between">
@@ -25,7 +24,7 @@ const LatestPostsGroup = ({ posts, siteInfo }) => {
{locale.COMMON.LATEST_POSTS}
</div>
</div>
{posts.map(post => {
{latestPosts.map(post => {
const selected = currentPath === `${BLOG.SUB_PATH}/article/${post.slug}`
const headerImage = post?.page_cover
? `url("${post.page_cover}")`
@@ -52,7 +51,7 @@ const LatestPostsGroup = ({ posts, siteInfo }) => {
>
<div>
<div style={{ WebkitLineClamp: 2 }}>{post.title}</div>
<div className="text-gray-500">{post.date?.start_date}</div>
<div className="text-gray-500">{post.lastEditedTime}</div>
</div>
</div>
</a>

View File

@@ -6,7 +6,7 @@ import Catalog from './Catalog'
import { InfoCard } from './InfoCard'
import { AnalyticsCard } from './AnalyticsCard'
import CONFIG_HEXO from '../config_hexo'
export default function SideRight (props) {
export default function SideRight(props) {
const {
post, currentCategory, categories, latestPosts, tags,
currentTag, showCategory, showTag, slot
@@ -14,13 +14,13 @@ export default function SideRight (props) {
return (
<div className={'lg:w-80 px-2 space-y-4 pt-4 lg:pt-0'}>
<InfoCard {...props}/>
{ CONFIG_HEXO.WIDGET_ANALYTICS && <AnalyticsCard {...props}/>}
<InfoCard {...props} />
{CONFIG_HEXO.WIDGET_ANALYTICS && <AnalyticsCard {...props} />}
{showCategory && (
<Card>
<div className='ml-2 mb-1 font-sans'>
<i className='fas fa-th'/> 分类
<i className='fas fa-th' /> 分类
</div>
<CategoryGroup
currentCategory={currentCategory}
@@ -34,11 +34,11 @@ export default function SideRight (props) {
</Card>
)}
{CONFIG_HEXO.WIDGET_LATEST_POSTS && latestPosts && latestPosts.length > 0 && <Card>
<LatestPostsGroup posts={latestPosts} {...props} />
<LatestPostsGroup {...props} />
</Card>}
<div className='sticky top-20'>
{post && post.toc && <Card>
{post && post.toc && <Card>
<Catalog toc={post.toc} />
</Card>}
{slot}