1import { getConfigValue } from './baici/utils/config.js'; 2import { makeDeliveryPath } from './baici/utils/utils.js'; 3 4const PREVIEW_META_NAME = 'urn:adobe:aue:config:preview'; 5 6/** 7 * Normalizes an AEM content path to a delivery-relative path for preview URLs. 8 * @param {string} aemPath 9 * @returns {string} 10 */ 11export function resolvePreviewDeliveryPath(aemPath) { 12 const normalized = makeDeliveryPath(aemPath.replace(/\.html$/, '')); 13 if (!normalized || normalized === '/index') return '/'; 14 return normalized.startsWith('/') ? normalized : `/${normalized}`; 15} 16 17/** 18 * Builds the full Universal Editor preview URL from the config base URL. 19 * @param {string} previewBase 20 * @param {string} aemPath 21 * @returns {string} 22 */ 23export function buildUePreviewUrl(previewBase, aemPath) { 24 const base = previewBase.trim().replace(/\/$/, ''); 25 return `${base}${resolvePreviewDeliveryPath(aemPath)}`; 26} 27 28/** 29 * Sets the Universal Editor preview meta tag consumed by the Open Page button. 30 * @param {string} previewUrl 31 */ 32export function setUePreviewMeta(previewUrl) { 33 let meta = document.querySelector(`meta[name="${PREVIEW_META_NAME}"]`); 34 if (!meta) { 35 meta = document.createElement('meta'); 36 meta.name = PREVIEW_META_NAME; 37 document.head.appendChild(meta); 38 } 39 meta.content = previewUrl; 40} 41 42/** 43 * Reads the environment-specific `preview_url` config and sets the UE preview meta tag. 44 * Each AEM Author environment publishes its own config sheet with the correct preview base URL. 45 * @returns {Promise<void>} 46 */ 47export async function configureUePreview() { 48 const previewBase = await getConfigValue('preview_url'); 49 if (!previewBase) return; 50 51 const aemPath = window.AEM_PAGE_PATH || window.location.pathname; 52 setUePreviewMeta(buildUePreviewUrl(previewBase, aemPath)); 53}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.