공개 Markdown 본문 fragment 주석을 줄이도록 렌더링 구조 정리 (v1.10.4)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-01 17:01:14 +09:00
parent c686b1c848
commit 943794ae34
9 changed files with 144 additions and 22 deletions

View File

@@ -963,8 +963,6 @@ const inArticleAdAfterBlockIds = computed(() => {
.map((item) => item.block.id)
})
const inArticleAdAfterBlockIdSet = computed(() => new Set(inArticleAdAfterBlockIds.value))
const headingIdsByBlock = computed(() => {
const createHeadingId = createHeadingIdFactory()
const ids = {}
@@ -978,6 +976,39 @@ const headingIdsByBlock = computed(() => {
return ids
})
/**
* 공개 본문 렌더링용 블록 목록을 반환한다.
* 인아티클 광고는 별도 v-if 대신 블록으로 삽입해 fragment 주석을 줄인다.
* @returns {Array<Object>} 렌더링 블록 목록
*/
const renderBlocks = computed(() => {
const sourceBlocks = blocks.value
const adAfterBlockIds = inArticleAdAfterBlockIds.value
if (props.interactive || !adAfterBlockIds.length) {
return sourceBlocks
}
const adAfterIdSet = new Set(adAfterBlockIds)
const result = []
for (const block of sourceBlocks) {
result.push(block)
if (adAfterIdSet.has(block.id)) {
result.push({
id: `in-article-ad-after-${block.id}`,
type: 'in-article-ad',
meta: {
afterBlockId: block.id
}
})
}
}
return result
})
/** @type {import('vue').ComputedRef<number>} 문서 맨 아래 단일 이미지 삽입 줄 */
const tailInsertBeforeLine = computed(() => {
const lastBlock = blocks.value[blocks.value.length - 1]
@@ -3040,15 +3071,16 @@ onBeforeUnmount(() => {
@focusout.capture="emitLiveLineBlur"
@keydown.capture="onRendererSelectionKeydown"
>
<template v-for="block in blocks" :key="block.id">
<div
v-if="interactive && getBlockInsertBeforeLine(block) !== null"
class="content-markdown-renderer__block-insert"
:class="{ 'content-markdown-renderer__block-insert--active': blockInsertDropTarget?.insertBeforeLine === getBlockInsertBeforeLine(block) }"
@dragover="onBlockInsertDragOver($event, block)"
@dragleave="onBlockInsertDragLeave"
@drop="onBlockInsertDrop($event, block)"
/>
<ContentMarkdownBlockGroup
v-for="block in renderBlocks"
:key="block.id"
:interactive="interactive"
:show-insert="getBlockInsertBeforeLine(block) !== null"
:insert-active="blockInsertDropTarget?.insertBeforeLine === getBlockInsertBeforeLine(block)"
@dragover="onBlockInsertDragOver($event, block)"
@dragleave="onBlockInsertDragLeave"
@drop="onBlockInsertDrop($event, block)"
>
<ContentMarkdownEditableInline
v-if="block.type === 'spacer' && interactive"
tag="p"
@@ -3509,14 +3541,13 @@ onBeforeUnmount(() => {
<p v-else-if="block.type === 'paragraph'" class="content-markdown-renderer__paragraph mb-2.5 text-base text-[var(--site-text)] last:mb-0">
<ContentMarkdownInlineSegments :text="block.text" multiline />
</p>
<SiteAdSlot
v-if="inArticleAdAfterBlockIdSet.has(block.id)"
v-else-if="block.type === 'in-article-ad'"
class="content-markdown-renderer__in-article-ad my-8"
:code="normalizedInArticleAdCode"
location="post-in-article"
/>
</template>
</ContentMarkdownBlockGroup>
<div
v-if="interactive"