https://github.com/xtrm-en/lume-cache-assets
@lumeland plugin that allows caching remote assets locally
https://github.com/xtrm-en/lume-cache-assets
deno lume lume-plugin
Last synced: 12 months ago
JSON representation
@lumeland plugin that allows caching remote assets locally
- Host: GitHub
- URL: https://github.com/xtrm-en/lume-cache-assets
- Owner: xtrm-en
- License: mit
- Created: 2024-01-13T23:33:57.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-14T17:55:12.000Z (over 2 years ago)
- Last Synced: 2025-05-15T20:27:06.379Z (about 1 year ago)
- Topics: deno, lume, lume-plugin
- Language: TypeScript
- Homepage:
- Size: 21.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lume-cache-assets
[Lume](https://lume.land) plugin that allows caching remote assets locally.
## Installation
Import this plugin in your `_config.ts` file to use it:
```ts
import lume from "https://deno.land/x/lume/mod.ts";
import cacheAssets from "https://deno.land/x/lume_cache_assets@0.0.8/mod.ts";
const site = lume();
site.use(cacheAssets(/* Options */));
export default site;
```
## Options
```ts
interface Options {
/**
* The extensions of the files to process.
* @default [".html"]
*/
extensions?: string[];
/**
* A function that returns true if the URL should be cached.
* @default (url: string) => url.startsWith("https://") && [".png", ".jpg", ".jpeg", ".gif", ".svg", ".ico", ".webp"].some((ext) => url.endsWith(ext)),
*/
shouldCache?: (url: string) => boolean;
/**
* Transforms the URL into a hashed version for local storage use.
* @param url The URL to transform.
* @returns A file-system-compatible string.
* @default (url: string) => sha1(url)
*/
transform?: (url: string) => string;
/**
* The folder where the images will be cached.
* @default "cache"
*/
folder?: string;
/**
* Whether to log the output or not.
* @default true
*/
logOutput?: boolean;
}
```
## Full example
```ts
import lume from "https://deno.land/x/lume/mod.ts";
import cacheAssets from "https://deno.land/x/lume_cache_assets@0.0.8/mod.ts";
import md5 from 'npm:md5';
const site = lume();
site.use(cacheAssets({
extensions: [".html"],
shouldCache: (url: string) => url.startsWith("https://") && url.endsWith(".png"),
transform: md5,
folder: "assets/cache",
logOutput: true,
}));
export default site;
```
### wait what's `logOutput`?
glad you asked.

## License
This project is licensed under the [MIT License](./LICENSE).