Skip to content

Commit 3a84e18

Browse files
committed
chore: updated images process
1 parent 6062419 commit 3a84e18

File tree

565 files changed

+447
-54
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

565 files changed

+447
-54
lines changed

.eslintcache

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

app/components/ProxiedPrismicImage.vue

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
* Adapted from https://github.com/prismicio/prismic-vue/blob/68a8be98a79c4627f83ca33735f07668329fe1e3/src/PrismicImage.vue
99
*/
1010
11-
import type { PrismicImageProps } from '@prismicio/vue'
11+
import type { FilledImageFieldImage } from '@prismicio/client'
1212
13-
import { asImagePixelDensitySrcSet, asImageWidthSrcSet, isFilled } from '@prismicio/client'
13+
import type { PrismicImageProps } from '@prismicio/vue'
14+
import { asImagePixelDensitySrcSet, asImageWidthSrcSet } from '@prismicio/client'
1415
1516
const props = defineProps<PrismicImageProps>()
1617
const { fallbackAlt, field, widths, alt, pixelDensities, imgixParams } = props
@@ -42,18 +43,15 @@ function castInt(input: string | number | undefined): number | undefined {
4243
return Number.isNaN(parsed) ? undefined : parsed
4344
}
4445
45-
if (!isFilled.imageThumbnail(field))
46-
throw new Error('Image is not filled')
47-
48-
// Transform field to use local paths
49-
const localField = transformResponsiveImageFieldToLocal(field)
46+
const { baseUrl } = useRuntimeConfig().public
47+
const localField = transformResponsiveImageFieldToLocal(baseUrl, field)
5048
5149
// asImageWidthSrcSet requires full URLs, so we use a dummy domain
5250
const DUMMY_DOMAIN = 'https://localhost'
5351
const tempField = {
5452
...localField,
5553
url: `${DUMMY_DOMAIN}${localField.url}`,
56-
}
54+
} as FilledImageFieldImage
5755
5856
// Transform responsive variants to use dummy domain for srcSet generation
5957
const responsiveViews = ['Lg', 'Md', 'Sm', 'Xs'] as const
@@ -90,13 +88,13 @@ else if (pixelDensities) {
9088
}
9189
}
9290
93-
const ar = field.dimensions.width / field.dimensions.height
91+
const ar = field.dimensions ? field.dimensions.width / field.dimensions.height : 1
9492
9593
const castedWidth = castInt(width)
9694
const castedHeight = castInt(height)
9795
98-
let resolvedWidth = castedWidth ?? field.dimensions.width
99-
let resolvedHeight = castedHeight ?? field.dimensions.height
96+
let resolvedWidth = castedWidth ?? field.dimensions?.width
97+
let resolvedHeight = castedHeight ?? field.dimensions?.height
10098
10199
if (castedWidth != null && castedHeight == null)
102100
resolvedHeight = castedWidth / ar
@@ -107,12 +105,9 @@ const image = {
107105
src,
108106
srcSet,
109107
alt: alt ?? (field.alt || fallbackAlt),
110-
width: Math.round(resolvedWidth),
111-
height: Math.round(resolvedHeight),
108+
width: resolvedWidth ? Math.round(resolvedWidth) : undefined,
109+
height: resolvedHeight ? Math.round(resolvedHeight) : undefined,
112110
}
113-
114-
// Images are now downloaded during build time by the crawler
115-
// This component only handles URL transformation to local paths
116111
</script>
117112

118113
<template>

app/slices/ExchangesGrid/index.vue

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,30 @@ import type { Content } from '@prismicio/client'
33
44
defineProps(getSliceComponentProps<Content.ExchangesGridSlice>())
55
6-
const { data: exchanges } = await useFetch('/api/exchanges')
6+
const { client } = usePrismic()
7+
const { data: exchanges } = await useAsyncData(`exchanges`, async () => {
8+
try {
9+
return await client.getAllByType('exchange').then(res => res.map(r => r.data))
10+
}
11+
catch (error) {
12+
console.error(`Exchanges not found:`, error)
13+
throw createError({ statusCode: 404, statusMessage: 'Exchanges not found', fatal: true })
14+
}
15+
}, {
16+
server: true,
17+
})
718
</script>
819

920
<template>
1021
<section bg-neutral-0 pt-0="!">
1122
<ul grid="~ cols-[repeat(auto-fit,minmax(200px,368px))] gap-16 justify-center">
1223
<li v-for="({ link, logo, name }, i) in exchanges" :key="i">
13-
<NuxtLink external :to="link" flex="~ row items-center gap-x-16" nq-hoverable target="_blank">
24+
<PrismicLink :field="link" flex="~ row items-center gap-x-16" nq-hoverable target="_blank">
1425
<ProxiedPrismicImage :field="logo!" h-full w-40 object-contain flex="~ items-center" />
1526
<h3 font-semibold f-text-xl>
1627
{{ name }}
1728
</h3>
18-
</NuxtLink>
29+
</PrismicLink>
1930
</li>
2031
</ul>
2132
</section>

lib/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ console.table({
8989
'GitHub Pages': isGitHubPages ? 'yes' : 'no',
9090
'Production': isProduction ? 'yes' : 'no',
9191
'Local': isLocal ? 'yes' : 'no',
92+
'Base URL': process.env.NUXT_PUBLIC_BASE_URL || '/',
9293
})
9394

9495
export default {

modules/image-downloader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ async function downloadImages(): Promise<void> {
4545

4646
console.warn(`🔍 Analyzing ${data.allImages.length} unique Prismic images...`)
4747

48-
const status = await analyzeImageSync(data.allImages)
48+
const { baseUrl } = useRuntimeConfig().public
49+
const status = await analyzeImageSync(baseUrl, data.allImages)
4950
logImageSyncStatus(status)
5051

5152
let manifest: Record<string, string[]> = {}

nuxt.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export default defineNuxtConfig({
165165
allowedOrigins: ['https://www.nimiq.com', 'https://prestaking.nimiq.network', process.env.NIMIQ_STATIC_PREVIEW].filter(Boolean) as string[],
166166
},
167167
public: {
168+
baseUrl: process.env.NUXT_PUBLIC_BASE_URL || '/',
168169
clientNetwork: 'main-albatross',
169170
apiDomain: process.env.NUXT_PUBLIC_API_ENDPOINT || '',
170171
validatorsApi: process.env.NUXT_PUBLIC_VALIDATORS_API || 'https://validators-api-mainnet.nuxt.dev',
@@ -201,6 +202,7 @@ export default defineNuxtConfig({
201202
allowedOrigins: array(string()),
202203
}),
203204
public: object({
205+
baseUrl: string(),
204206
clientNetwork: optional(string()),
205207
apiDomain: string(),
206208
validatorsApi: optional(string()),

0 commit comments

Comments
 (0)