feat(plugins/starlists): add languages, forks and stars to repositories (#853) [skip ci]

This commit is contained in:
Simon Lecoq
2022-02-08 06:01:11 +01:00
committed by GitHub
parent dedfe8970f
commit 2a0329d878
3 changed files with 28 additions and 2 deletions

View File

@@ -44,9 +44,15 @@ export default async function({login, q, imports, data, account}, {enabled = fal
for (const list of lists) { for (const list of lists) {
console.debug(`metrics/compute/${login}/plugins > starlists > fetching ${list.name}`) console.debug(`metrics/compute/${login}/plugins > starlists > fetching ${list.name}`)
await page.goto(list.link) await page.goto(list.link)
const repositories = await page.evaluate(() => [...document.querySelectorAll("#user-list-repositories > div")].map(element => ({ const repositories = await page.evaluate(() => [...document.querySelectorAll("#user-list-repositories > div:not(.paginate-container)")].map(element => ({
name:element.querySelector("div:first-child")?.innerText.replace(" / ", "/") ?? "", name:element.querySelector("div:first-child")?.innerText.replace(" / ", "/") ?? "",
description:element.querySelector(".py-1")?.innerText ?? "", description:element.querySelector(".py-1")?.innerText ?? "",
language:{
name:element.querySelector("[itemprop='programmingLanguage']")?.innerText ?? "",
color:element.querySelector(".repo-language-color")?.style?.backgroundColor?.match(/\d+/g)?.map(x => Number(x).toString(16)).join("") ?? null,
},
stargazers:Number(element.querySelector("[href$='/stargazers']")?.innerText.trim().replace(/[^\d]/g, "") ?? NaN),
forks:Number(element.querySelector("[href$='/network/members']")?.innerText.trim().replace(/[^\d]/g, "") ?? NaN),
})) }))
) )
list.repositories.push(...repositories) list.repositories.push(...repositories)

View File

@@ -34,6 +34,26 @@
<div class="field description"> <div class="field description">
<%= repository.description %> <%= repository.description %>
</div> </div>
<div class="field infos">
<% if (repository.language?.name) { %>
<div class="language">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill="#<%= repository.language.color ?? "959DA5" %>" fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8z"></path></svg>
<%= repository.language.name %>
</div>
<% } %>
<% if (Number.isFinite(repository.stargazers)) { %>
<div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="11" height="11"><path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"></path></svg>
<%= f(repository.stargazers) %>
</div>
<% } %>
<% if (Number.isFinite(repository.stargazers)) { %>
<div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="11" height="11"><path fill-rule="evenodd" d="M5 3.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm0 2.122a2.25 2.25 0 10-1.5 0v.878A2.25 2.25 0 005.75 8.5h1.5v2.128a2.251 2.251 0 101.5 0V8.5h1.5a2.25 2.25 0 002.25-2.25v-.878a2.25 2.25 0 10-1.5 0v.878a.75.75 0 01-.75.75h-4.5A.75.75 0 015 6.25v-.878zm3.75 7.378a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm3-8.75a.75.75 0 100-1.5.75.75 0 000 1.5z"></path></svg>
<%= f(repository.forks) %>
</div>
<% } %>
</div>
</section> </section>
</div> </div>
<% } %> <% } %>

View File

@@ -870,7 +870,7 @@
.starlist .repository { .starlist .repository {
margin: 6px 0 0; margin: 6px 0 0;
} }
.starlist .repository .description { .starlist .repository .description, .starlist .repository .infos {
font-size: 11px; font-size: 11px;
} }
.starlist .repository .name { .starlist .repository .name {