+
From b6a9ef20d8853aeef33c46be7cdd7b1e8e68d627 Mon Sep 17 00:00:00 2001
From: Joe Clay <27cupsofcoffee@gmail.com>
Date: Mon, 13 Jan 2025 23:17:28 +0000
Subject: [PATCH 02/12] Replace Shields.io with locally rendered data/badges
---
sass/_extra.scss | 8 ++
sass/_semantic.scss | 2 +-
sass/semantic/_label.scss | 2 +-
templates/categories/macros.html | 161 +++++++++++++++++++------------
4 files changed, 111 insertions(+), 62 deletions(-)
diff --git a/sass/_extra.scss b/sass/_extra.scss
index c79c2d62..ed8c144e 100644
--- a/sass/_extra.scss
+++ b/sass/_extra.scss
@@ -57,6 +57,14 @@
margin-right: 0.5em;
}
+.ui.label > .icon {
+ margin-right: 0.25em;
+}
+
+.ui.label > .detail {
+ margin-left: 0.5em;
+}
+
@media only screen and (max-width: 991px) {
.masthead .ui.menu a.item {
display: none;
diff --git a/sass/_semantic.scss b/sass/_semantic.scss
index 64094c55..a8a7134f 100644
--- a/sass/_semantic.scss
+++ b/sass/_semantic.scss
@@ -8,7 +8,7 @@
@import 'semantic/icon';
@import 'semantic/image';
// @import 'semantic/input';
-// @import 'semantic/label';
+@import 'semantic/label';
@import 'semantic/list';
//@import 'semantic/loader';
//@import 'semantic/placeholder';
diff --git a/sass/semantic/_label.scss b/sass/semantic/_label.scss
index 02183579..72107d7c 100755
--- a/sass/semantic/_label.scss
+++ b/sass/semantic/_label.scss
@@ -351,7 +351,7 @@ a.ui.label {
}
.ui.card .image > .ui.ribbon.label,
.ui.image > .ui.ribbon.label {
- left: calc(--0.05rem - 1.2em);
+ left: calc(-0.05rem - 1.2em);
}
.ui.card .image > .ui[class*="right ribbon"].label,
.ui.image > .ui[class*="right ribbon"].label {
diff --git a/templates/categories/macros.html b/templates/categories/macros.html
index e301f79a..14d0eec6 100644
--- a/templates/categories/macros.html
+++ b/templates/categories/macros.html
@@ -1,36 +1,39 @@
{% macro info(item, section, archived=false) %}
+{% set github_token = get_env(name="GITHUB_TOKEN") %}
+
{% if item.name %}
{% set name = item.name %}
{% endif %}
-{% if item.source %}
- {% if item.source == 'crates' %}
- {% set data = load_data(url = "https://crates.io/api/v1/crates/" ~ item.name ~ "?include=downloads", format="json", headers=["User-Agent=arewegameyet (gamedev-wg@rust-lang.org)"]) %}
- {# human readable name #}
- {% set name = data.crate.name %}
- {# Github/Gitlab/Etc. repository #}
- {% set repository_url = data.crate.repository %}
- {% set crate_url = 'https://crates.io/crates/' ~ name %}
- {% set description = data.crate.description %}
- {% set latest_version = data.crate.default_version %}
- {% set downloads = data.crate.downloads %}
- {% set recent_downloads = data.crate.recent_downloads %}
- {% if data.crate.homepage %}
- {% set homepage_url = data.crate.homepage %}
- {% endif %}
- {% elif item.source == 'github' %}
- {% set data = load_data(url="https://api.github.com/repos/" ~ item.name, format="json") %}
- {% set name = data.name %}
- {% set repository_url = data.html_url %}
- {# Org or User name #}
- {% set owner = data.owner.login %}
- {% if data.homepage != "" %}
- {% set homepage_url = data.homepage %}
- {% endif %}
- {% set description = data.description %}
- {% set stars = data.stargazers_count %}
- {% set last_commit = data.pushed_at %}
+{% if item.source and item.source == 'crates' %}
+ {% set data = load_data(url = "https://crates.io/api/v1/crates/" ~ item.name ~ "?include=downloads,default_version", format="json", headers=["User-Agent=arewegameyet (gamedev-wg@rust-lang.org)"]) %}
+
+ {% set name = data.crate.name %}
+ {% set description = data.crate.description %}
+ {% set repository_url = data.crate.repository %}
+ {% set crate_url = 'https://crates.io/crates/' ~ name %}
+ {% set latest_version = data.crate.default_version %}
+ {% set downloads = data.crate.downloads %}
+ {% set recent_downloads = data.crate.recent_downloads %}
+ {% set license = data.versions | first | get(key="license") %}
+
+ {% if data.crate.homepage %}
+ {% set homepage_url = data.crate.homepage %}
+ {% endif %}
+{% elif item.source and item.source == 'github' %}
+ {% set data = load_data(url="https://api.github.com/repos/" ~ item.name, headers=["Authorization=Bearer " ~ github_token], format="json") %}
+
+ {% set name = data.name %}
+ {% set description = data.description %}
+ {% set repository_url = data.html_url %}
+
+ {% if data.license %}
+ {% set license = data.license.name %}
+ {% endif %}
+
+ {% if data.homepage %}
+ {% set homepage_url = data.homepage %}
{% endif %}
{% endif %}
@@ -50,6 +53,24 @@
{% set primary_url = repository_url %}
{% endif %}
+{% if repository_url and repository_url is containing("github.com/") %}
+ {% set repo_id = repository_url | split(pat="github.com/") | last %}
+
+ {% set data = load_data(url="https://api.github.com/repos/" ~ repo_id, headers=["Authorization=Bearer " ~ github_token], format="json", required=false) %}
+ {% if data %}
+ {% set stars = data.stargazers_count %}
+ {% set last_activity = data.pushed_at %}
+ {% endif %}
+{% elif repository_url and repository_url is containing("gitlab.com/") %}
+ {% set repo_id = repository_url | split(pat="gitlab.com/") | last | urlencode_strict %}
+
+ {% set data = load_data(url="https://gitlab.com/api/v4/projects/" ~ repo_id, format="json", required=false) %}
+ {% if data %}
+ {% set stars = data.star_count %}
+ {% set last_activity = data.last_activity_at %}
+ {% endif %}
+{% endif %}
+
{% if item.image %}
{% if primary_url %}
@@ -66,28 +87,28 @@
{% endif %}
-
-
+
+
{% if repository_url %}
-
-
+
+
{% endif %}
{% if crate_url %}
-
-
+
+
{% endif %}
{% if homepage_url %}
-
-
+
+
{% endif %}
-
+