惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
美团技术团队
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Security Blog
Microsoft Security Blog
F
Fortinet All Blogs
A
About on SuperTechFans
Recent Announcements
Recent Announcements
D
Docker
Vercel News
Vercel News
Engineering at Meta
Engineering at Meta
腾讯CDC
Martin Fowler
Martin Fowler
阮一峰的网络日志
阮一峰的网络日志

The Eleventy Firehose

New Sponsorship Tiers for the Build Awesome Kickstarter Securely Publishing our Packages to npm Back Build Awesome Pro and make it easier to build for the web! The Possum Mascot, now with additional Awesome Build Awesome (11ty) (@11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty.dev) Release Import v1.0.20 · 11ty/import Release Import v1.0.21 · 11ty/import Build Awesome (11ty) (@11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty.dev) Cozy Keyboard Build and Build Awesome AMA Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty.dev) A few demos of Editing and Collaboration in Build Awesome Pro (as always, AMA!) Build Awesome (11ty) (@11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Bluesky: May 6, 2026 at 7:54:00 PM UTC An Awesome Theming Demo with Dave Gandy (and more Build Awesome AMA) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Release v8.0.0 · 11ty/eleventy-plugin-vite Build Awesome Pro Kickstarter AMA
Quick Tip: Fetch GitHub Stargazers Count (and More) at Bu...
Zach Leather · 2026-06-07 · via The Eleventy Firehose

Older iterations of this website used a third party JavaScript widget to show the number of GitHub Stars the project currently had. You can see it in action on the versioned docs for 0.7.1 (scroll to the bottom).

This was in fact the only <script> tag on the entire 11ty.dev web site and it was from a third party. Naturally, it needed to be annihilated.

Let’s change up our architecture to ruthlessly eliminate this client-side JavaScript.

Get the Stargazers Count from the GitHub API

Read more at the GitHub API documentation.

This is a bit different from our client-side implementation because this data is only updated as often as your build runs. This is implemented using a global JavaScript data file at _data/github.js.

_data/github.js

import fetch from "node-fetch";

export default async function () {
	console.log("Fetching new github stargazers count…");

	// GitHub API: https://developer.github.com/v3/repos/#get
	let res = await fetch("https://api.github.com/repos/11ty/eleventy");
	let json = await res.json();

	// prune the data to return only what we want
	return {
		stargazers: json.stargazers_count,
	};
};
const fetch = require("node-fetch");

module.exports = async function () {
	console.log("Fetching new github stargazers count…");

	// GitHub API: https://developer.github.com/v3/repos/#get
	let res = await fetch("https://api.github.com/repos/11ty/eleventy");
	let json = await res.json();

	// prune the data to return only what we want
	return {
		stargazers: json.stargazers_count,
	};
};

Now in your templates you can output the stargazers count with:

Syntax Liquid, Nunjucks

{{ github.stargazers }} GitHub Stars

which outputs

1515 GitHub Stars

Bonus: I created a humanReadableNum filter) using the human-readable-numbers package to format the number.

More Examples

You can look in the footer of this page to see examples of this in use on this very web site. I used it for:

These all use the recommended caching mechanism described in the next section.

Update Counts Daily

If you want to update these counts automatically every day, read Quick Tip #008—Trigger a Netlify Build Every Day with IFTTT.