본문 이미지 최적화·라이트박스·번호형 페이지네이션 반영 (v1.10.3)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,4 +1,28 @@
|
||||
const postCardThumbnailUrlPattern = /^\/uploads\/posts\/\d{4}\/\d{2}\/thumbs\/[^/?#]+-card\.webp$/i
|
||||
const postBodyThumbnailUrlPattern = /^\/uploads\/posts\/\d{4}\/\d{2}\/thumbs\/[^/?#]+-body\.webp$/i
|
||||
const postUploadImageUrlPattern = /^\/uploads\/posts\/\d{4}\/\d{2}\/[^/?#]+\.(?:jpe?g|png|webp)$/i
|
||||
|
||||
/**
|
||||
* 게시물 원본 이미지 URL에 대응하는 파생 이미지 URL을 만든다.
|
||||
* @param {string|null|undefined} imageUrl - 원본 이미지 URL
|
||||
* @param {'body'} kind - 파생 이미지 종류
|
||||
* @returns {string} 파생 이미지 URL
|
||||
*/
|
||||
const getPostDerivativeImageUrl = (imageUrl, kind) => {
|
||||
const normalizedUrl = String(imageUrl || '')
|
||||
|
||||
if (!postUploadImageUrlPattern.test(normalizedUrl)) {
|
||||
return ''
|
||||
}
|
||||
|
||||
const slashIndex = normalizedUrl.lastIndexOf('/')
|
||||
const directory = slashIndex >= 0 ? normalizedUrl.slice(0, slashIndex) : ''
|
||||
const fileName = slashIndex >= 0 ? normalizedUrl.slice(slashIndex + 1) : normalizedUrl
|
||||
const dotIndex = fileName.lastIndexOf('.')
|
||||
const stem = dotIndex >= 0 ? fileName.slice(0, dotIndex) : fileName
|
||||
|
||||
return `${directory}/thumbs/${stem}-${kind}.webp`
|
||||
}
|
||||
|
||||
/**
|
||||
* 게시물 카드 썸네일 URL인지 확인한다.
|
||||
@@ -8,3 +32,19 @@ const postCardThumbnailUrlPattern = /^\/uploads\/posts\/\d{4}\/\d{2}\/thumbs\/[^
|
||||
export const isPostCardThumbnailUrl = (imageUrl) => Boolean(
|
||||
imageUrl && postCardThumbnailUrlPattern.test(String(imageUrl))
|
||||
)
|
||||
|
||||
/**
|
||||
* 게시물 본문 표시용 파생 이미지 URL인지 확인한다.
|
||||
* @param {string|null|undefined} imageUrl - 검사할 이미지 URL
|
||||
* @returns {boolean} 본문 표시용 파생 이미지 여부
|
||||
*/
|
||||
export const isPostBodyThumbnailUrl = (imageUrl) => Boolean(
|
||||
imageUrl && postBodyThumbnailUrlPattern.test(String(imageUrl))
|
||||
)
|
||||
|
||||
/**
|
||||
* 게시물 원본 이미지 URL에 대응하는 본문 표시용 이미지 URL을 만든다.
|
||||
* @param {string|null|undefined} imageUrl - 원본 이미지 URL
|
||||
* @returns {string} 본문 표시용 파생 이미지 URL
|
||||
*/
|
||||
export const getPostBodyThumbnailUrl = (imageUrl) => getPostDerivativeImageUrl(imageUrl, 'body')
|
||||
|
||||
Reference in New Issue
Block a user