@flyo/nitro-astro 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/cdn.ts +30 -1
  2. package/package.json +1 -1
package/cdn.ts CHANGED
@@ -5,8 +5,37 @@ import type { ExternalImageService, ImageTransform } from "astro";
5
5
 
6
6
  const service: ExternalImageService = {
7
7
  getURL(options: ImageTransform) {
8
- return `https://https://storage.flyo.cloud/${options.src}/thumb/${options.width}x${options.height}?format=${options.format}`;
8
+
9
+ // check if the options.src contains already https://storage.flyo.cloud
10
+ let url = options.src.includes('https://storage.flyo.cloud') ? options.src : `https://storage.flyo.cloud/${options.src}`
11
+
12
+ // if either width or height are defined we add the /thumb/$widthx$height path to it.
13
+ let width: string | number | null = options.width ? options.width : null;
14
+ let height: string | number | null = options.height ? options.height : null;
15
+
16
+ if (width || height) {
17
+ if (width === null) {
18
+ width = 'null';
19
+ }
20
+ if (height === null) {
21
+ height = 'null';
22
+ }
23
+ url += `/thumb/${width}x${height}`;
24
+ }
25
+
26
+ const format = options.format ? options.format : 'webp';
27
+
28
+ return `${url}?format=${format}`;
9
29
  },
30
+
31
+ getHTMLAttributes(options) {
32
+ const { ...attributes } = options;
33
+ return {
34
+ ...attributes,
35
+ loading: options.loading ?? 'lazy',
36
+ decoding: options.decoding ?? 'async',
37
+ };
38
+ }
10
39
  };
11
40
 
12
41
  export default service;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flyo/nitro-astro",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Astro Framework",
5
5
  "main": "./dist/nitro-astro.js",
6
6
  "module": "./dist/nitro-astro.mjs",