-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f77d33
commit 9a3f05d
Showing
12 changed files
with
221 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//Setup | ||
export default async function ({login, imports, q}, {enabled = false} = {}) { | ||
//Plugin execution | ||
try { | ||
//Check if plugin is enabled and requirements are met | ||
if ((!enabled)||(!q.topics)) | ||
return null | ||
//Parameters override | ||
let {"topics.sort":sort = "stars", "topics.limit":limit = 15} = q | ||
//Shuffle | ||
const shuffle = (sort === "random") | ||
//Sort method | ||
sort = {starred:"created", activity:"updated", stars:"stars", random:"created"}[sort] ?? "starred" | ||
//Limit | ||
limit = Math.max(1, Math.min(20, Number(limit))) | ||
//Start puppeteer and navigate to topics | ||
let topics = [] | ||
console.debug(`metrics/compute/${login}/plugins > topics > starting browser`) | ||
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 > loaded ${await browser.version()}`) | ||
const page = await browser.newPage() | ||
//Iterate through pages | ||
for (let i = 1; i <= 100; i++) { | ||
//Load page | ||
console.debug(`metrics/compute/${login}/plugins > topics > loading page ${i}`) | ||
await page.goto(`https://github.com/stars/${login}/topics?direction=desc&page=${i}&sort=${sort}`) | ||
const frame = page.mainFrame() | ||
//Extract topics | ||
await Promise.race([frame.waitForSelector("ul.repo-list"), frame.waitForSelector(".blankslate")]) | ||
const starred = await frame.evaluate(() => [...document.querySelectorAll("ul.repo-list li")].map(li => ({ | ||
name:li.querySelector(".f3").innerText, | ||
description:li.querySelector(".f5").innerText, | ||
icon:li.querySelector("img")?.src ?? null, | ||
}))) | ||
//Check if next page exists | ||
if (!starred.length) | ||
break | ||
topics.push(...starred) | ||
} | ||
//Shuffle topics | ||
if (shuffle) | ||
topics = imports.shuffle(topics) | ||
//Limit topics | ||
if (limit > 0) { | ||
console.debug(`metrics/compute/${login}/plugins > topics > keeping only ${limit} topics`) | ||
const removed = topics.slice(limit) | ||
topics = topics.slice(0, limit) | ||
topics.push({name:`And ${removed.length} more...`, description:removed.map(({name}) => name).join(", "), icon:null}) | ||
} | ||
//Convert icons to base64 | ||
for (const topic of topics) { | ||
if (topic.icon) { | ||
console.debug(`metrics/compute/${login}/plugins > topics > processing ${topic.name}`) | ||
topic.icon = await imports.imgb64(topic.icon) | ||
} | ||
//Escape HTML description | ||
topic.description = imports.htmlescape(topic.description) | ||
} | ||
//Results | ||
return {list:topics} | ||
} | ||
//Handle errors | ||
catch (error) { | ||
console.debug(error) | ||
throw {error:{message:`An error occured`}} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters