diff options
| -rw-r--r-- | src/scraper.ts | 10 | ||||
| -rw-r--r-- | views/repo.eta | 3 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/scraper.ts b/src/scraper.ts index c1bdef5..4ffdc43 100644 --- a/src/scraper.ts +++ b/src/scraper.ts @@ -54,6 +54,7 @@ export interface RepoInfo { stars: string | null; watchers: string | null; forks: string | null; + numReleases?: number; } export interface GitHubRepo extends GitHubTree { @@ -110,12 +111,21 @@ function parseRepoInfo(html: string): RepoInfo { const watchersMatch = html.match(/<strong>(\d+)<\/strong>\s*watching/); const forksMatch = html.match(/id="repo-network-counter"[^>]*>([^<]+)/); + let numReleases: number | undefined; + const releaseCountMatch = html.match( + /<a[^>]*href="[^"]*\/releases"[^>]*>[\s\S]*?<span[^>]*title="(\d+)"[^>]*(?:class="[^"]*Counter|data-view-component="true")[^>]*>/, + ); + if (releaseCountMatch) { + numReleases = parseInt(releaseCountMatch[1], 10); + } + return { description, website: websiteMatch?.[1] || null, stars: starsMatch?.[1]?.trim() || null, watchers: watchersMatch?.[1] || null, forks: forksMatch?.[1]?.trim() || null, + numReleases, }; } diff --git a/views/repo.eta b/views/repo.eta index 4965e75..5bebb95 100644 --- a/views/repo.eta +++ b/views/repo.eta @@ -17,6 +17,9 @@ <% if (it.info.forks) { %> <span class="count"><img src="/static/icons/git-fork.svg" alt="forks" class="icon"> <%= it.info.forks %></span> <% } %> + <% if (it.info.numReleases) { %> + <div><a href="/<%= it.repo.owner %>/<%= it.repo.name %>/releases" rel="noreferrer"><%= it.info.numReleases %> releases</a></div> + <% } %> </div> <% } %> |
