Skip to content

Commit 1f43e6c

Browse files
committed
fix: images grids
Signed-off-by: Innei <[email protected]>
1 parent 2a393b7 commit 1f43e6c

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

src/components/ui/markdown/customize.md

+22
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,28 @@ https://loremflickr.com/640/480/city?3
184184
![](https://loremflickr.com/640/480/city?4)
185185
:::
186186

187+
```
188+
::: grid {cols=3,rows=2,gap=12,type=images}
189+
![](https://loremflickr.com/640/480/city?4)
190+
![](https://loremflickr.com/640/480/city?4)
191+
![](https://loremflickr.com/640/480/city?4)
192+
![](https://loremflickr.com/640/480/city?4)
193+
![](https://loremflickr.com/640/480/city?4)
194+
![](https://loremflickr.com/640/480/city?4)
195+
:::
196+
197+
```
198+
199+
::: grid {cols=3,rows=2,gap=12,type=images}
200+
![](https://loremflickr.com/640/480/city?4)
201+
![](https://loremflickr.com/640/480/city?4)
202+
![](https://loremflickr.com/640/480/city?4)
203+
![](https://loremflickr.com/640/480/city?4)
204+
![](https://loremflickr.com/640/480/city?4)
205+
![](https://loremflickr.com/640/480/city?4)
206+
:::
207+
208+
187209

188210
## Rich Link
189211

src/components/ui/markdown/parsers/container.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export const ContainerRule: MarkdownToJSX.Rule = {
143143

144144
return (
145145
<GridMarkdownImages
146+
height={rows && cols ? +rows / +cols : 1}
146147
key={state.key}
147148
imagesSrc={imagesSrc}
148149
Wrapper={Grid}

src/components/ui/markdown/renderers/image.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,15 @@ export const GridMarkdownImage = (props: any) => {
5656
export const GridMarkdownImages: FC<{
5757
imagesSrc: string[]
5858
Wrapper: Component
59-
}> = ({ imagesSrc, Wrapper }) => {
59+
height: number
60+
}> = ({ imagesSrc, Wrapper, height = 1 }) => {
6061
return (
61-
<div className="relative pb-[100%]">
62+
<div
63+
className="relative"
64+
style={{
65+
paddingBottom: `${height * 100}%`,
66+
}}
67+
>
6268
<Wrapper className="absolute inset-0">
6369
{imagesSrc.map((src) => {
6470
return <GridZoomImage key={src} src={src} />

src/lib/image.ts

+8-17
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,16 @@ export function getDominantColor(imageObject: HTMLImageElement) {
4040
.slice(1)}`
4141
}
4242

43-
export const addImageUrlCropSizeQuery = (url: string, size: number) => {
44-
const parsedUrl = new URL(url)
45-
46-
// Tencent Cloud 数据万象
47-
// ?imageMogr2/thumbnail/300x/crop/300x300/gravity/center
48-
parsedUrl.searchParams.set(
49-
`imageMogr2/thumbnail/${size}x/crop/${size}x${size}/gravity/center/strip`,
50-
'',
51-
)
52-
53-
return parsedUrl.toString().replace(/=$/, '')
54-
}
55-
43+
const TENCENT_CDN_DOMAIN = 'cdn.innei.ren'
5644
export const addImageUrlResizeQuery = (url: string, size: number) => {
5745
const parsedUrl = new URL(url)
5846

59-
// Tencent Cloud 数据万象
60-
// ?imageMogr2/thumbnail/300x
61-
parsedUrl.searchParams.set(`imageMogr2/thumbnail/${size}x/strip`, '')
47+
if (parsedUrl.host === TENCENT_CDN_DOMAIN) {
48+
// Tencent Cloud 数据万象
49+
// ?imageMogr2/thumbnail/300x
50+
51+
return `${url}?imageMogr2/thumbnail/${size}x/strip`
52+
}
6253

63-
return parsedUrl.toString().replace(/=$/, '')
54+
return url
6455
}

0 commit comments

Comments
 (0)