From 39376c00127c5f065dd3ff7e457ecf9b5ef52bfb Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 17 Jul 2024 16:57:37 +0200 Subject: [PATCH] Fix tests --- .../ThemeConfig/Conversion/FixImages.ts | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/Models/ThemeConfig/Conversion/FixImages.ts b/src/Models/ThemeConfig/Conversion/FixImages.ts index 2be9c0e363..cc1fc7a55d 100644 --- a/src/Models/ThemeConfig/Conversion/FixImages.ts +++ b/src/Models/ThemeConfig/Conversion/FixImages.ts @@ -54,6 +54,20 @@ export class ExtractImages extends Conversion< ) } + static isImageType(metapath: any): boolean { + if (metapath.hints.typehint === "icon" || + metapath.hints.typehint === "image") { + return true + } + + const types = metapath.hints.types?.split(";").map(x => x.trim()) + if (types?.some(t => t === "icon" || t === "image")) { + return true + } + + return false + } + /** * const images = new ExtractImages(true, new Set()).convert({ * "layers": [ @@ -102,9 +116,14 @@ export class ExtractImages extends Conversion< const allFoundImages: { path: string; context: string }[] = [] for (const metapath of ExtractImages.layoutMetaPaths) { const mightBeTr = ExtractImages.mightBeTagRendering(metapath) - const allRenderedValuesAreImages = - metapath.hints.typehint === "icon" || metapath.hints.typehint === "image" + + const allRenderedValuesAreImages = ExtractImages.isImageType(metapath) + const found = Utils.CollectPath(metapath.path, json) + if(found.length === 0){ + continue + } + if (mightBeTr) { // We might have tagRenderingConfigs containing icons here for (const el of found) { @@ -134,9 +153,9 @@ export class ExtractImages extends Conversion< // Inspect all the rendered values const fromPath = Utils.CollectPath(trpath.path, foundImage) const isRendered = trpath.hints.typehint === "rendered" - const isImage = - trpath.hints.typehint === "icon" || - trpath.hints.typehint === "image" + + const isImage = ExtractImages.isImageType(trpath) + for (const img of fromPath) { if (allRenderedValuesAreImages && isRendered) { // What we found is an image @@ -158,7 +177,7 @@ export class ExtractImages extends Conversion< } else { allFoundImages.push({ path: img.leaf, - context: context + "." + path, + context: context + "." + path }) } } @@ -172,7 +191,7 @@ export class ExtractImages extends Conversion< .ExtractImages(false) .map((path) => ({ path, - context: context + "." + path, + context: context + "." + path })) ) } @@ -192,7 +211,7 @@ export class ExtractImages extends Conversion< } allFoundImages.push({ context: context.path.join(".") + "." + foundElement.path.join("."), - path: foundElement.leaf, + path: foundElement.leaf }) } } @@ -283,7 +302,6 @@ export class FixImages extends DesugaringStep { const absolute = url.protocol + "//" + url.host let relative = url.protocol + "//" + url.host + url.pathname relative = relative.substring(0, relative.lastIndexOf("/")) - const self = this if (relative.endsWith("assets/generated/themes")) { context.warn( @@ -292,8 +310,10 @@ export class FixImages extends DesugaringStep { relative = absolute } + const knownImages = this._knownImages + function replaceString(leaf: string) { - if (self._knownImages.has(leaf)) { + if (knownImages.has(leaf)) { return leaf } @@ -316,7 +336,7 @@ export class FixImages extends DesugaringStep { json = Utils.Clone(json) for (const metapath of metapaths) { - if (metapath.hints.typehint !== "image" && metapath.hints.typehint !== "icon") { + if (!ExtractImages.isImageType(metapath)) { continue } const mightBeTr = ExtractImages.mightBeTagRendering(metapath)