From 94ddb3fe885ba9d36054b1e4f2c34b58717e54aa Mon Sep 17 00:00:00 2001 From: Obelous <47227283+0belous@users.noreply.github.com> Date: Tue, 19 Aug 2025 02:29:03 +0100 Subject: [PATCH] Add source code to description --- update.js | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/update.js b/update.js index b6ebd59..11ae641 100644 --- a/update.js +++ b/update.js @@ -50,7 +50,7 @@ async function clearImagesFolder() { } async function downloadImage(url, filename) { - console.log(` -> Downloading image: ${url} as ${filename}`); + console.log(`Downloading image: ${url} as ${filename}`); try { const res = await fetch(url, { headers: { 'User-Agent': userAgent } }); if (!res.ok) throw new Error(`Failed to fetch image: ${res.status}`); @@ -76,6 +76,44 @@ function hashString(str) { return crypto.createHash('md5').update(str).digest('hex'); } +function findGithubUrl(obj) { + if (!obj) return null; + for (const key in obj) { + if (typeof obj[key] === 'string') { + const match = obj[key].match(/https?:\/\/github\.com\/[^\/]+\/[^\/]+/); + if (match) { + return match[0]; + } + } else if (typeof obj[key] === 'object' && obj[key] !== null) { + const url = findGithubUrl(obj[key]); + if (url) return url; + } + } + return null; +} + +async function processDescriptions(pluginData) { + try { + for (const plugin of pluginData) { + const repoUrl = findGithubUrl(plugin); + if (repoUrl) { + const sourceLink = `\n\n[Source Code](${repoUrl})`; + const descriptionProp = plugin.overview ? 'overview' : (plugin.Description ? 'Description' : null); + if (descriptionProp) { + if (!plugin[descriptionProp].includes(repoUrl)) { + plugin[descriptionProp] += sourceLink; + } + } else { + plugin.overview = sourceLink.trim(); + } + } + } + console.log(`Sucessfully injected source URLs`); + } catch (err) { + console.error('Error processing descriptions:', err); + } +} + async function processImages(pluginData) { await clearImagesFolder(); for (const plugin of pluginData) { @@ -113,6 +151,7 @@ async function writeManifest(dataToWrite){ async function main() { const plugins = await getSources(); await processImages(plugins); + await processDescriptions(plugins); await writeManifest(plugins); }