Skip to content

Commit 5e85fd1

Browse files
committed
Fix author arrays, HTML escaping, null guard, and code quality in Libraries page
1 parent fd0ec83 commit 5e85fd1

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

libraries/index.html

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,17 @@ <h1 class="page-header__heading">mrbgems</h1>
5555
{% for mgem in gems %}
5656
{% assign mod = row_index | modulo: row_size %}
5757
{% if mod == 0 %}<div class="libs-row">{% endif %}
58+
{% if mgem.author.first %}{% assign mgem_author = mgem.author | join: ", " %}{% else %}{% assign mgem_author = mgem.author %}{% endif %}
5859
<a
5960
href="{{ mgem.website }}"
6061
class="libs-card"
61-
data-name="{{ mgem.name | downcase }}"
62-
data-author="{{ mgem.author | downcase }}"
63-
data-description="{{ mgem.description | downcase }}"
62+
data-name="{{ mgem.name | downcase | xml_escape }}"
63+
data-author="{{ mgem_author | downcase | xml_escape }}"
64+
data-description="{{ mgem.description | downcase | xml_escape }}"
6465
>
6566
<div class="libs-card__header">
6667
<span class="libs-card__name">{{ mgem.name }}</span>
67-
<span class="libs-card__author">{{ mgem.author }}</span>
68+
<span class="libs-card__author">{{ mgem_author }}</span>
6869
</div>
6970
<p class="libs-card__description">{{ mgem.description }}</p>
7071
</a>
@@ -79,12 +80,12 @@ <h1 class="page-header__heading">mrbgems</h1>
7980
</div>
8081
</section>
8182

82-
<div class="libs-footer">
83+
<section class="libs-footer">
8384
<div class="libs-footer__inner">
84-
<span class="libs-footer__text" id="libs-footer-count">Showing {{ total }} libraries </span>
85+
<span class="libs-footer__text" id="libs-footer-count">Showing {{ total }} libraries &#8212;</span>
8586
<a href="https://github.com/mruby/mgem-list" class="libs-footer__link">view all on GitHub &#8594;</a>
8687
</div>
87-
</div>
88+
</section>
8889

8990
<script>
9091
(function () {
@@ -96,6 +97,8 @@ <h1 class="page-header__heading">mrbgems</h1>
9697
var total = cards.length;
9798
var timer;
9899

100+
if (!input || !countLabel || !footerCount || !noResults) return;
101+
99102
function update(query) {
100103
var q = query.trim().toLowerCase();
101104
var visible = 0;
@@ -113,6 +116,17 @@ <h1 class="page-header__heading">mrbgems</h1>
113116
}
114117
});
115118

119+
document.querySelectorAll('.libs-row').forEach(function (row) {
120+
var hasVisible = Array.from(row.querySelectorAll('.libs-card')).some(function (c) {
121+
return !c.hasAttribute('hidden');
122+
});
123+
if (hasVisible) {
124+
row.removeAttribute('hidden');
125+
} else {
126+
row.setAttribute('hidden', '');
127+
}
128+
});
129+
116130
if (q) {
117131
countLabel.textContent = 'Showing ' + visible + ' of ' + total + ' libraries';
118132
footerCount.textContent = 'Showing ' + visible + ' of ' + total + ' libraries \u2014';

0 commit comments

Comments
 (0)