Skip to content

适配 hexo-filter-gitcalendar 插件的数据格式要求#26

Open
abbkirito wants to merge 3 commits intoZfour:masterfrom
abbkirito:master
Open

适配 hexo-filter-gitcalendar 插件的数据格式要求#26
abbkirito wants to merge 3 commits intoZfour:masterfrom
abbkirito:master

Conversation

@abbkirito
Copy link

此 PR 改进了 API,使其完全符合 hexo-filter-gitcalendar 插件期望的数据结构,解决了因格式不匹配导致的渲染错误(如 TypeError 和 [object Object] 显示)。
问题:
原 API 返回扁平的一维贡献数组,而插件要求 53 周 × 7 天的二维数组。当数据不符合这一严格格式时:

插件抛出 TypeError: can't access property "date", git_lastweek[git_thisdayindex] is undefined。

统计信息显示 [object Object] 而非数字。

仅支持少数请求路径(如 /?username),当插件使用其他端点时返回 404 错误。
解决方案
改用稳定的第三方 API(github-contributions-api.jogruber.de/v4)替代直接爬取 GitHub 页面。

将扁平贡献列表转换为 53 周二维数组:

按 7 天分割。

不足 53 周时,在前面插入空周(日期向前推算,count: 0)。

确保最后一周恰好有 7 天,若不足则追加空白天(日期向后推算,count: 0)。

手动计算 total 字段(对扁平数组的 count 求和),确保其为整数(避免 [object Object] 问题)。

支持多种请求风格:

/?username=xxx

/api?username=xxx

/xxx(路径参数)

直接以用户名为查询字符串的无参数名形式(如 ?Sunrisepeak)

添加异常处理和请求超时设置,提升健壮性。

保留 CORS 头(Access-Control-Allow-Origin: *)以允许跨域调用。

@vercel
Copy link

vercel bot commented Feb 20, 2026

@abbkirito is attempting to deploy a commit to the zfour's projects Team on Vercel.

A member of the Team first needs to authorize it.

@abbkirito
Copy link
Author

使用大佬的的插件时发现无论原本还是自定义api, 再结合butterfly主题下的hexo 博客发现 数据无法加载(不知道是版本问题还是其它问题),重写api 发现问题,发现数据的数据匹配问题

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