From 4270f2ea40c821779c897b17f232b4fa21e0844c Mon Sep 17 00:00:00 2001 From: KrishP147 Date: Tue, 20 Oct 2026 13:15:27 -0400 Subject: [PATCH] feat(site): live star count via GitHub API on page load; cron back to weekly Co-Authored-By: Claude Opus 5.5 (1M context) --- .github/workflows/deploy-portfolio.yml | 4 ++-- site/src/app.js | 28 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-portfolio.yml b/.github/workflows/deploy-portfolio.yml index a746a42..fa82a88 100644 --- a/.github/workflows/deploy-portfolio.yml +++ b/.github/workflows/deploy-portfolio.yml @@ -18,9 +18,9 @@ on: - "*/*/README.md" - "CONTRIBUTING.md" - "THIRD_PARTY_LICENSES.md" - # Hourly rebuild so the GitHub star count on the site stays current. + # Weekly rebuild refreshes the baked-in star count (app.js updates it live). schedule: - - cron: "17 * * * *" + - cron: "0 12 * * 1" workflow_dispatch: permissions: {} diff --git a/site/src/app.js b/site/src/app.js index 0a6a6dc..48a4934 100644 --- a/site/src/app.js +++ b/site/src/app.js @@ -2,6 +2,34 @@ filter.js (SkillFilter); this file only handles events and rendering. The buffer always starts with "/" (pre-typed, undeletable); the rest is typed freely and ranked by SkillFilter.search. */ +// Live GitHub star count. The build bakes in a count (build_site.py); this +// refreshes it per visit, cached 10 min per tab to stay under the API's +// 60 requests/hour unauthenticated limit. Any failure keeps the baked count. +(function () { + "use strict"; + var KEY = "gh-stars"; + function show(n) { + var els = document.querySelectorAll(".gh-stars"); + for (var i = 0; i < els.length; i++) { + els[i].textContent = "★ " + n; + els[i].hidden = false; + } + } + try { + var c = JSON.parse(sessionStorage.getItem(KEY) || "null"); + if (c && Date.now() - c.t < 600000) return show(c.n); + } catch (e) {} + if (!window.fetch) return; + fetch("https://api.github.com/repos/KrishP147/skills") + .then(function (r) { return r.ok ? r.json() : null; }) + .then(function (d) { + if (!d || typeof d.stargazers_count !== "number") return; + show(d.stargazers_count); + try { sessionStorage.setItem(KEY, JSON.stringify({ n: d.stargazers_count, t: Date.now() })); } catch (e) {} + }) + .catch(function () {}); +})(); + (function () { "use strict"; var F = window.SkillFilter;