Skip to content

Commit 29b445d

Browse files
authored
feat(plugins/topics): add labels alias (lowlighter#776) [skip ci]
1 parent db2be65 commit 29b445d

File tree

4 files changed

+89
-48
lines changed

4 files changed

+89
-48
lines changed

source/plugins/topics/README.md

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
### 📌 Starred topics
2-
3-
The *topics* plugin displays your [starred topics](https://github.com/stars?filter=topics).
4-
Check out [GitHub topics](https://github.com/topics) to search interesting topics.
5-
1+
<!--header-->
62
<table>
7-
<td align="center">
8-
<details open><summary>With icons</summary>
9-
<img src="https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.topics.icons.svg">
10-
</details>
11-
<details open><summary>With labels</summary>
12-
<img src="https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.topics.svg">
13-
</details>
14-
<img width="900" height="1" alt="">
15-
</td>
3+
<tr><th colspan="2"><h3>📌 Starred topics</h3></th></tr>
4+
<tr><td colspan="2" align="center"><p>This plugin displays <a href="https://github.com/stars?filter=topics">starred topics</a>.
5+
Check out <a href="https://github.com/topics">GitHub topics</a> to search interesting topics.</p>
6+
</td></tr>
7+
<tr>
8+
<th rowspan="3">Supported features<br><sub><a href="metadata.yml">→ Full specification</a></sub></th>
9+
<td><a href="/source/templates/classic"><code>📗 Classic template</code></a> <a href="/source/templates/markdown"><code>📒 Markdown template</code></a></td>
10+
</tr>
11+
<tr>
12+
<td><code>👤 Users</code></td>
13+
</tr>
14+
<tr>
15+
<td><i>No tokens are required for this plugin</i></td>
16+
</tr>
17+
<tr>
18+
<td colspan="2" align="center">
19+
<details open><summary>With icons</summary><img src="https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.topics.icons.svg" alt=""></img></details>
20+
<details open><summary>With labels</summary><img src="https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.topics.svg" alt=""></img></details>
21+
<img width="900" height="1" alt="">
22+
</td>
23+
</tr>
1624
</table>
17-
18-
This uses puppeteer to navigate through your starred topics page.
25+
<!--/header-->
1926

2027
#### ➡️ Available options
2128

@@ -26,7 +33,8 @@ This uses puppeteer to navigate through your starred topics page.
2633
</tr>
2734
<tr>
2835
<td nowrap="nowrap"><code>plugin_topics</code></td>
29-
<td rowspan="2">Display starred topics<img width="900" height="1" alt=""></td>
36+
<td rowspan="2"><p>Enable topics plugin</p>
37+
<img width="900" height="1" alt=""></td>
3038
</tr>
3139
<tr>
3240
<td nowrap="nowrap"><b>type:</b> <code>boolean</code>
@@ -35,17 +43,31 @@ This uses puppeteer to navigate through your starred topics page.
3543
</tr>
3644
<tr>
3745
<td nowrap="nowrap"><code>plugin_topics_mode</code></td>
38-
<td rowspan="2">Plugin mode<img width="900" height="1" alt=""></td>
46+
<td rowspan="2"><p>Display mode:</p>
47+
<ul>
48+
<li><code>labels</code>: display labels</li>
49+
<li><code>icons</code>: display icons <em>(topics without icons will be ignored)</em></li>
50+
<li><code>starred</code>: alias for <code>labels</code></li>
51+
<li><code>mastered</code>: alias for <code>icons</code></li>
52+
</ul>
53+
<img width="900" height="1" alt=""></td>
3954
</tr>
4055
<tr>
4156
<td nowrap="nowrap"><b>type:</b> <code>string</code>
4257
<br>
4358
<b>default:</b> starred<br>
44-
<b>allowed values:</b><ul><li>starred</li><li>icons</li><li>mastered</li></ul></td>
59+
<b>allowed values:</b><ul><li>labels</li><li>icons</li><li>starred</li><li>mastered</li></ul></td>
4560
</tr>
4661
<tr>
4762
<td nowrap="nowrap"><code>plugin_topics_sort</code></td>
48-
<td rowspan="2">Sorting method of starred topics<img width="900" height="1" alt=""></td>
63+
<td rowspan="2"><p>Sorting method:</p>
64+
<ul>
65+
<li><code>stars</code>: sort by most stars</li>
66+
<li><code>activity</code>: sort by recent activity</li>
67+
<li><code>starred</code>: sort by the date you starred them</li>
68+
<li><code>random</code>: sort topics randomly</li>
69+
</ul>
70+
<img width="900" height="1" alt=""></td>
4971
</tr>
5072
<tr>
5173
<td nowrap="nowrap"><b>type:</b> <code>string</code>
@@ -55,14 +77,17 @@ This uses puppeteer to navigate through your starred topics page.
5577
</tr>
5678
<tr>
5779
<td nowrap="nowrap"><code>plugin_topics_limit</code></td>
58-
<td rowspan="2">Maximum number of topics to display<img width="900" height="1" alt=""></td>
80+
<td rowspan="2"><p>Display limit</p>
81+
<p>When using <code>plugin_topics_mode: labels</code>, an ellipsis will be displayed</p>
82+
<img width="900" height="1" alt=""></td>
5983
</tr>
6084
<tr>
6185
<td nowrap="nowrap"><b>type:</b> <code>number</code>
6286
<i>(0 ≤
6387
𝑥
6488
≤ 20)</i>
6589
<br>
90+
<b>zero behaviour:</b> disable</br>
6691
<b>default:</b> 15<br></td>
6792
</tr>
6893
</table>

source/plugins/topics/index.mjs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default async function({login, data, imports, q, account}, {enabled = fal
88

99
//Load inputs
1010
let {sort, mode, limit} = imports.metadata.plugins.topics.inputs({data, account, q})
11+
const type = {starred:"labels", labels:"labels", mastered:"icons", icons:"icons"}[mode]
1112
const shuffle = (sort === "random")
1213

1314
//Start puppeteer and navigate to topics
@@ -51,8 +52,8 @@ export default async function({login, data, imports, q, account}, {enabled = fal
5152
topics = imports.shuffle(topics)
5253
}
5354

54-
//Limit topics (starred mode)
55-
if ((mode === "starred") && (limit > 0)) {
55+
//Limit topics (labels)
56+
if ((type === "labels") && (limit > 0)) {
5657
console.debug(`metrics/compute/${login}/plugins > topics > keeping only ${limit} topics`)
5758
const removed = topics.splice(limit)
5859
if (removed.length)
@@ -72,14 +73,14 @@ export default async function({login, data, imports, q, account}, {enabled = fal
7273
topic.description = imports.htmlescape(topic.description)
7374
}
7475

75-
//Filter topics with icon (mastered mode)
76-
if (mode === "mastered") {
76+
//Filter topics with icon (icons)
77+
if (type === "icons") {
7778
console.debug(`metrics/compute/${login}/plugins > topics > filtering topics with icon`)
7879
topics = topics.filter(({icon}) => icon)
7980
}
8081

81-
//Limit topics (mastered mode)
82-
if ((mode === "mastered") && (limit > 0)) {
82+
//Limit topics (icons)
83+
if ((type === "icons") && (limit > 0)) {
8384
console.debug(`metrics/compute/${login}/plugins > topics > keeping only ${limit} topics`)
8485
topics.splice(limit)
8586
}

source/plugins/topics/metadata.yml

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,59 @@
11
name: "📌 Starred topics"
22
category: github
3+
description: |
4+
This plugin displays [starred topics](https://github.com/stars?filter=topics).
5+
Check out [GitHub topics](https://github.com/topics) to search interesting topics.
6+
examples:
7+
+with icons: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.topics.icons.svg
8+
+with labels: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.topics.svg
39
index: 2
410
supports:
511
- user
612
scopes: []
713
inputs:
814

9-
# Enable or disable plugin
1015
plugin_topics:
11-
description: Display starred topics
16+
description: Enable topics plugin
1217
type: boolean
1318
default: no
1419

15-
# Plugin mode
1620
plugin_topics_mode:
17-
description: Plugin mode
21+
description: |
22+
Display mode:
23+
- `labels`: display labels
24+
- `icons`: display icons *(topics without icons will be ignored)*
25+
- `starred`: alias for `labels`
26+
- `mastered`: alias for `icons`
1827
type: string
1928
default: starred
2029
values:
21-
- starred # Display starred topics as labels
22-
- icons # Display starred topics as icons
23-
- mastered # Display starred topics as mastered/known technologies icons
30+
- labels
31+
- icons
32+
- starred
33+
- mastered
2434

25-
# Topics sorting order
2635
plugin_topics_sort:
27-
description: Sorting method of starred topics
36+
description: |
37+
Sorting method:
38+
- `stars`: sort by most stars
39+
- `activity`: sort by recent activity
40+
- `starred`: sort by the date you starred them
41+
- `random`: sort topics randomly
2842
type: string
2943
default: stars
3044
values:
31-
- stars # Sort topics by stargazers
32-
- activity # Sort topics by recent activity
33-
- starred # Sort topics by the date you starred them
34-
- random # Sort topics randomly
45+
- stars
46+
- activity
47+
- starred
48+
- random
3549

36-
# Number of topics to display
37-
# Set to 0 to disable limitations
38-
# When in "starred" mode, additional topics will be grouped into an ellipsis
3950
plugin_topics_limit:
40-
description: Maximum number of topics to display
51+
description: |
52+
Display limit
53+
54+
When using `plugin_topics_mode: labels`, an ellipsis will be displayed
4155
type: number
4256
default: 15
4357
min: 0
44-
max: 20
58+
max: 20
59+
zero: disable

source/templates/classic/partials/topics.ejs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<section>
33
<h2 class="field">
44
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M14.184 1.143a1.75 1.75 0 00-2.502-.57L.912 7.916a1.75 1.75 0 00-.53 2.32l.447.775a1.75 1.75 0 002.275.702l11.745-5.656a1.75 1.75 0 00.757-2.451l-1.422-2.464zm-1.657.669a.25.25 0 01.358.081l1.422 2.464a.25.25 0 01-.108.35l-2.016.97-1.505-2.605 1.85-1.26zM9.436 3.92l1.391 2.41-5.42 2.61-.942-1.63 4.97-3.39zM3.222 8.157l-1.466 1a.25.25 0 00-.075.33l.447.775a.25.25 0 00.325.1l1.598-.769-.83-1.436zm6.253 2.306a.75.75 0 00-.944-.252l-1.809.87a.75.75 0 00-.293.253L4.38 14.326a.75.75 0 101.238.848l1.881-2.75v2.826a.75.75 0 001.5 0v-2.826l1.881 2.75a.75.75 0 001.238-.848l-2.644-3.863z"></path></svg>
5-
<%= {starred:"Starred topics", icons:"Starred topics", mastered:"Mastered technologies and topics"}[plugins.topics.mode] %>
5+
<%= {starred:"Starred topics", labels:"Starred topics", icons:"Starred topics", mastered:"Mastered technologies and topics"}[plugins.topics.mode] %>
66
</h2>
77
<div class="row">
88
<% if (plugins.topics.error) { %>
@@ -15,11 +15,11 @@
1515
<% } else { %>
1616
<section>
1717
<div class="topics fill-width">
18-
<% if (plugins.topics.mode === "starred") { %>
18+
<% if (plugins.topics.type === "labels") { %>
1919
<% for (const {name, description} of plugins.topics.list) { %>
2020
<div class="label" title="<%= description %>"><%= name.toLocaleLowerCase() %></div>
2121
<% } %>
22-
<% } else if ((plugins.topics.mode === "mastered")||(plugins.topics.mode === "icons")) { %>
22+
<% } else if ((plugins.topics.type === "icons")) { %>
2323
<% for (const {name, icon} of plugins.topics.list) { %>
2424
<% if (icon) { %>
2525
<img src="<%= icon %>" width="24" height="24" alt="<%= name %>" title="<%= name %>"/>

0 commit comments

Comments
 (0)