Coworker를 사용하여 범용 편집기에서 이미지 업데이트를 허용하도록 사이트 스크립트 구성 universal-editor-image-update-coworker
콘텐츠 작성자는 범용 편집기 🔗에서 Coworker를 사용하여 선택한 구성 요소에서 이미지를 찾아 바꿀 수 있습니다. 동료는 선택한 구성 요소를 AEM Assets 게재 URL로 업데이트합니다.
이 기능을 사용하려면 사이트의 클라이언트측 스크립트를 업데이트해야 합니다. 이러한 변경 사항은 Edge Delivers Services 사이트에서 AEM Assets 게재 URL을 이미지로 렌더링하는 데 필요합니다.
사이트 스크립트 구성 configure
Edge Delivery Services 사이트는 클라이언트측 스크립트를 사용하여 페이지 콘텐츠가 렌더링되는 방법을 제어합니다. AEM Assets 게재 URL이 이미지로 렌더링되도록 Coworker에서 이미지를 업데이트할 때를 포함하여 사이트의 스크립트에 다음 변경 사항을 추가합니다.
scripts/scripts.js에서 연결된 이미지 렌더링 render-images
scripts/scripts.js에 다음 함수를 추가하십시오.
const IMAGE_HREF_RE = /\.(?:avif|webp|png|jpe?g|gif|svg)$/i;
export function decorateLinkedPictures(container) {
container.querySelectorAll('a[href]').forEach((link) => {
const href = link.getAttribute('href');
const url = new URL(href, window.location.href);
if (!IMAGE_HREF_RE.test(url.pathname)) return;
const text = link.textContent.trim();
const picture = document.createElement('picture');
const img = document.createElement('img');
img.src = url.href;
img.alt = text === href || text === url.href ? '' : text;
img.loading = 'lazy';
picture.append(img);
moveInstrumentation(link, img);
link.replaceWith(picture);
});
}
decorateMain()의 첫 번째 줄로 decorateLinkedPictures을(를) 호출합니다.
export function decorateMain(main) {
decorateLinkedPictures(main);
decorateIcons(main);
buildAutoBlocks(main);
decorateSections(main);
decorateBlocks(main);
decorateButtons(main);
}
scripts/editor-support.js에서 이미지 업데이트 처리 handle-updates
scripts.js에서 decorateLinkedPictures 가져오기:
import { decorateButtons, decorateMain, decorateLinkedPictures } from './scripts.js';
applyChanges()에서 업데이트된 콘텐츠를 장식하기 전에 decorateLinkedPictures을(를) 호출하십시오.
- 분기 차단:
decorateButtons(newBlock)전에decorateLinkedPictures(newBlock)을(를) 호출합니다. - 섹션 분기:
decorateButtons(newSection)전에decorateLinkedPictures(newSection)을(를) 호출합니다. - 기본 콘텐츠 분기:
element.replaceWith(...newElements)전에newElements.forEach((el) => decorateLinkedPictures(el))을(를) 호출합니다.
AEM Assets 게재 URL 유지 preserve-urls
createOptimizedPicture을(를) 통해 이미지를 전달하는 블록은 다른 원본에서 제공된 이미지를 건너뛰어야 합니다. 사이트에서 AEM Assets 전달 계층 URL의 크기를 조정할 수 없습니다.
예를 들어 blocks/cards/cards.js에서 다음과 같이 이미지 처리 코드를 업데이트합니다.
ul.querySelectorAll('picture > img').forEach((img) => {
if (new URL(img.src, window.location.href).origin !== window.location.origin) return;
const optimizedPic = createOptimizedPicture(img.src, img.alt, false, [{ width: '750' }]);
moveInstrumentation(img, optimizedPic.querySelector('img'));
img.closest('picture').replaceWith(optimizedPic);
});
작성된 이미지에서 createOptimizedPicture을(를) 호출하는 모든 사용자 지정 블록에 동일한 원본 검사를 적용합니다.
동료를 사용하여 이미지 찾기 및 바꾸기 use-integration
필요한 단계를 완료했으므로 콘텐츠 작성자는 범용 편집기 사이드 패널에서 Coworker를 사용하여 선택한 구성 요소에서 이미지를 찾아 바꿀 수 있습니다.