대표 이미지 원본 선택 보강 v1.7.9
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { z } from 'zod'
|
||||
import { ADMIN_POST_PLACEHOLDER_TITLE } from '../../lib/admin-post-title.js'
|
||||
import { normalizeMarkdownContent } from '../../lib/markdown-content-normalizer.js'
|
||||
import { isPostCardThumbnailUrl } from '../../lib/post-card-thumbnail-url.js'
|
||||
import { postStatusSchema } from './content-schema.js'
|
||||
|
||||
export const adminPostInputSchema = z.object({
|
||||
@@ -11,7 +12,11 @@ export const adminPostInputSchema = z.object({
|
||||
slug: z.string().trim().min(1).regex(/^[a-z0-9가-힣]+(?:-[a-z0-9가-힣]+)*$/),
|
||||
content: z.preprocess(normalizeMarkdownContent, z.string()).default(''),
|
||||
excerpt: z.string().default(''),
|
||||
featuredImage: z.string().trim().nullable().default(null),
|
||||
featuredImage: z.string()
|
||||
.trim()
|
||||
.nullable()
|
||||
.default(null)
|
||||
.refine((value) => !isPostCardThumbnailUrl(value), '카드 썸네일은 대표 이미지로 사용할 수 없습니다.'),
|
||||
showFeaturedImage: z.boolean().default(false),
|
||||
isFeatured: z.boolean().default(false),
|
||||
seoTitle: z.string().trim().default(''),
|
||||
|
||||
@@ -2,13 +2,15 @@ import { existsSync } from 'node:fs'
|
||||
import { mkdir, stat } from 'node:fs/promises'
|
||||
import { dirname, extname, join, posix } from 'node:path'
|
||||
import sharp from 'sharp'
|
||||
import { isPostCardThumbnailUrl } from '../../lib/post-card-thumbnail-url.js'
|
||||
|
||||
export { isPostCardThumbnailUrl }
|
||||
|
||||
export const POST_THUMBNAIL_WIDTH = 640
|
||||
export const POST_THUMBNAIL_HEIGHT = 360
|
||||
export const POST_THUMBNAIL_QUALITY = 82
|
||||
|
||||
const postUploadUrlPattern = /^\/uploads\/posts\/\d{4}\/\d{2}\/[^/?#]+$/i
|
||||
const postThumbnailUrlPattern = /^\/uploads\/posts\/\d{4}\/\d{2}\/thumbs\/[^/?#]+-card\.webp$/i
|
||||
const postThumbnailDirectoryName = 'thumbs'
|
||||
const postThumbnailSuffix = '-card'
|
||||
const postThumbnailExtension = '.webp'
|
||||
@@ -75,13 +77,6 @@ export const getPostThumbnailUrl = (imageUrl) => {
|
||||
return `${directory}/${postThumbnailDirectoryName}/${getPostThumbnailFileName(fileName)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 게시물 카드 썸네일 URL인지 확인한다.
|
||||
* @param {string|null|undefined} imageUrl - 검사할 이미지 URL
|
||||
* @returns {boolean} 카드 썸네일 여부
|
||||
*/
|
||||
export const isPostCardThumbnailUrl = (imageUrl) => Boolean(imageUrl && postThumbnailUrlPattern.test(imageUrl))
|
||||
|
||||
/**
|
||||
* 게시물 카드 썸네일 URL의 디스크 경로를 조회한다.
|
||||
* @param {string} imageUrl - 원본 이미지 URL
|
||||
|
||||
Reference in New Issue
Block a user