fix(gallery): invalid source
This commit is contained in:
parent
0167f90326
commit
4ea00d1af6
@ -35,7 +35,7 @@ export const NoteRender = ({ content }: NoteRenderProps) => {
|
|||||||
slide: 1
|
slide: 1
|
||||||
})
|
})
|
||||||
const slides = useMemo(() => {
|
const slides = useMemo(() => {
|
||||||
const urls: string[] = []
|
const sources: { url: string; type: 'image' | 'video' | 'youtube' }[] = []
|
||||||
const parts = content.matchAll(new RegExp(`${link.source}`, 'gui'))
|
const parts = content.matchAll(new RegExp(`${link.source}`, 'gui'))
|
||||||
;[...parts]
|
;[...parts]
|
||||||
.filter((p) => typeof p !== 'undefined')
|
.filter((p) => typeof p !== 'undefined')
|
||||||
@ -43,18 +43,23 @@ export const NoteRender = ({ content }: NoteRenderProps) => {
|
|||||||
const [href] = part
|
const [href] = part
|
||||||
|
|
||||||
if (href && isValidUrl(href)) {
|
if (href && isValidUrl(href)) {
|
||||||
if (isValidImageUrl(href) || isValidVideoUrl(href)) {
|
if (isValidImageUrl(href)) {
|
||||||
urls.push(href)
|
sources.push({ url: href, type: 'image' })
|
||||||
|
} else if (isValidVideoUrl(href)) {
|
||||||
|
sources.push({ url: href, type: 'video' })
|
||||||
} else if (isYoutubeLink(href)) {
|
} else if (isYoutubeLink(href)) {
|
||||||
const id = getIdFromYoutubeLink(href)
|
const id = getIdFromYoutubeLink(href)
|
||||||
if (id) {
|
if (id) {
|
||||||
urls.push(`https://www.youtube.com/embed/${id}`)
|
sources.push({
|
||||||
|
url: `https://www.youtube.com/embed/${id}`,
|
||||||
|
type: 'youtube'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return urls
|
return sources
|
||||||
}, [content])
|
}, [content])
|
||||||
|
|
||||||
const openLightBoxOnSlide = useCallback(
|
const openLightBoxOnSlide = useCallback(
|
||||||
@ -62,7 +67,7 @@ export const NoteRender = ({ content }: NoteRenderProps) => {
|
|||||||
slides.length &&
|
slides.length &&
|
||||||
setLightBoxController((prev) => ({
|
setLightBoxController((prev) => ({
|
||||||
toggler: !prev.toggler,
|
toggler: !prev.toggler,
|
||||||
slide: slides.findIndex((s) => s === url) + 1
|
slide: slides.findIndex((s) => s.url === url) + 1
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
[slides]
|
[slides]
|
||||||
@ -184,7 +189,8 @@ export const NoteRender = ({ content }: NoteRenderProps) => {
|
|||||||
createPortal(
|
createPortal(
|
||||||
<FsLightbox
|
<FsLightbox
|
||||||
toggler={lightBoxController.toggler}
|
toggler={lightBoxController.toggler}
|
||||||
sources={slides}
|
sources={slides.map((s) => s.url)}
|
||||||
|
types={slides.map((s) => s.type)}
|
||||||
slide={lightBoxController.slide}
|
slide={lightBoxController.slide}
|
||||||
/>,
|
/>,
|
||||||
document.body
|
document.body
|
||||||
|
Loading…
x
Reference in New Issue
Block a user