Open
Conversation
|
@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. |
Author
|
使用大佬的的插件时发现无论原本还是自定义api, 再结合butterfly主题下的hexo 博客发现 数据无法加载(不知道是版本问题还是其它问题),重写api 发现问题,发现数据的数据匹配问题 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
此 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: *)以允许跨域调用。