NotionNext
NotionNext copied to clipboard
feat(next): 支持通过标签置顶文章(NEXT主题)
已知问题
- NEXT 主题无法通过标签实现文章置顶,用户无法灵活调整置顶文章。
解决方案
- 新增
sortPostsByTopTag工具方法,支持按指定标签(如top)将文章置顶。 - 在首页、分类、标签、搜索等页面,若当前主题为 next 且设置了置顶标签,则自动将带有该标签的文章排在前面。
- 在
themes/next/config.js增加NEXT_TOP_TAG配置项,支持自定义置顶标签名。
改动收益
- 主题用户可通过标签灵活置顶任意文章,无需手动排序。
- 兼容原有排序逻辑,未设置置顶标签时不影响现有功能。
- 仅影响 next 主题,其他主题不受影响。
具体改动
lib/utils/post.js- 新增
sortPostsByTopTag方法。
- 新增
themes/next/config.js- 新增
NEXT_TOP_TAG配置项,默认值为'top'。
- 新增
pages/index.js、pages/page/[page].js、pages/category/[category]/index.js、pages/category/[category]/page/[page].js、pages/tag/[tag]/index.js、pages/tag/[tag]/page/[page].js、pages/search/index.js、pages/search/[keyword]/index.js、pages/search/[keyword]/page/[page].js- 在获取文章列表后,按置顶标签重排。
测试确认
- [x] 本地开发环境测试通过
- [x] 生产环境构建测试通过
- [x] 置顶标签配置后,文章正确置顶
- [x] 未配置置顶标签时,排序不受影响
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.