Skip to content

Conversation

@6uu1
Copy link

@6uu1 6uu1 commented Aug 13, 2025

已知问题

  1. NEXT 主题无法通过标签实现文章置顶,用户无法灵活调整置顶文章。

解决方案

  1. 新增 sortPostsByTopTag 工具方法,支持按指定标签(如 top)将文章置顶。
  2. 在首页、分类、标签、搜索等页面,若当前主题为 next 且设置了置顶标签,则自动将带有该标签的文章排在前面。
  3. themes/next/config.js 增加 NEXT_TOP_TAG 配置项,支持自定义置顶标签名。

改动收益

  1. 主题用户可通过标签灵活置顶任意文章,无需手动排序。
  2. 兼容原有排序逻辑,未设置置顶标签时不影响现有功能。
  3. 仅影响 next 主题,其他主题不受影响。

具体改动

  1. lib/utils/post.js
    • 新增 sortPostsByTopTag 方法。
  2. themes/next/config.js
    • 新增 NEXT_TOP_TAG 配置项,默认值为 'top'
  3. pages/index.jspages/page/[page].jspages/category/[category]/index.jspages/category/[category]/page/[page].jspages/tag/[tag]/index.jspages/tag/[tag]/page/[page].jspages/search/index.jspages/search/[keyword]/index.jspages/search/[keyword]/page/[page].js
    • 在获取文章列表后,按置顶标签重排。

测试确认

  • 本地开发环境测试通过
  • 生产环境构建测试通过
  • 置顶标签配置后,文章正确置顶
  • 未配置置顶标签时,排序不受影响

@vercel
Copy link

vercel bot commented Aug 13, 2025

Someone is attempting to deploy a commit to the tangly1024's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant