diff --git a/README.md b/README.md index 0f328de..06cf39a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

eleventy Logo

-# eleventy-cache-assets +# eleventy-fetch _Requires Node 12+_ @@ -10,21 +10,21 @@ With the added benefit that if one successful request completes, you can now wor This plugin can save any kind of asset—JSON, HTML, images, videos, etc. -## [The full `eleventy-cache-assets` documentation is on 11ty.dev](https://www.11ty.dev/docs/plugins/cache/). +## [The full `eleventy-fetch` documentation is on 11ty.dev](https://www.11ty.dev/docs/plugins/cache/). * _This is a plugin for the [Eleventy static site generator](https://www.11ty.dev/)._ * Find more [Eleventy plugins](https://www.11ty.dev/docs/plugins/). * Please star [Eleventy on GitHub](https://github.com/11ty/eleventy/), follow [@eleven_ty](https://twitter.com/eleven_ty) on Twitter, and support [11ty on Open Collective](https://opencollective.com/11ty) -[![npm Version](https://img.shields.io/npm/v/@11ty/eleventy-cache-assets.svg?style=for-the-badge)](https://www.npmjs.com/package/@11ty/eleventy-cache-assets) [![GitHub issues](https://img.shields.io/github/issues/11ty/eleventy-cache-assets.svg?style=for-the-badge)](https://github.com/11ty/eleventy/issues) +[![npm Version](https://img.shields.io/npm/v/@11ty/eleventy-fetch.svg?style=for-the-badge)](https://www.npmjs.com/package/@11ty/eleventy-fetch) [![GitHub issues](https://img.shields.io/github/issues/11ty/eleventy-fetch.svg?style=for-the-badge)](https://github.com/11ty/eleventy/issues) ## Installation ``` -npm install @11ty/eleventy-cache-assets +npm install @11ty/eleventy-fetch ``` -_[The full `eleventy-cache-assets` documentation is on 11ty.dev](https://www.11ty.dev/docs/plugins/cache/)._ +_[The full `eleventy-fetch` documentation is on 11ty.dev](https://www.11ty.dev/docs/plugins/cache/)._ ## Tests @@ -46,3 +46,9 @@ npm run test * `flat-cache` save method seems to be synchronous, is there a better async one? * Our cache stores raw buffers internally, which are pretty bloated compared to the original. Surely there is a more efficient way to do this. Maybe store the files in their original format. --> + +## Community Roadmap + +- [Top Feature Requests](https://github.com/11ty/eleventy-fetch/issues?q=label%3Aneeds-votes+sort%3Areactions-%2B1-desc+label%3Aenhancement) (Add your own votes using the 👍 reaction) +- [Top Bugs 😱](https://github.com/11ty/eleventy-fetch/issues?q=is%3Aissue+is%3Aopen+label%3Abug+sort%3Areactions-%2B1-desc) (Add your own votes using the 👍 reaction) +- [Newest Bugs 🙀](https://github.com/11ty/eleventy-fetch/issues?q=is%3Aopen+is%3Aissue+label%3Abug) diff --git a/eleventy-cache-assets.js b/eleventy-fetch.js similarity index 100% rename from eleventy-cache-assets.js rename to eleventy-fetch.js diff --git a/package.json b/package.json index a79d802..5500e22 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,22 @@ { - "name": "@11ty/eleventy-cache-assets", + "name": "@11ty/eleventy-fetch", "version": "2.3.0", - "description": "Cache remote assets, locally (automatically).", + "description": "Fetch and locally cache remote API calls and assets.", "publishConfig": { "access": "public" }, "repository": { "type": "git", - "url": "git+https://github.com/11ty/eleventy-cache-assets.git" + "url": "git+https://github.com/11ty/eleventy-fetch.git" }, - "main": "eleventy-cache-assets.js", + "main": "eleventy-fetch.js", "scripts": { "test": "ava", "sample": "node sample" }, "files": [ "src/", - "eleventy-cache-assets.js" + "eleventy-fetch.js" ], "engines": { "node": ">=12" @@ -36,9 +36,9 @@ }, "license": "MIT", "bugs": { - "url": "https://github.com/11ty/eleventy-cache-assets/issues" + "url": "https://github.com/11ty/eleventy-fetch/issues" }, - "homepage": "https://github.com/11ty/eleventy-cache-assets#readme", + "homepage": "https://github.com/11ty/eleventy-fetch#readme", "devDependencies": { "ava": "^4.0.1" }, diff --git a/src/AssetCache.js b/src/AssetCache.js index 50dbecd..9071b42 100644 --- a/src/AssetCache.js +++ b/src/AssetCache.js @@ -45,7 +45,7 @@ class AssetCache { } get cacheFilename() { - return `eleventy-cache-assets-${this.hash}`; + return `eleventy-fetch-${this.hash}`; } get rootDir() { diff --git a/src/RemoteAssetCache.js b/src/RemoteAssetCache.js index 04abb28..2f53665 100644 --- a/src/RemoteAssetCache.js +++ b/src/RemoteAssetCache.js @@ -57,15 +57,15 @@ class RemoteAssetCache extends AssetCache { let type = optionsOverride.type || this.options.type; let body = await this.getResponseValue(response, type); - console.log( `[11ty/eleventy-cache-assets] ${isDryRun? "Fetching" : "Caching"}: ${this.cleanUrl}` ); + console.log( `[11ty/eleventy-fetch] ${isDryRun? "Fetching" : "Caching"}: ${this.displayUrl}` ); if(!isDryRun) { await super.save(body, type); } return body; } catch(e) { if(this.cachedObject) { - console.log( `[11ty/eleventy-cache-assets] Error fetching ${this.cleanUrl}. Message: ${e.message}`); - console.log( `[11ty/eleventy-cache-assets] Failing gracefully with an expired cache entry.` ); + console.log( `[11ty/eleventy-fetch] Error fetching ${this.displayUrl}. Message: ${e.message}`); + console.log( `[11ty/eleventy-fetch] Failing gracefully with an expired cache entry.` ); return super.getCachedValue(); } else { return Promise.reject(e); diff --git a/test/AssetCacheTest.js b/test/AssetCacheTest.js index 872a9ee..30582d0 100644 --- a/test/AssetCacheTest.js +++ b/test/AssetCacheTest.js @@ -18,15 +18,15 @@ test("Absolute path cache directory", t => { let cache = new AssetCache("lksdjflkjsdf", "/tmp/.cache"); let cachePath = normalizePath(cache.cachePath); - t.is(cachePath, "/tmp/.cache/eleventy-cache-assets-lksdjflkjsdf"); + t.is(cachePath, "/tmp/.cache/eleventy-fetch-lksdjflkjsdf"); }); test("Relative path cache directory", t => { let cache = new AssetCache("lksdjflkjsdf", ".cache"); let cachePath = normalizePath(cache.cachePath); - t.not(cachePath, ".cache/eleventy-cache-assets-lksdjflkjsdf"); - t.true(cachePath.endsWith(".cache/eleventy-cache-assets-lksdjflkjsdf")); + t.not(cachePath, ".cache/eleventy-fetch-lksdjflkjsdf"); + t.true(cachePath.endsWith(".cache/eleventy-fetch-lksdjflkjsdf")); }); test("AWS Lambda root directory resolves correctly", t => { @@ -36,7 +36,7 @@ test("AWS Lambda root directory resolves correctly", t => { let cache = new AssetCache("lksdjflkjsdf", ".cache"); let cachePath = normalizePath(cache.cachePath); - t.is(cachePath, `${cwd}/.cache/eleventy-cache-assets-lksdjflkjsdf`); + t.is(cachePath, `${cwd}/.cache/eleventy-fetch-lksdjflkjsdf`); delete "ELEVENTY_ROOT" in process.env; delete "LAMBDA_TASK_ROOT" in process.env; }); diff --git a/test/QueueTest.js b/test/QueueTest.js index 8c8501b..1ad3ddb 100644 --- a/test/QueueTest.js +++ b/test/QueueTest.js @@ -1,6 +1,5 @@ const test = require("ava"); const fs = require("fs"); -const shorthash = require("short-hash"); const Cache = require("../"); const RemoteAssetCache = require("../src/RemoteAssetCache"); diff --git a/test/RemoteAssetCacheTest.js b/test/RemoteAssetCacheTest.js index 50229b7..c3542c0 100644 --- a/test/RemoteAssetCacheTest.js +++ b/test/RemoteAssetCacheTest.js @@ -25,13 +25,13 @@ test("getDurationMs", t => { test("Local hash file names", async t => { let pngUrl = "https://www.zachleat.com/img/avatar-2017-big.png"; - t.is((new RemoteAssetCache(pngUrl)).cachePath, path.resolve(".", `.cache/eleventy-cache-assets-${shorthash(pngUrl)}`)); + t.is((new RemoteAssetCache(pngUrl)).cachePath, path.resolve(".", `.cache/eleventy-fetch-${shorthash(pngUrl)}`)); let fontUrl = "https://www.zachleat.com/font.woff"; - t.is((new RemoteAssetCache(fontUrl)).cachePath, path.resolve(".", `.cache/eleventy-cache-assets-${shorthash(fontUrl)}`)); + t.is((new RemoteAssetCache(fontUrl)).cachePath, path.resolve(".", `.cache/eleventy-fetch-${shorthash(fontUrl)}`)); let fontUrl2 = "https://www.zachleat.com/font.woff2"; - t.is((new RemoteAssetCache(fontUrl2)).cachePath, path.resolve(".", `.cache/eleventy-cache-assets-${shorthash(fontUrl2)}`)); + t.is((new RemoteAssetCache(fontUrl2)).cachePath, path.resolve(".", `.cache/eleventy-fetch-${shorthash(fontUrl2)}`)); }); test("Clean url", async t => { @@ -44,7 +44,7 @@ test("Clean url", async t => { test("Local hash without file extension in URL", async t => { let noExt = "https://twitter.com/zachleat/profile_image?size=bigger"; - t.is((new RemoteAssetCache(noExt)).cachePath, path.resolve(".", `.cache/eleventy-cache-assets-${shorthash(noExt)}`)); + t.is((new RemoteAssetCache(noExt)).cachePath, path.resolve(".", `.cache/eleventy-fetch-${shorthash(noExt)}`)); }); test("Fetching!", async t => {