Created
February 24, 2025 08:41
-
-
Save hongjr03/70c1a0e2624dd66db6d13294faa3e7ff to your computer and use it in GitHub Desktop.
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
| // 替换 USERNAME 为你的 GitHub 用户名,将结果放在 contribution.json 文件中 | |
| // 然后运行这个文件,生成的图片就是你的 GitHub 贡献图 | |
| // https://github-contributions-api.jogruber.de/v4/USERNAME | |
| #set page(width: auto, height: auto) | |
| #{ | |
| let contribution-json = json("contribution.json") | |
| .contributions | |
| .map(ct => { | |
| let ( | |
| year, | |
| month, | |
| day, | |
| ) = ct.date.split("-").map(x => int(x)) | |
| let date = datetime( | |
| year: year, | |
| month: month, | |
| day: day, | |
| ) | |
| ( | |
| date: date, | |
| count: ct.count, | |
| level: ct.level, | |
| ) | |
| }) | |
| .filter(ct => ct.date <= datetime.today()) | |
| .sorted(key: it => it.date) | |
| // .rev() | |
| contribution-json = ( | |
| if contribution-json.first().date.weekday() != 0 { | |
| range(contribution-json.first().date.weekday()).map(x => ( | |
| date: contribution-json.first().date - duration(days: x), | |
| count: none, | |
| level: none, | |
| )) | |
| } | |
| + contribution-json | |
| + if datetime.today().weekday() != 6 { | |
| range(6 - datetime.today().weekday()).map(x => ( | |
| date: datetime.today() + duration(days: x + 1), | |
| count: none, | |
| level: none, | |
| )) | |
| } | |
| ).chunks(7) | |
| set table(stroke: none, inset: 0pt) | |
| table( | |
| columns: (auto,) + (2em,) * contribution-json.len(), | |
| align: top, | |
| rows: (2em, auto), | |
| stroke: none, | |
| // datetime header | |
| [], | |
| ..{ | |
| range(contribution-json.len()).map(x => if calc.rem(x, 3) == 0 { | |
| rotate(-45deg)[#contribution-json.at(x).first().date.display()] | |
| } else { | |
| [] | |
| }) | |
| }, | |
| table( | |
| rows: (2em,) * 7, | |
| columns: auto, | |
| align: right, | |
| inset: 1em, | |
| stroke: none, | |
| [Mon], | |
| [Tue], | |
| [Wed], | |
| [Thu], | |
| [Fri], | |
| [Sat], | |
| [Sun], | |
| ), | |
| ..contribution-json.map(ct => { | |
| table( | |
| rows: (2em,) * 7, | |
| columns: 2em, | |
| ..ct.map(ct => { | |
| if ct.level == none { table.cell(stroke: none)[] } else { | |
| table.cell(fill: green.lighten(30%).darken(ct.level / 4 * 100%))[] | |
| } | |
| }) | |
| ) | |
| }) | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment