-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from e3stpavel/works
Fixed 'works' endpoint by adding '.json' extension
- Loading branch information
Showing
3 changed files
with
40 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { APIRoute } from 'astro' | ||
import { getImage } from 'astro:assets' | ||
|
||
export const GET: APIRoute = async () => { | ||
const productsImages = import.meta.glob<{ default: ImageMetadata }>([ | ||
'/src/assets/products/**/*.{jpeg,jpg,png}', | ||
'!**/og/**/*.{jpeg,jpg,png}', | ||
'!**/fallback.png', | ||
'!**/works/*.{jpeg,jpg,png}', | ||
], { eager: true }) | ||
|
||
const worksImages = import.meta.glob<{ default: ImageMetadata }>( | ||
'/src/assets/products/works/*.{jpeg,jpg,png}', | ||
{ eager: true }, | ||
) | ||
|
||
// resolve only unused images | ||
const resolved = await Promise.all( | ||
Object.values(worksImages).map( | ||
async ({ default: src }) => await getImage({ src }), | ||
), | ||
) | ||
|
||
return new Response( | ||
JSON.stringify([ | ||
...Object.values(productsImages) | ||
.map(({ default: { src, width, height } }) => ({ | ||
src, | ||
attributes: { | ||
width, | ||
height, | ||
loading: 'lazy', | ||
decoding: 'async', | ||
}, | ||
})), | ||
...resolved.map(({ src, attributes }) => ({ src, attributes })), | ||
]), | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.