Skip to content

Commit

Permalink
Replace Shields.io with locally rendered data/badges (#591)
Browse files Browse the repository at this point in the history
* Improve accessibility of badges

* Replace Shields.io with locally rendered data/badges

* Fix missing repo info when repository URL ends in a slash

* Fix missing activity info for items without source

* Fix missing repo info when repository URL ends in .git

* Format star count

* Fix GitHub icon displaying even when repo is on a different site

* More accessibility tweaks

* Add Gitea stats support

* Re-order card markup for better accessibility

I tried the page with NVDA, and the aria-label approach didn't work (apparently it's not valid for 'li' tags). So instead, I just tweaked the markup to properly present the item's title first.

* Add build date to the footer

* Hide license badge when GitHub check inconclusive

A lot of the cases where 'Other' was showing as the license turned out to be MIT/Apache projects with their files named wrong, which feels misleading.
  • Loading branch information
17cupsofcoffee authored Jan 25, 2025
1 parent 1b47646 commit 7df2373
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 87 deletions.
21 changes: 21 additions & 0 deletions sass/_extra.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
height: 256px;
}

.ui.cards > .card > .content > .header:not(.ui), .ui.card > .content > .header:not(.ui) {
display: inline-block;
margin-bottom: 0;
}

.ui.card > .image > img, .ui.cards > .card > .image > img {
object-fit: cover;
width: 100%;
Expand All @@ -57,6 +62,22 @@
margin-right: 0.5em;
}

ul.ui.horizontal.list {
margin: 0;
}

ul.ui.list li::before {
content: none;
}

.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;
Expand Down
2 changes: 1 addition & 1 deletion sass/_semantic.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion sass/semantic/_label.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
215 changes: 136 additions & 79 deletions templates/categories/macros.html
Original file line number Diff line number Diff line change
@@ -1,31 +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=", format="json", headers=["User-Agent=arewegameyet ([email protected])"]) %}
{# 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 %}
{% 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 %}
{% 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 ([email protected])"]) %}

{% 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 and data.license.key != "other" %}
{% set license = data.license.name %}
{% endif %}

{% if data.homepage %}
{% set homepage_url = data.homepage %}
{% endif %}
{% endif %}

Expand All @@ -45,6 +53,35 @@
{% set primary_url = repository_url %}
{% endif %}

{# Fetch repository stats #}
{% if repository_url and repository_url is containing("github.com/") %}
{% set repo_icon = "github" %}
{% set repo_id = repository_url | split(pat="github.com/") | last | trim_end_matches(pat="/") | trim_end_matches(pat=".git") %}

{% 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_icon = "gitlab" %}
{% set repo_id = repository_url | split(pat="gitlab.com/") | last | trim_end_matches(pat="/") | trim_end_matches(pat=".git") | 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 %}
{% elif repository_url and repository_url is containing("gitea.com/") %}
{% set repo_id = repository_url | split(pat="gitea.com/") | last | trim_end_matches(pat="/") | trim_end_matches(pat=".git") %}

{% set data = load_data(url="https://gitea.com/api/v1/repos/" ~ repo_id, format="json", required=false) %}
{% if data %}
{% set stars = data.stars_count %}
{% set last_activity = data.updated_at %}
{% endif %}
{% endif %}

<li class="ui card{% if archived %} archived{% endif %}">
{% if item.image %}
{% if primary_url %}
Expand All @@ -61,35 +98,35 @@
{% endif %}

<div class="content">
<a href="#{{ name | slugify }}" id="{{ name | slugify }}" aria-label="Permanent link for {{ name }}">
<i class="right floated hashtag icon"></i>
<h3 class="header">
{% if primary_url %}
<a href="{{ primary_url }}">{{ name }}</a>
{% else %}
{{ name }}
{% endif %}
</h3>

<a class="right floated" href="#{{ name | slugify }}" id="{{ name | slugify }}" aria-label="Permanent link for {{ name }}">
<i class="hashtag icon" aria-hidden="true"></i>
</a>

{% if repository_url %}
<a href="{{ repository_url }}" aria-label="Github link for {{ name }}">
<i class="right floated github icon"></i>
<a class="right floated" href="{{ repository_url }}" aria-label="Repository link for {{ name }}">
<i class="{{ repo_icon | default(value="code") }} icon" aria-hidden="true"></i>
</a>
{% endif %}

{% if crate_url %}
<a href="{{ crate_url }}" aria-label="Crates.io link for {{ name }}">
<i class="right floated cube icon"></i>
<a class="right floated" href="{{ crate_url }}" aria-label="Crates.io link for {{ name }}">
<i class="cube icon" aria-hidden="true"></i>
</a>
{% endif %}

{% if homepage_url %}
<a href="{{ homepage_url }}" aria-label="Website link for {{ name }}">
<i class="right floated home icon"></i>
<a class="right floated" href="{{ homepage_url }}" aria-label="Website link for {{ name }}">
<i class="home icon" aria-hidden="true"></i>
</a>
{% endif %}

<div class="header">
{% if primary_url %}
<a href="{{ primary_url }}">{{ name }}</a>
{% else %}
{{ name }}
{% endif %}
</div>

<div class="meta">
{% for category in item.categories %}
Expand All @@ -105,66 +142,86 @@
</div>
</div>

{% if item.source or gitter_url %}
{% if item.source or repository_url or gitter_url %}
<div class="extra content">

<div class="ui horizontal list">
{% if item.source and item.source == 'crates' %}
<div class="item">
<ul class="ui horizontal list">
{% if gitter_url %}
<li class="item">
<div class="content">
<a href="https://crates.io/crates/{{name}}">
<img src="https://img.shields.io/crates/v/{{name}}.svg?maxAge=2592000" alt="Crates.io link for {{ name }}">
<a class="ui blue label" href="{{ gitter_url }}" target="_blank">
<i class="chat icon" aria-hidden="true"></i>
Chat on Gitter
</a>
</div>
</div>
<div class="item" aria-hidden="true">
</li>
{% endif %}
{% if latest_version %}
<li class="item">
<div class="content">
<a href="https://crates.io/crates/{{name}}">
<img src="https://img.shields.io/crates/d/{{name}}.svg?maxAge=2592000" alt="Download count for {{ name }}">
</a>
<div class="ui basic label">
<i class="code icon" aria-hidden="true"></i>
Latest version:
<div class="detail">{{ latest_version }}</div>
</div>
</div>
</div>
<div class="item" aria-hidden="true">
</li>
{% endif %}
{% if downloads %}
<li class="item">
<div class="content">
<a href="https://crates.io/crates/{{name}}">
<img src="https://img.shields.io/crates/dr/{{name}}.svg?maxAge=2592000" alt="Recent download count for {{ name }}">
</a>
<div class="ui basic label">
<i class="download icon" aria-hidden="true"></i>
Downloads:
<div class="detail">{{ downloads | num_format }}</div>
</div>
</div>
</div>
<div class="item" aria-hidden="true">
</li>
{% endif %}
{% if recent_downloads %}
<li class="item">
<div class="content">
<a href="https://crates.io/crates/{{name}}">
<img src="https://img.shields.io/crates/l/{{name}}.svg?maxAge=2592000" alt="License for {{ name }}">
</a>
<div class="ui basic label">
<i class="clock icon" aria-hidden="true"></i>
Recent downloads:
<div class="detail">{{ recent_downloads | num_format }}</div>
</div>
</div>
</div>
</li>
{% endif %}
{% if item.source and item.source == 'github' %}
<div class="item" aria-hidden="true">
{% if license %}
<li class="item">
<div class="content">
<a href="https://github.com/{{owner}}/{{name}}">
<img src="https://img.shields.io/github/stars/{{owner}}/{{name}}?style=flat" alt="Github Stars for {{ name }}">
</a>
<div class="ui basic label">
<i class="balance scale icon" aria-hidden="true"></i>
License:
<div class="detail">{{ license }}</div>
</div>
</div>
</div>
<div class="item" aria-hidden="true">
</li>
{% endif %}
{% if stars %}
<li class="item">
<div class="content">
<a href="https://github.com/{{owner}}/{{name}}">
<img src="https://img.shields.io/github/last-commit/{{owner}}/{{name}}" alt="Last commit date for {{ name }}">
</a>
<div class="ui basic label">
<i class="star icon" aria-hidden="true"></i>
Stars:
<div class="detail">{{ stars | num_format }}</div>
</div>
</div>
</div>
</li>
{% endif %}
{% if gitter_url %}
<div class="item">
{% if last_activity %}
<li class="item">
<div class="content">
<a href="{{ gitter_url }}" target="_blank">
<img src="/assets/badges/chat.svg"/>
</a>
<div class="ui basic label">
<i class="calendar icon" aria-hidden="true"></i>
Last activity:
<div class="detail">{{ last_activity | date }}</div>
</div>
</div>
</div>
</li>
{% endif %}
</div>
</ul>
</div>
{% endif %}
</li>
Expand Down
10 changes: 5 additions & 5 deletions templates/categories/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{# Heading #}
<section class="ui vertical stripe">
<h1 class="ui center aligned icon header">
<i class="circular icon {{ section.extra.icon }}"></i>
<i class="circular icon {{ section.extra.icon }}" aria-hidden="true"></i>
{{ page.title }}
</h1>
<div class="ui text container">
Expand Down Expand Up @@ -51,7 +51,7 @@ <h1 class="ui center aligned icon header">
<section>
<h2 class="ui horizontal divider small header">
<a href="#{{ section.extra.plural | slugify }}" id="{{ section.extra.plural | slugify }}">
<i class="list icon big"></i>
<i class="list icon big" aria-hidden="true"></i>
{{ section.extra.plural | title }}
</a>
</h2>
Expand All @@ -71,15 +71,15 @@ <h2 class="ui horizontal divider small header">
<section>
<h2 class="ui horizontal divider small header">
<a href="#{{ section.extra.plural | slugify }}" id="{{ section.extra.plural | slugify }}">
<i class="bed icon big"></i>
<i class="bed icon big" aria-hidden="true"></i>
Archived
</a>
</h2>

<div class="ui vertical stripe">
<div class="ui container">
<div class="ui message">
<i class="info circle icon"></i>
<i class="info circle icon" aria-hidden="true"></i>
These {{ section.extra.plural }} are no longer maintained, but may still be of interest.
</div>

Expand All @@ -96,7 +96,7 @@ <h2 class="ui horizontal divider small header">
<section>
<h2 class="ui horizontal divider small header">
<a href="#contribute" id="contribute">
<i class="chat icon big"></i>
<i class="chat icon big" aria-hidden="true"></i>
Contribute
</a>
</h2>
Expand Down
8 changes: 7 additions & 1 deletion templates/master.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ <h4 class="ui inverted header">About</h4>
</div>
<div class="ten wide column">
<h4 class="ui inverted header">Arewegameyet?</h4>
<p><a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.</p>
<p>
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a>
<br />
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.
<br />
Page generated at {{ now() | date(format="%Y-%m-%d %H:%M") }}.
</p>
</div>
<div class="three wide column">
<h4 class="ui inverted header">Get involved</h4>
Expand Down

0 comments on commit 7df2373

Please sign in to comment.