Coworkerを使用してユニバーサルエディターで画像の更新を許可するようにサイトスクリプトを設定します universal-editor-image-update-coworker
コンテンツ作成者は、ユニバーサルエディター🔗内の同僚を使用して、選択したコンポーネント内の画像を検索および置換できます。 Coworkerは、選択したコンポーネントをAEM Assets配信URLで更新します。
この機能を使用するには、サイトのクライアントサイドスクリプトを更新する必要があります。 これらの変更は、AEM Assets配信URLがEdge Delivers Services サイトで画像としてレンダリングするために必要です。
サイトスクリプトの設定 configure
Edge Delivery Services sitesでは、クライアントサイドスクリプトを使用して、ページコンテンツのレンダリング方法を制御します。 次の変更点をサイトのスクリプトに追加して、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);
});
}
decorateLinkedPicturesをdecorateMain()の最初の行として呼び出します:
export function decorateMain(main) {
decorateLinkedPictures(main);
decorateIcons(main);
buildAutoBlocks(main);
decorateSections(main);
decorateBlocks(main);
decorateButtons(main);
}
scripts/editor-support.jsでの画像の更新を処理 handle-updates
decorateLinkedPicturesをscripts.jsからインポート:
import { decorateButtons, decorateMain, decorateLinkedPictures } from './scripts.js';
applyChanges()で、更新されたコンテンツをデコレートする前にdecorateLinkedPicturesに電話します。
- ブロック分岐:
decorateButtons(newBlock)の前にdecorateLinkedPictures(newBlock)を呼び出します。 - セクション分岐:
decorateButtons(newSection)の前にdecorateLinkedPictures(newSection)を呼び出します。 - Default-content ブランチ:
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を使用して、選択したコンポーネント内の画像を検索して置換できます。