The great refactor (#82)
This commit is contained in:
30
source/plugins/topics/README.md
Normal file
30
source/plugins/topics/README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
### 📌 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.
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.topics.svg">
|
||||
<details open><summary>Mastered and known technologies version</summary>
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.topics.mastered.svg">
|
||||
</details>
|
||||
<img width="900" height="1" alt="">
|
||||
</td>
|
||||
</table>
|
||||
|
||||
This uses puppeteer to navigate through your starred topics page.
|
||||
|
||||
#### ℹ️ Examples workflows
|
||||
|
||||
[➡️ Available options for this plugin](metadata.yml)
|
||||
|
||||
```yaml
|
||||
- uses: lowlighter/metrics@latest
|
||||
with:
|
||||
# ... other options
|
||||
plugin_topics: yes
|
||||
plugin_topics_sort: stars # Sort by most starred topics
|
||||
plugin_topics_mode: mastered # Display icons instead of labels
|
||||
plugin_topics_limit: 0 # Disable limitations
|
||||
```
|
||||
@@ -1,24 +1,15 @@
|
||||
//Setup
|
||||
export default async function ({login, imports, q, account}, {enabled = false} = {}) {
|
||||
export default async function ({login, data, imports, q, account}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.topics))
|
||||
return null
|
||||
if (account === "organization")
|
||||
throw {error:{message:"Not available for organizations"}}
|
||||
//Parameters override
|
||||
let {"topics.sort":sort = "stars", "topics.mode":mode = "starred", "topics.limit":limit} = q
|
||||
//Shuffle
|
||||
const shuffle = (sort === "random")
|
||||
//Sort method
|
||||
sort = {starred:"created", activity:"updated", stars:"stars", random:"created"}[sort] ?? "starred"
|
||||
//Limit
|
||||
if (!Number.isFinite(limit))
|
||||
limit = (mode === "mastered" ? 0 : 15)
|
||||
limit = Math.max(0, Math.min(20, Number(limit)))
|
||||
//Mode
|
||||
mode = ["starred", "mastered"].includes(mode) ? mode : "starred"
|
||||
|
||||
//Load inputs
|
||||
let {sort, mode, limit} = imports.metadata.plugins.topics.inputs({data, account, q})
|
||||
const shuffle = (sort === "random")
|
||||
|
||||
//Start puppeteer and navigate to topics
|
||||
console.debug(`metrics/compute/${login}/plugins > topics > searching starred topics`)
|
||||
let topics = []
|
||||
@@ -26,6 +17,7 @@
|
||||
const browser = await imports.puppeteer.launch({headless:true, executablePath:process.env.PUPPETEER_BROWSER_PATH, args:["--no-sandbox", "--disable-extensions", "--disable-setuid-sandbox", "--disable-dev-shm-usage"]})
|
||||
console.debug(`metrics/compute/${login}/plugins > topics > started ${await browser.version()}`)
|
||||
const page = await browser.newPage()
|
||||
|
||||
//Iterate through pages
|
||||
for (let i = 1; i <= 100; i++) {
|
||||
//Load page
|
||||
@@ -47,14 +39,17 @@
|
||||
}
|
||||
topics.push(...starred)
|
||||
}
|
||||
|
||||
//Close browser
|
||||
console.debug(`metrics/compute/${login}/plugins > music > closing browser`)
|
||||
await browser.close()
|
||||
|
||||
//Shuffle topics
|
||||
if (shuffle) {
|
||||
console.debug(`metrics/compute/${login}/plugins > topics > shuffling topics`)
|
||||
topics = imports.shuffle(topics)
|
||||
}
|
||||
|
||||
//Limit topics (starred mode)
|
||||
if ((mode === "starred")&&(limit > 0)) {
|
||||
console.debug(`metrics/compute/${login}/plugins > topics > keeping only ${limit} topics`)
|
||||
@@ -62,6 +57,7 @@
|
||||
if (removed.length)
|
||||
topics.push({name:`And ${removed.length} more...`, description:removed.map(({name}) => name).join(", "), icon:null})
|
||||
}
|
||||
|
||||
//Convert icons to base64
|
||||
console.debug(`metrics/compute/${login}/plugins > topics > loading artworks`)
|
||||
for (const topic of topics) {
|
||||
@@ -72,16 +68,19 @@
|
||||
//Escape HTML description
|
||||
topic.description = imports.htmlescape(topic.description)
|
||||
}
|
||||
|
||||
//Filter topics with icon (mastered mode)
|
||||
if (mode === "mastered") {
|
||||
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)) {
|
||||
console.debug(`metrics/compute/${login}/plugins > topics > keeping only ${limit} topics`)
|
||||
topics.splice(limit)
|
||||
}
|
||||
|
||||
//Results
|
||||
return {mode, list:topics}
|
||||
}
|
||||
|
||||
41
source/plugins/topics/metadata.yml
Normal file
41
source/plugins/topics/metadata.yml
Normal file
@@ -0,0 +1,41 @@
|
||||
name: "📌 Starred topics"
|
||||
cost: N/A
|
||||
supports:
|
||||
- user
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_topics:
|
||||
description: Display starred topics
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
# Plugin mode
|
||||
plugin_topics_mode:
|
||||
description: Plugin mode
|
||||
type: string
|
||||
default: starred
|
||||
values:
|
||||
- starred # Display starred topics as labels
|
||||
- mastered # Display starred topics as mastered/known technologies icons
|
||||
|
||||
# Topics sorting order
|
||||
plugin_topics_sort:
|
||||
description: Sorting method of starred topics
|
||||
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
|
||||
|
||||
# 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
|
||||
type: number
|
||||
default: 15
|
||||
min: 0
|
||||
max: 20
|
||||
Reference in New Issue
Block a user