[ci] format
This commit is contained in:
parent
00c605ce35
commit
6f1fbd8be0
16 changed files with 80 additions and 86 deletions
|
@ -1,8 +1,8 @@
|
|||
import type { AstroConfig } from 'astro';
|
||||
import { bgGreen, black, cyan, dim, green } from 'kleur/colors';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import type { AstroConfig } from 'astro';
|
||||
import type { SSRImageService, TransformOptions } from '../loaders/index.js';
|
||||
import { loadLocalImage, loadRemoteImage } from '../utils/images.js';
|
||||
import { debug, info, LoggerLevel, warn } from '../utils/logger.js';
|
||||
|
|
|
@ -8,7 +8,7 @@ import { isRemoteImage } from './utils/paths.js';
|
|||
async function loadRemoteImage(src: URL) {
|
||||
try {
|
||||
const res = await fetch(src);
|
||||
|
||||
|
||||
if (!res.ok) {
|
||||
return undefined;
|
||||
}
|
||||
|
@ -50,4 +50,4 @@ export const get: APIRoute = async ({ request }) => {
|
|||
} catch (err: unknown) {
|
||||
return new Response(`Server Error: ${err}`, { status: 500 });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import type { AstroConfig, AstroIntegration } from 'astro';
|
||||
import { createPlugin } from './vite-plugin-astro-image.js';
|
||||
import { ssgBuild } from './build/ssg.js';
|
||||
import type { ImageService, TransformOptions } from './loaders/index.js';
|
||||
import type { LoggerLevel } from './utils/logger.js';
|
||||
import { joinPaths, prependForwardSlash, propsToFilename } from './utils/paths.js';
|
||||
import { createPlugin } from './vite-plugin-astro-image.js';
|
||||
|
||||
export { getImage } from './lib/get-image.js';
|
||||
export { getPicture } from './lib/get-picture.js';
|
||||
|
@ -111,7 +111,7 @@ export default function integration(options: IntegrationOptions = {}): AstroInte
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/// <reference types="astro/astro-jsx" />
|
||||
import type { ImageService, OutputFormat, TransformOptions } from '../loaders/index.js';
|
||||
import { isSSRService, parseAspectRatio } from '../loaders/index.js';
|
||||
import sharp from '../loaders/sharp.js';
|
||||
import type { ImageService, OutputFormat, TransformOptions } from '../loaders/index.js';
|
||||
import { isRemoteImage } from '../utils/paths.js';
|
||||
import type { ImageMetadata } from '../vite-plugin-astro-image.js';
|
||||
|
||||
|
@ -95,7 +95,7 @@ async function resolveTransform(input: GetImageTransform): Promise<TransformOpti
|
|||
* @param transform @type {TransformOptions} The transformations requested for the optimized image.
|
||||
* @returns @type {ImageAttributes} The HTML attributes to be included on the built `<img />` element.
|
||||
*/
|
||||
export async function getImage(
|
||||
export async function getImage(
|
||||
transform: GetImageTransform
|
||||
): Promise<astroHTML.JSX.ImgHTMLAttributes> {
|
||||
if (!transform.src) {
|
||||
|
@ -151,6 +151,6 @@ async function resolveTransform(input: GetImageTransform): Promise<TransformOpti
|
|||
|
||||
return {
|
||||
...attributes,
|
||||
src
|
||||
src,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
/// <reference types="astro/astro-jsx" />
|
||||
import mime from 'mime';
|
||||
import { extname } from 'node:path';
|
||||
import { OutputFormat, TransformOptions } from '../loaders/index.js';
|
||||
import { parseAspectRatio } from '../loaders/index.js';
|
||||
import { OutputFormat, parseAspectRatio, TransformOptions } from '../loaders/index.js';
|
||||
import { ImageMetadata } from '../vite-plugin-astro-image.js';
|
||||
import { getImage } from './get-image.js';
|
||||
|
||||
|
|
|
@ -7,45 +7,38 @@
|
|||
* Simplified, optimized and add modified for 52 bit, which provides a larger hash space
|
||||
* and still making use of Javascript's 53-bit integer space.
|
||||
*/
|
||||
export const fnv1a52 = (str: string) => {
|
||||
const len = str.length
|
||||
let i = 0,
|
||||
t0 = 0,
|
||||
v0 = 0x2325,
|
||||
t1 = 0,
|
||||
v1 = 0x8422,
|
||||
t2 = 0,
|
||||
v2 = 0x9ce4,
|
||||
t3 = 0,
|
||||
v3 = 0xcbf2
|
||||
export const fnv1a52 = (str: string) => {
|
||||
const len = str.length;
|
||||
let i = 0,
|
||||
t0 = 0,
|
||||
v0 = 0x2325,
|
||||
t1 = 0,
|
||||
v1 = 0x8422,
|
||||
t2 = 0,
|
||||
v2 = 0x9ce4,
|
||||
t3 = 0,
|
||||
v3 = 0xcbf2;
|
||||
|
||||
while (i < len) {
|
||||
v0 ^= str.charCodeAt(i++)
|
||||
t0 = v0 * 435
|
||||
t1 = v1 * 435
|
||||
t2 = v2 * 435
|
||||
t3 = v3 * 435
|
||||
t2 += v0 << 8
|
||||
t3 += v1 << 8
|
||||
t1 += t0 >>> 16
|
||||
v0 = t0 & 65535
|
||||
t2 += t1 >>> 16
|
||||
v1 = t1 & 65535
|
||||
v3 = (t3 + (t2 >>> 16)) & 65535
|
||||
v2 = t2 & 65535
|
||||
}
|
||||
while (i < len) {
|
||||
v0 ^= str.charCodeAt(i++);
|
||||
t0 = v0 * 435;
|
||||
t1 = v1 * 435;
|
||||
t2 = v2 * 435;
|
||||
t3 = v3 * 435;
|
||||
t2 += v0 << 8;
|
||||
t3 += v1 << 8;
|
||||
t1 += t0 >>> 16;
|
||||
v0 = t0 & 65535;
|
||||
t2 += t1 >>> 16;
|
||||
v1 = t1 & 65535;
|
||||
v3 = (t3 + (t2 >>> 16)) & 65535;
|
||||
v2 = t2 & 65535;
|
||||
}
|
||||
|
||||
return (
|
||||
(v3 & 15) * 281474976710656 +
|
||||
v2 * 4294967296 +
|
||||
v1 * 65536 +
|
||||
(v0 ^ (v3 >> 4))
|
||||
)
|
||||
}
|
||||
return (v3 & 15) * 281474976710656 + v2 * 4294967296 + v1 * 65536 + (v0 ^ (v3 >> 4));
|
||||
};
|
||||
|
||||
export const etag = (payload: string, weak = false) => {
|
||||
const prefix = weak ? 'W/"' : '"'
|
||||
return (
|
||||
prefix + fnv1a52(payload).toString(36) + payload.length.toString(36) + '"'
|
||||
)
|
||||
}
|
||||
const prefix = weak ? 'W/"' : '"';
|
||||
return prefix + fnv1a52(payload).toString(36) + payload.length.toString(36) + '"';
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { OutputFormat, TransformOptions } from "../loaders/index.js";
|
||||
import { shorthash } from "./shorthash.js";
|
||||
import { OutputFormat, TransformOptions } from '../loaders/index.js';
|
||||
import { shorthash } from './shorthash.js';
|
||||
|
||||
export function isRemoteImage(src: string) {
|
||||
return /^http(s?):\/\//.test(src);
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import { basename, extname, join } from 'node:path';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { Readable } from 'node:stream';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
import type { AstroConfig } from 'astro';
|
||||
import MagicString from 'magic-string';
|
||||
import type { PluginContext } from 'rollup';
|
||||
import fs from 'node:fs/promises';
|
||||
import path, { basename, extname, join } from 'node:path';
|
||||
import { Readable } from 'node:stream';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
import slash from 'slash';
|
||||
import type { Plugin, ResolvedConfig } from 'vite';
|
||||
import type { IntegrationOptions } from './index.js';
|
||||
|
@ -132,6 +130,6 @@ export function createPlugin(config: AstroConfig, options: Required<IntegrationO
|
|||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ describe('SSG images - dev', function () {
|
|||
let fixture;
|
||||
let devServer;
|
||||
let $;
|
||||
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({ root: './fixtures/basic-image/' });
|
||||
devServer = await fixture.startDevServer();
|
||||
const html = await fixture.fetch('/').then((res) => res.text());
|
||||
$ = cheerio.load(html);
|
||||
const html = await fixture.fetch('/').then((res) => res.text());
|
||||
$ = cheerio.load(html);
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
|
@ -68,7 +68,9 @@ describe('SSG images - dev', function () {
|
|||
expect(searchParams.get('f')).to.equal('webp');
|
||||
expect(searchParams.get('w')).to.equal('544');
|
||||
expect(searchParams.get('h')).to.equal('184');
|
||||
expect(searchParams.get('href')).to.equal('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png');
|
||||
expect(searchParams.get('href')).to.equal(
|
||||
'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -95,12 +97,12 @@ describe('SSG images with subpath - dev', function () {
|
|||
let fixture;
|
||||
let devServer;
|
||||
let $;
|
||||
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({ root: './fixtures/basic-image/', base: '/docs' });
|
||||
devServer = await fixture.startDevServer();
|
||||
const html = await fixture.fetch('/docs/').then((res) => res.text());
|
||||
$ = cheerio.load(html);
|
||||
const html = await fixture.fetch('/docs/').then((res) => res.text());
|
||||
$ = cheerio.load(html);
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
|
@ -155,7 +157,9 @@ describe('SSG images with subpath - dev', function () {
|
|||
expect(searchParams.get('f')).to.equal('webp');
|
||||
expect(searchParams.get('w')).to.equal('544');
|
||||
expect(searchParams.get('h')).to.equal('184');
|
||||
expect(searchParams.get('href')).to.equal('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png');
|
||||
expect(searchParams.get('href')).to.equal(
|
||||
'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -235,9 +239,7 @@ describe('SSG images - build', function () {
|
|||
it('includes <img> attributes', () => {
|
||||
const image = $('#google');
|
||||
|
||||
expect(image.attr('src')).to.equal(
|
||||
`/googlelogo_color_272x92dp_${HASH}.webp`
|
||||
);
|
||||
expect(image.attr('src')).to.equal(`/googlelogo_color_272x92dp_${HASH}.webp`);
|
||||
expect(image.attr('width')).to.equal('544');
|
||||
expect(image.attr('height')).to.equal('184');
|
||||
});
|
||||
|
@ -331,9 +333,7 @@ describe('SSG images with subpath - build', function () {
|
|||
it('includes <img> attributes', () => {
|
||||
const image = $('#google');
|
||||
|
||||
expect(image.attr('src')).to.equal(
|
||||
`/docs/googlelogo_color_272x92dp_${HASH}.webp`
|
||||
);
|
||||
expect(image.attr('src')).to.equal(`/docs/googlelogo_color_272x92dp_${HASH}.webp`);
|
||||
expect(image.attr('width')).to.equal('544');
|
||||
expect(image.attr('height')).to.equal('184');
|
||||
});
|
||||
|
|
|
@ -10,7 +10,7 @@ describe('SSR images - build', function () {
|
|||
fixture = await loadFixture({
|
||||
root: './fixtures/basic-image/',
|
||||
adapter: testAdapter({ streaming: false }),
|
||||
output: 'server'
|
||||
output: 'server',
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
@ -154,7 +154,7 @@ describe('SSR images with subpath - build', function () {
|
|||
root: './fixtures/basic-image/',
|
||||
adapter: testAdapter({ streaming: false }),
|
||||
output: 'server',
|
||||
base: '/docs'
|
||||
base: '/docs',
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
@ -232,7 +232,9 @@ describe('SSR images with subpath - build', function () {
|
|||
expect(searchParams.get('f')).to.equal('webp');
|
||||
expect(searchParams.get('w')).to.equal('544');
|
||||
expect(searchParams.get('h')).to.equal('184');
|
||||
expect(searchParams.get('href')).to.equal('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png');
|
||||
expect(searchParams.get('href')).to.equal(
|
||||
'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps remote image query params', async () => {
|
||||
|
|
|
@ -147,7 +147,7 @@ describe('SSR images with subpath - dev', function () {
|
|||
root: './fixtures/basic-image/',
|
||||
adapter: testAdapter(),
|
||||
output: 'server',
|
||||
base: '/docs'
|
||||
base: '/docs',
|
||||
});
|
||||
|
||||
devServer = await fixture.startDevServer();
|
||||
|
|
|
@ -95,7 +95,9 @@ describe('SSG pictures - dev', function () {
|
|||
expect(searchParams.get('f')).to.equal('png');
|
||||
expect(searchParams.get('w')).to.equal('544');
|
||||
expect(searchParams.get('h')).to.equal('184');
|
||||
expect(searchParams.get('href')).to.equal('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png');
|
||||
expect(searchParams.get('href')).to.equal(
|
||||
'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'
|
||||
);
|
||||
expect(image.attr('alt')).to.equal('Google logo');
|
||||
});
|
||||
});
|
||||
|
@ -217,7 +219,9 @@ describe('SSG pictures with subpath - dev', function () {
|
|||
expect(searchParams.get('f')).to.equal('png');
|
||||
expect(searchParams.get('w')).to.equal('544');
|
||||
expect(searchParams.get('h')).to.equal('184');
|
||||
expect(searchParams.get('href')).to.equal('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png');
|
||||
expect(searchParams.get('href')).to.equal(
|
||||
'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'
|
||||
);
|
||||
expect(image.attr('alt')).to.equal('Google logo');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -192,7 +192,7 @@ describe('SSR pictures with subpath - build', function () {
|
|||
root: './fixtures/basic-picture/',
|
||||
adapter: testAdapter(),
|
||||
output: 'server',
|
||||
base: '/docs'
|
||||
base: '/docs',
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
|
|
@ -165,7 +165,7 @@ describe('SSR pictures with subpath - dev', function () {
|
|||
root: './fixtures/basic-picture/',
|
||||
adapter: testAdapter(),
|
||||
output: 'server',
|
||||
base: '/docs'
|
||||
base: '/docs',
|
||||
});
|
||||
|
||||
devServer = await fixture.startDevServer();
|
||||
|
|
|
@ -39,7 +39,7 @@ describe('Image rotation', function () {
|
|||
'/Landscape_5.6d88c17f_ZtLntP.jpg',
|
||||
'/Landscape_6.1a88f6d8_Z1Pl4xy.jpg',
|
||||
'/Landscape_7.cb1008c2_Z1JYr40.jpg',
|
||||
'/Landscape_8.3d2837d2_1xTOBN.jpg'
|
||||
'/Landscape_8.3d2837d2_1xTOBN.jpg',
|
||||
];
|
||||
|
||||
it('includes <img> attributes', () => {
|
||||
|
@ -73,7 +73,7 @@ describe('Image rotation', function () {
|
|||
'/Portrait_5.b3b6cc6f_Z23Ek26.jpg',
|
||||
'/Portrait_6.94e06390_ak2Ek.jpg',
|
||||
'/Portrait_7.9ffdecfe_Z1S4klG.jpg',
|
||||
'/Portrait_8.9d01343d_2dak03.jpg'
|
||||
'/Portrait_8.9d01343d_2dak03.jpg',
|
||||
];
|
||||
|
||||
it('includes <img> attributes', () => {
|
||||
|
|
|
@ -61,9 +61,7 @@ describe('Images in MDX - build', function () {
|
|||
it('includes <img> attributes', () => {
|
||||
const image = $('#google');
|
||||
|
||||
expect(image.attr('src')).to.equal(
|
||||
`/googlelogo_color_272x92dp_${HASH}.webp`
|
||||
);
|
||||
expect(image.attr('src')).to.equal(`/googlelogo_color_272x92dp_${HASH}.webp`);
|
||||
expect(image.attr('width')).to.equal('544');
|
||||
expect(image.attr('height')).to.equal('184');
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue