Skip to content

Commit 0da1a8d

Browse files
authored
feat(plugins/starlists): add new starlists plugin (#765)
1 parent 5efce7e commit 0da1a8d

File tree

8 files changed

+221
-0
lines changed

8 files changed

+221
-0
lines changed

source/app/web/statics/app.placeholder.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,23 @@
743743
},
744744
})
745745
: null),
746+
//Starlists
747+
...(set.plugins.enabled.starlists
748+
? ({
749+
starlists: {
750+
lists: new Array(Number(options["starlists.limit"])).fill(null).map(_ => ({
751+
link: faker.internet.url(),
752+
name: `${faker.random.arrayElement(["😎", "🥳", "🧐", "😂", "😁"])} ${faker.lorem.word()}`,
753+
description: faker.lorem.sentence(),
754+
count: faker.datatype.number(100),
755+
repositories: new Array(Number(options["starlists.limit.repositories"])).fill(null).map((_, i) => ({
756+
description: !i ? "📊 An image generator with 20+ metrics about your GitHub account such as activity, community, repositories, coding habits, website performances, music played, starred topics, etc. that you can put on your profile or elsewhere !" : faker.lorem.sentence(),
757+
name: !i ? "lowlighter/metrics" : `${faker.random.word()}/${faker.random.word()}`,
758+
}))
759+
})),
760+
},
761+
})
762+
: null),
746763
//Repositories
747764
...(set.plugins.enabled.repositories
748765
? ({

source/plugins/starlists/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
### 💫 Starlists
2+
3+
The *starlists* plugin displays your recently star lists.
4+
5+
<table>
6+
<td align="center">
7+
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.starlist.svg">
8+
<img width="900" height="1" alt="">
9+
</td>
10+
</table>
11+
12+
#### ℹ️ Examples workflows
13+
14+
[➡️ Available options for this plugin](metadata.yml)
15+
16+
```yaml
17+
- uses: lowlighter/metrics@latest
18+
with:
19+
# ... other options
20+
plugin_starlists: yes
21+
plugin_starlists_limit: 16 # Limit to 16 entries
22+
plugin_starlists_limit_repositories: 2 # Limit to 2 repositories per entries
23+
plugin_starlists_ignored: list1, list2 # Ignored lists
24+
plugin_starlists_only: list3 # Only display this list
25+
```

source/plugins/starlists/index.mjs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//Setup
2+
export default async function({login, q, imports, data, account}, {enabled = false} = {}) {
3+
//Plugin execution
4+
try {
5+
//Check if plugin is enabled and requirements are met
6+
if ((!enabled)||(!q.starlists))
7+
return null
8+
9+
//Load inputs
10+
let {limit, ignored, only, "limit.repositories":_limit} = imports.metadata.plugins.starlists.inputs({data, account, q})
11+
12+
//Start puppeteer and navigate to star lists
13+
console.debug(`metrics/compute/${login}/plugins > starlists > starting browser`)
14+
const browser = await imports.puppeteer.launch()
15+
console.debug(`metrics/compute/${login}/plugins > starlists > started ${await browser.version()}`)
16+
const page = await browser.newPage()
17+
18+
//Fetch star lists
19+
console.debug(`metrics/compute/${login}/plugins > starlists > fetching lists`)
20+
await page.goto(`https://github.com/${login}?tab=stars`)
21+
let lists = (await page.evaluate(() => [...document.querySelectorAll("[href^='/stars/lowlighter/lists']")].map(element => ({
22+
link:element.href,
23+
name:element.querySelector("h3")?.innerText ?? "",
24+
description:element.querySelector("span")?.innerText ?? "",
25+
count:Number(element.querySelector("div")?.innerText.match(/(?<count>\d+)/)?.groups.count),
26+
repositories:[]
27+
}))))
28+
const count = lists.length
29+
lists = lists.slice(0, limit).filter(({name}) => (only.includes(name.toLocaleLowerCase())) || ((!only.length)&&((!name)||(!ignored.includes(name.toLocaleLowerCase())))))
30+
console.debug(`metrics/compute/${login}/plugins > starlists > extracted ${lists.length} lists`)
31+
32+
//Fetch star list content
33+
for (const list of lists) {
34+
console.debug(`metrics/compute/${login}/plugins > starlists > fetching ${list.name}`)
35+
await page.goto(list.link)
36+
const repositories = await page.evaluate(() => [...document.querySelectorAll("#user-list-repositories > div")].map(element => ({
37+
name:element.querySelector("div:first-child")?.innerText.replace(" / ", "/") ?? "",
38+
description:element.querySelector(".py-1")?.innerText ?? ""
39+
})))
40+
list.repositories.push(...repositories)
41+
list.repositories = list.repositories.slice(0, _limit)
42+
}
43+
44+
//Close browser
45+
console.debug(`metrics/compute/${login}/plugins > starlists > closing browser`)
46+
await browser.close()
47+
48+
//Results
49+
return {lists, count}
50+
}
51+
//Handle errors
52+
catch (error) {
53+
throw {error:{message:"An error occured", instance:error}}
54+
}
55+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "💫 Starlists"
2+
category: github
3+
index: ~
4+
supports:
5+
- user
6+
scopes: []
7+
inputs:
8+
9+
# Enable or disable plugin
10+
plugin_starlists:
11+
description: Display star lists
12+
type: boolean
13+
default: no
14+
15+
# Number of star lists to display
16+
plugin_starlists_limit:
17+
description: Number of star lists to display
18+
type: number
19+
default: 2
20+
min: 1
21+
max: 100
22+
23+
# Number of repositories to display per star lists
24+
plugin_starlists_limit_repositories:
25+
description: Number of repositories to display per star lists
26+
type: number
27+
default: 2
28+
min: 0
29+
max: 100
30+
31+
# List of star lists that will be ignored
32+
plugin_starlists_ignored:
33+
description: Star lists to skip
34+
type: array
35+
format: comma-separated
36+
default: ""
37+
example: 😎 list1, 🥳 list2, ...
38+
39+
# List of star lists to display
40+
# Using this option is equivalent of using "plugin_starlists_ignored" with all star lists but the ones listed
41+
plugin_starlists_only:
42+
description: Start lists to display
43+
type: array
44+
format: comma-separated
45+
default: ""
46+
example: 😎 list1, 🥳 list2, ...

source/plugins/starlists/tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- name: Starlists plugin (default)
2+
uses: lowlighter/metrics@latest
3+
with:
4+
token: MOCKED_TOKEN
5+
plugin_starlists: yes

source/templates/classic/partials/_.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"tweets",
2121
"isocalendar",
2222
"stars",
23+
"starlists",
2324
"stargazers",
2425
"people",
2526
"activity",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<% if (plugins.starlists) { %>
2+
<section>
3+
<h2 class="field">
4+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M1.75 2.5a.75.75 0 000 1.5h6.5a.75.75 0 000-1.5h-6.5zm4 5a.75.75 0 000 1.5h7.5a.75.75 0 000-1.5h-7.5zm0 5a.75.75 0 000 1.5h7.5a.75.75 0 000-1.5h-7.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path><path d="M13.314 4.918L11.07 2.417A.25.25 0 0111.256 2h4.488a.25.25 0 01.186.417l-2.244 2.5a.25.25 0 01-.372 0z"></path></svg>
5+
<%= plugins.starlists?.count ?? "" %> Star list<%= s(plugins.starlists?.count ?? 0) %>
6+
</h2>
7+
<div class="row">
8+
<section class="largeable-flex-wrap">
9+
<% if (plugins.starlists.error) { %>
10+
<div class="field error">
11+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M2.343 13.657A8 8 0 1113.657 2.343 8 8 0 012.343 13.657zM6.03 4.97a.75.75 0 00-1.06 1.06L6.94 8 4.97 9.97a.75.75 0 101.06 1.06L8 9.06l1.97 1.97a.75.75 0 101.06-1.06L9.06 8l1.97-1.97a.75.75 0 10-1.06-1.06L8 6.94 6.03 4.97z"></path></svg>
12+
<%= plugins.starlists.error.message %>
13+
</div>
14+
<% } else { %>
15+
<% for (const {name, description, count, repositories} of plugins.starlists.lists) { %>
16+
<div class="starlist">
17+
<h2 class="field">
18+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path></svg>
19+
<%= name %>
20+
</h2>
21+
<div class="count"><%= count %> repositor<%= s(count, "y") %></div>
22+
<div class="description"><%= description %></div>
23+
<div class="repositories">
24+
<% for (const repository of repositories) { %>
25+
<div class="row fill-width largeable-width-half">
26+
<section class="repository">
27+
<div class="field">
28+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4 5.75C4 4.784 4.784 4 5.75 4h4.5c.966 0 1.75.784 1.75 1.75v4.5A1.75 1.75 0 0110.25 12h-4.5A1.75 1.75 0 014 10.25v-4.5zm1.75-.25a.25.25 0 00-.25.25v4.5c0 .138.112.25.25.25h4.5a.25.25 0 00.25-.25v-4.5a.25.25 0 00-.25-.25h-4.5z"></path></svg>
29+
<div class="name">
30+
<span><%= repository.name %></span>
31+
<span></span>
32+
</div>
33+
</div>
34+
<div class="field description">
35+
<%= repository.description %>
36+
</div>
37+
</section>
38+
</div>
39+
<% } %>
40+
</div>
41+
</div>
42+
<% } %>
43+
<% } %>
44+
</section>
45+
</div>
46+
</section>
47+
<% } %>

source/templates/classic/style.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,31 @@
837837
-webkit-box-orient: vertical;
838838
}
839839

840+
/* Star lists */
841+
.starlist {
842+
margin-left: 28px;
843+
}
844+
.starlist > .description, .starlist > .count {
845+
margin-left: 32px;
846+
}
847+
.starlist > .count {
848+
font-size: 12px;
849+
color: #666666;
850+
}
851+
.starlist .repositories {
852+
margin-left: -5px;
853+
margin-bottom: 20px;
854+
}
855+
.starlist .repository {
856+
margin: 6px 0 0;
857+
}
858+
.starlist .repository .description {
859+
font-size: 11px;
860+
}
861+
.starlist .repository .name {
862+
font-size: 14px;
863+
}
864+
840865
/* Anilist */
841866
.anilist {
842867
display: flex;

0 commit comments

Comments
 (0)