Filter for 11ty to show the number of downloads of a npm package. Based on the work of @alex-page!
That's easy!
npm install eleventy-filter-npm-package-downloads
Add it to your eleventy.config.js
like so:
import { npmPackageDownloads } from 'eleventy-filter-npm-package-downloads';
export default function (eleventyConfig) {
eleventyConfig.addNunjucksAsyncFilter('packageDownloads',
async (packageName, callback) => {
await npmPackageDownloads(packageName, callback);
});
return {
markdownTemplateEngine: "njk"
};
};
Now you can use it in your layout templates:
You've got {{ '@11ty/eleventy' | packageDownloads }} downloads last week!
MIT. See LICENSE