From 29b445d5b59533720e7123c3650d6aed28d985ef Mon Sep 17 00:00:00 2001 From: Simon Lecoq <22963968+lowlighter@users.noreply.github.com> Date: Sun, 16 Jan 2022 00:32:51 +0100 Subject: [PATCH] feat(plugins/topics): add `labels` alias (#776) [skip ci] --- source/plugins/topics/README.md | 67 ++++++++++++++------ source/plugins/topics/index.mjs | 13 ++-- source/plugins/topics/metadata.yml | 51 +++++++++------ source/templates/classic/partials/topics.ejs | 6 +- 4 files changed, 89 insertions(+), 48 deletions(-) diff --git a/source/plugins/topics/README.md b/source/plugins/topics/README.md index 4955d62c..3602eb2d 100644 --- a/source/plugins/topics/README.md +++ b/source/plugins/topics/README.md @@ -1,21 +1,28 @@ -### 📌 Starred topics - -The *topics* plugin displays your [starred topics](https://github.com/stars?filter=topics). -Check out [GitHub topics](https://github.com/topics) to search interesting topics. - + - + + + + + + + + + + + + + + +
-
With icons - -
-
With labels - -
- -

📌 Starred topics

This plugin displays starred topics. +Check out GitHub topics to search interesting topics.

+
Supported features
→ Full specification
📗 Classic template 📒 Markdown template
👤 Users
No tokens are required for this plugin
+
With icons
+
With labels
+ +
- -This uses puppeteer to navigate through your starred topics page. + #### ➡️ Available options @@ -26,7 +33,8 @@ This uses puppeteer to navigate through your starred topics page. plugin_topics - Display starred topics +

Enable topics plugin

+ type: boolean @@ -35,17 +43,31 @@ This uses puppeteer to navigate through your starred topics page. plugin_topics_mode - Plugin mode +

Display mode:

+ + type: string
default: starred
-allowed values: +allowed values: plugin_topics_sort - Sorting method of starred topics +

Sorting method:

+ + type: string @@ -55,7 +77,9 @@ This uses puppeteer to navigate through your starred topics page. plugin_topics_limit - Maximum number of topics to display +

Display limit

+

When using plugin_topics_mode: labels, an ellipsis will be displayed

+ type: number @@ -63,6 +87,7 @@ This uses puppeteer to navigate through your starred topics page. 𝑥 ≤ 20)
+zero behaviour: disable
default: 15
diff --git a/source/plugins/topics/index.mjs b/source/plugins/topics/index.mjs index 8fc3fa35..e9a81fb1 100644 --- a/source/plugins/topics/index.mjs +++ b/source/plugins/topics/index.mjs @@ -8,6 +8,7 @@ export default async function({login, data, imports, q, account}, {enabled = fal //Load inputs let {sort, mode, limit} = imports.metadata.plugins.topics.inputs({data, account, q}) + const type = {starred:"labels", labels:"labels", mastered:"icons", icons:"icons"}[mode] const shuffle = (sort === "random") //Start puppeteer and navigate to topics @@ -51,8 +52,8 @@ export default async function({login, data, imports, q, account}, {enabled = fal topics = imports.shuffle(topics) } - //Limit topics (starred mode) - if ((mode === "starred") && (limit > 0)) { + //Limit topics (labels) + if ((type === "labels") && (limit > 0)) { console.debug(`metrics/compute/${login}/plugins > topics > keeping only ${limit} topics`) const removed = topics.splice(limit) if (removed.length) @@ -72,14 +73,14 @@ export default async function({login, data, imports, q, account}, {enabled = fal topic.description = imports.htmlescape(topic.description) } - //Filter topics with icon (mastered mode) - if (mode === "mastered") { + //Filter topics with icon (icons) + if (type === "icons") { console.debug(`metrics/compute/${login}/plugins > topics > filtering topics with icon`) topics = topics.filter(({icon}) => icon) } - //Limit topics (mastered mode) - if ((mode === "mastered") && (limit > 0)) { + //Limit topics (icons) + if ((type === "icons") && (limit > 0)) { console.debug(`metrics/compute/${login}/plugins > topics > keeping only ${limit} topics`) topics.splice(limit) } diff --git a/source/plugins/topics/metadata.yml b/source/plugins/topics/metadata.yml index e8a52a1b..a4db24a9 100644 --- a/source/plugins/topics/metadata.yml +++ b/source/plugins/topics/metadata.yml @@ -1,44 +1,59 @@ name: "📌 Starred topics" category: github +description: | + This plugin displays [starred topics](https://github.com/stars?filter=topics). + Check out [GitHub topics](https://github.com/topics) to search interesting topics. +examples: + +with icons: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.topics.icons.svg + +with labels: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.topics.svg index: 2 supports: - user scopes: [] inputs: - # Enable or disable plugin plugin_topics: - description: Display starred topics + description: Enable topics plugin type: boolean default: no - # Plugin mode plugin_topics_mode: - description: Plugin mode + description: | + Display mode: + - `labels`: display labels + - `icons`: display icons *(topics without icons will be ignored)* + - `starred`: alias for `labels` + - `mastered`: alias for `icons` type: string default: starred values: - - starred # Display starred topics as labels - - icons # Display starred topics as icons - - mastered # Display starred topics as mastered/known technologies icons + - labels + - icons + - starred + - mastered - # Topics sorting order plugin_topics_sort: - description: Sorting method of starred topics + description: | + Sorting method: + - `stars`: sort by most stars + - `activity`: sort by recent activity + - `starred`: sort by the date you starred them + - `random`: sort topics randomly type: string default: stars values: - - stars # Sort topics by stargazers - - activity # Sort topics by recent activity - - starred # Sort topics by the date you starred them - - random # Sort topics randomly + - stars + - activity + - starred + - random - # Number of topics to display - # Set to 0 to disable limitations - # When in "starred" mode, additional topics will be grouped into an ellipsis plugin_topics_limit: - description: Maximum number of topics to display + description: | + Display limit + + When using `plugin_topics_mode: labels`, an ellipsis will be displayed type: number default: 15 min: 0 - max: 20 \ No newline at end of file + max: 20 + zero: disable \ No newline at end of file diff --git a/source/templates/classic/partials/topics.ejs b/source/templates/classic/partials/topics.ejs index 3be1d782..092334ec 100644 --- a/source/templates/classic/partials/topics.ejs +++ b/source/templates/classic/partials/topics.ejs @@ -2,7 +2,7 @@

- <%= {starred:"Starred topics", icons:"Starred topics", mastered:"Mastered technologies and topics"}[plugins.topics.mode] %> + <%= {starred:"Starred topics", labels:"Starred topics", icons:"Starred topics", mastered:"Mastered technologies and topics"}[plugins.topics.mode] %>

<% if (plugins.topics.error) { %> @@ -15,11 +15,11 @@ <% } else { %>
- <% if (plugins.topics.mode === "starred") { %> + <% if (plugins.topics.type === "labels") { %> <% for (const {name, description} of plugins.topics.list) { %>
<%= name.toLocaleLowerCase() %>
<% } %> - <% } else if ((plugins.topics.mode === "mastered")||(plugins.topics.mode === "icons")) { %> + <% } else if ((plugins.topics.type === "icons")) { %> <% for (const {name, icon} of plugins.topics.list) { %> <% if (icon) { %> <%= name %>