|
1 | 1 | {% macro info(item, section, archived=false) %}
|
2 | 2 |
|
| 3 | +{% set github_token = get_env(name="GITHUB_TOKEN") %} |
| 4 | + |
3 | 5 | {% if item.name %}
|
4 | 6 | {% set name = item.name %}
|
5 | 7 | {% endif %}
|
6 | 8 |
|
7 |
| -{% if item.source %} |
8 |
| - {% if item.source == 'crates' %} |
9 |
| - {% set data = load_data(url = "https://crates.io/api/v1/crates/" ~ item.name ~ "?include=", format="json", headers=["User-Agent=arewegameyet ( [email protected])"]) %} |
10 |
| - {# human readable name #} |
11 |
| - {% set name = data.crate.name %} |
12 |
| - {# Github/Gitlab/Etc. repository #} |
13 |
| - {% set repository_url = data.crate.repository %} |
14 |
| - {% set crate_url = 'https://crates.io/crates/' ~ name %} |
15 |
| - {% set description = data.crate.description %} |
16 |
| - {% if data.crate.homepage %} |
17 |
| - {% set homepage_url = data.crate.homepage %} |
18 |
| - {% endif %} |
19 |
| - {% elif item.source == 'github' %} |
20 |
| - {% set data = load_data(url="https://api.github.com/repos/" ~ item.name, format="json") %} |
21 |
| - {% set name = data.name %} |
22 |
| - {% set repository_url = data.html_url %} |
23 |
| - {# Org or User name #} |
24 |
| - {% set owner = data.owner.login %} |
25 |
| - {% if data.homepage != "" %} |
26 |
| - {% set homepage_url = data.homepage %} |
27 |
| - {% endif %} |
28 |
| - {% set description = data.description %} |
| 9 | +{% if item.source and item.source == 'crates' %} |
| 10 | + {% set data = load_data(url = "https://crates.io/api/v1/crates/" ~ item.name ~ "?include=downloads,default_version", format="json", headers=["User-Agent=arewegameyet ( [email protected])"]) %} |
| 11 | + |
| 12 | + {% set name = data.crate.name %} |
| 13 | + {% set description = data.crate.description %} |
| 14 | + {% set repository_url = data.crate.repository %} |
| 15 | + {% set crate_url = 'https://crates.io/crates/' ~ name %} |
| 16 | + {% set latest_version = data.crate.default_version %} |
| 17 | + {% set downloads = data.crate.downloads %} |
| 18 | + {% set recent_downloads = data.crate.recent_downloads %} |
| 19 | + {% set license = data.versions | first | get(key="license") %} |
| 20 | + |
| 21 | + {% if data.crate.homepage %} |
| 22 | + {% set homepage_url = data.crate.homepage %} |
| 23 | + {% endif %} |
| 24 | +{% elif item.source and item.source == 'github' %} |
| 25 | + {% set data = load_data(url="https://api.github.com/repos/" ~ item.name, headers=["Authorization=Bearer " ~ github_token], format="json") %} |
| 26 | + |
| 27 | + {% set name = data.name %} |
| 28 | + {% set description = data.description %} |
| 29 | + {% set repository_url = data.html_url %} |
| 30 | + |
| 31 | + {% if data.license and data.license.key != "other" %} |
| 32 | + {% set license = data.license.name %} |
| 33 | + {% endif %} |
| 34 | + |
| 35 | + {% if data.homepage %} |
| 36 | + {% set homepage_url = data.homepage %} |
29 | 37 | {% endif %}
|
30 | 38 | {% endif %}
|
31 | 39 |
|
|
45 | 53 | {% set primary_url = repository_url %}
|
46 | 54 | {% endif %}
|
47 | 55 |
|
| 56 | +{# Fetch repository stats #} |
| 57 | +{% if repository_url and repository_url is containing("github.com/") %} |
| 58 | + {% set repo_icon = "github" %} |
| 59 | + {% set repo_id = repository_url | split(pat="github.com/") | last | trim_end_matches(pat="/") | trim_end_matches(pat=".git") %} |
| 60 | + |
| 61 | + {% set data = load_data(url="https://api.github.com/repos/" ~ repo_id, headers=["Authorization=Bearer " ~ github_token], format="json", required=false) %} |
| 62 | + {% if data %} |
| 63 | + {% set stars = data.stargazers_count %} |
| 64 | + {% set last_activity = data.pushed_at %} |
| 65 | + {% endif %} |
| 66 | +{% elif repository_url and repository_url is containing("gitlab.com/") %} |
| 67 | + {% set repo_icon = "gitlab" %} |
| 68 | + {% set repo_id = repository_url | split(pat="gitlab.com/") | last | trim_end_matches(pat="/") | trim_end_matches(pat=".git") | urlencode_strict %} |
| 69 | + |
| 70 | + {% set data = load_data(url="https://gitlab.com/api/v4/projects/" ~ repo_id, format="json", required=false) %} |
| 71 | + {% if data %} |
| 72 | + {% set stars = data.star_count %} |
| 73 | + {% set last_activity = data.last_activity_at %} |
| 74 | + {% endif %} |
| 75 | +{% elif repository_url and repository_url is containing("gitea.com/") %} |
| 76 | + {% set repo_id = repository_url | split(pat="gitea.com/") | last | trim_end_matches(pat="/") | trim_end_matches(pat=".git") %} |
| 77 | + |
| 78 | + {% set data = load_data(url="https://gitea.com/api/v1/repos/" ~ repo_id, format="json", required=false) %} |
| 79 | + {% if data %} |
| 80 | + {% set stars = data.stars_count %} |
| 81 | + {% set last_activity = data.updated_at %} |
| 82 | + {% endif %} |
| 83 | +{% endif %} |
| 84 | + |
48 | 85 | <li class="ui card{% if archived %} archived{% endif %}">
|
49 | 86 | {% if item.image %}
|
50 | 87 | {% if primary_url %}
|
|
61 | 98 | {% endif %}
|
62 | 99 |
|
63 | 100 | <div class="content">
|
64 |
| - <a href="#{{ name | slugify }}" id="{{ name | slugify }}" aria-label="Permanent link for {{ name }}"> |
65 |
| - <i class="right floated hashtag icon"></i> |
| 101 | + <h3 class="header"> |
| 102 | + {% if primary_url %} |
| 103 | + <a href="{{ primary_url }}">{{ name }}</a> |
| 104 | + {% else %} |
| 105 | + {{ name }} |
| 106 | + {% endif %} |
| 107 | + </h3> |
| 108 | + |
| 109 | + <a class="right floated" href="#{{ name | slugify }}" id="{{ name | slugify }}" aria-label="Permanent link for {{ name }}"> |
| 110 | + <i class="hashtag icon" aria-hidden="true"></i> |
66 | 111 | </a>
|
67 | 112 |
|
68 | 113 | {% if repository_url %}
|
69 |
| - <a href="{{ repository_url }}" aria-label="Github link for {{ name }}"> |
70 |
| - <i class="right floated github icon"></i> |
| 114 | + <a class="right floated" href="{{ repository_url }}" aria-label="Repository link for {{ name }}"> |
| 115 | + <i class="{{ repo_icon | default(value="code") }} icon" aria-hidden="true"></i> |
71 | 116 | </a>
|
72 | 117 | {% endif %}
|
73 | 118 |
|
74 | 119 | {% if crate_url %}
|
75 |
| - <a href="{{ crate_url }}" aria-label="Crates.io link for {{ name }}"> |
76 |
| - <i class="right floated cube icon"></i> |
| 120 | + <a class="right floated" href="{{ crate_url }}" aria-label="Crates.io link for {{ name }}"> |
| 121 | + <i class="cube icon" aria-hidden="true"></i> |
77 | 122 | </a>
|
78 | 123 | {% endif %}
|
79 | 124 |
|
80 | 125 | {% if homepage_url %}
|
81 |
| - <a href="{{ homepage_url }}" aria-label="Website link for {{ name }}"> |
82 |
| - <i class="right floated home icon"></i> |
| 126 | + <a class="right floated" href="{{ homepage_url }}" aria-label="Website link for {{ name }}"> |
| 127 | + <i class="home icon" aria-hidden="true"></i> |
83 | 128 | </a>
|
84 | 129 | {% endif %}
|
85 |
| - |
86 |
| - <div class="header"> |
87 |
| - {% if primary_url %} |
88 |
| - <a href="{{ primary_url }}">{{ name }}</a> |
89 |
| - {% else %} |
90 |
| - {{ name }} |
91 |
| - {% endif %} |
92 |
| - </div> |
93 | 130 |
|
94 | 131 | <div class="meta">
|
95 | 132 | {% for category in item.categories %}
|
|
105 | 142 | </div>
|
106 | 143 | </div>
|
107 | 144 |
|
108 |
| - {% if item.source or gitter_url %} |
| 145 | + {% if item.source or repository_url or gitter_url %} |
109 | 146 | <div class="extra content">
|
110 |
| - |
111 |
| - <div class="ui horizontal list"> |
112 |
| - {% if item.source and item.source == 'crates' %} |
113 |
| - <div class="item"> |
| 147 | + <ul class="ui horizontal list"> |
| 148 | + {% if gitter_url %} |
| 149 | + <li class="item"> |
114 | 150 | <div class="content">
|
115 |
| - <a href="https://crates.io/crates/{{name}}"> |
116 |
| - <img src="https://img.shields.io/crates/v/{{name}}.svg?maxAge=2592000" alt="Crates.io link for {{ name }}"> |
| 151 | + <a class="ui blue label" href="{{ gitter_url }}" target="_blank"> |
| 152 | + <i class="chat icon" aria-hidden="true"></i> |
| 153 | + Chat on Gitter |
117 | 154 | </a>
|
118 | 155 | </div>
|
119 |
| - </div> |
120 |
| - <div class="item" aria-hidden="true"> |
| 156 | + </li> |
| 157 | + {% endif %} |
| 158 | + {% if latest_version %} |
| 159 | + <li class="item"> |
121 | 160 | <div class="content">
|
122 |
| - <a href="https://crates.io/crates/{{name}}"> |
123 |
| - <img src="https://img.shields.io/crates/d/{{name}}.svg?maxAge=2592000" alt="Download count for {{ name }}"> |
124 |
| - </a> |
| 161 | + <div class="ui basic label"> |
| 162 | + <i class="code icon" aria-hidden="true"></i> |
| 163 | + Latest version: |
| 164 | + <div class="detail">{{ latest_version }}</div> |
| 165 | + </div> |
125 | 166 | </div>
|
126 |
| - </div> |
127 |
| - <div class="item" aria-hidden="true"> |
| 167 | + </li> |
| 168 | + {% endif %} |
| 169 | + {% if downloads %} |
| 170 | + <li class="item"> |
128 | 171 | <div class="content">
|
129 |
| - <a href="https://crates.io/crates/{{name}}"> |
130 |
| - <img src="https://img.shields.io/crates/dr/{{name}}.svg?maxAge=2592000" alt="Recent download count for {{ name }}"> |
131 |
| - </a> |
| 172 | + <div class="ui basic label"> |
| 173 | + <i class="download icon" aria-hidden="true"></i> |
| 174 | + Downloads: |
| 175 | + <div class="detail">{{ downloads | num_format }}</div> |
| 176 | + </div> |
132 | 177 | </div>
|
133 |
| - </div> |
134 |
| - <div class="item" aria-hidden="true"> |
| 178 | + </li> |
| 179 | + {% endif %} |
| 180 | + {% if recent_downloads %} |
| 181 | + <li class="item"> |
135 | 182 | <div class="content">
|
136 |
| - <a href="https://crates.io/crates/{{name}}"> |
137 |
| - <img src="https://img.shields.io/crates/l/{{name}}.svg?maxAge=2592000" alt="License for {{ name }}"> |
138 |
| - </a> |
| 183 | + <div class="ui basic label"> |
| 184 | + <i class="clock icon" aria-hidden="true"></i> |
| 185 | + Recent downloads: |
| 186 | + <div class="detail">{{ recent_downloads | num_format }}</div> |
| 187 | + </div> |
139 | 188 | </div>
|
140 |
| - </div> |
| 189 | + </li> |
141 | 190 | {% endif %}
|
142 |
| - {% if item.source and item.source == 'github' %} |
143 |
| - <div class="item" aria-hidden="true"> |
| 191 | + {% if license %} |
| 192 | + <li class="item"> |
144 | 193 | <div class="content">
|
145 |
| - <a href="https://github.com/{{owner}}/{{name}}"> |
146 |
| - <img src="https://img.shields.io/github/stars/{{owner}}/{{name}}?style=flat" alt="Github Stars for {{ name }}"> |
147 |
| - </a> |
| 194 | + <div class="ui basic label"> |
| 195 | + <i class="balance scale icon" aria-hidden="true"></i> |
| 196 | + License: |
| 197 | + <div class="detail">{{ license }}</div> |
| 198 | + </div> |
148 | 199 | </div>
|
149 |
| - </div> |
150 |
| - <div class="item" aria-hidden="true"> |
| 200 | + </li> |
| 201 | + {% endif %} |
| 202 | + {% if stars %} |
| 203 | + <li class="item"> |
151 | 204 | <div class="content">
|
152 |
| - <a href="https://github.com/{{owner}}/{{name}}"> |
153 |
| - <img src="https://img.shields.io/github/last-commit/{{owner}}/{{name}}" alt="Last commit date for {{ name }}"> |
154 |
| - </a> |
| 205 | + <div class="ui basic label"> |
| 206 | + <i class="star icon" aria-hidden="true"></i> |
| 207 | + Stars: |
| 208 | + <div class="detail">{{ stars | num_format }}</div> |
| 209 | + </div> |
155 | 210 | </div>
|
156 |
| - </div> |
| 211 | + </li> |
157 | 212 | {% endif %}
|
158 |
| - {% if gitter_url %} |
159 |
| - <div class="item"> |
| 213 | + {% if last_activity %} |
| 214 | + <li class="item"> |
160 | 215 | <div class="content">
|
161 |
| - <a href="{{ gitter_url }}" target="_blank"> |
162 |
| - <img src="/assets/badges/chat.svg"/> |
163 |
| - </a> |
| 216 | + <div class="ui basic label"> |
| 217 | + <i class="calendar icon" aria-hidden="true"></i> |
| 218 | + Last activity: |
| 219 | + <div class="detail">{{ last_activity | date }}</div> |
| 220 | + </div> |
164 | 221 | </div>
|
165 |
| - </div> |
| 222 | + </li> |
166 | 223 | {% endif %}
|
167 |
| - </div> |
| 224 | + </ul> |
168 | 225 | </div>
|
169 | 226 | {% endif %}
|
170 | 227 | </li>
|
|
0 commit comments