remove last slash from appUrl

This commit is contained in:
Niels Lyngsø
2024-08-15 13:33:39 +02:00
parent 4f683e234d
commit 130b1667ff
5 changed files with 14 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
import type { UmbBlockGridLayoutModel, UmbBlockGridTypeModel } from '../types.js';
import type { UmbBlockGridWorkspaceData } from '../index.js';
import { UmbArrayState, appendToFrozenArray, pushAtToUniqueArray } from '@umbraco-cms/backoffice/observable-api';
import { transformServerPathToClientPath } from '@umbraco-cms/backoffice/utils';
import { removeLastSlashFromPath, transformServerPathToClientPath } from '@umbraco-cms/backoffice/utils';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UMB_APP_CONTEXT } from '@umbraco-cms/backoffice/app';
import type { UmbPropertyEditorConfigCollection } from '@umbraco-cms/backoffice/property-editor';
@@ -29,7 +29,7 @@ export class UmbBlockGridManagerContext<
if (layoutStylesheet) {
// Cause we await initAppUrl in setting the _editorConfiguration, we can trust the appUrl begin here.
return this.#appUrl! + transformServerPathToClientPath(layoutStylesheet);
return removeLastSlashFromPath(this.#appUrl!) + transformServerPathToClientPath(layoutStylesheet);
}
return undefined;
});

View File

@@ -6,13 +6,13 @@ import { html, customElement, property, state, ifDefined } from '@umbraco-cms/ba
import { UmbRepositoryItemsManager } from '@umbraco-cms/backoffice/repository';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { UMB_APP_CONTEXT } from '@umbraco-cms/backoffice/app';
import { transformServerPathToClientPath } from '@umbraco-cms/backoffice/utils';
import { removeLastSlashFromPath, transformServerPathToClientPath } from '@umbraco-cms/backoffice/utils';
@customElement('umb-block-type-card')
export class UmbBlockTypeCardElement extends UmbLitElement {
//
#init: Promise<void>;
#appUrl?: string;
#appUrl: string = '';
#itemManager = new UmbRepositoryItemsManager<UmbDocumentTypeItemModel>(
this,
@@ -28,7 +28,7 @@ export class UmbBlockTypeCardElement extends UmbLitElement {
value = transformServerPathToClientPath(value);
if (value) {
this.#init.then(() => {
this._iconFile = this.#appUrl + value;
this._iconFile = removeLastSlashFromPath(this.#appUrl) + value;
});
} else {
this._iconFile = undefined;

View File

@@ -12,6 +12,7 @@ export * from './path/path-decode.function.js';
export * from './path/path-encode.function.js';
export * from './path/path-folder-name.function.js';
export * from './path/remove-initial-slash-from-path.function.js';
export * from './path/remove-last-slash-from-path.function.js';
export * from './path/stored-path.function.js';
export * from './path/transform-server-path-to-client-path.function.js';
export * from './path/umbraco-path.function.js';

View File

@@ -1,5 +1,5 @@
/**
*
* Removes the initial slash from a path, if the first character is a slash.
* @param path
*/
export function removeInitialSlashFromPath(path: string) {

View File

@@ -0,0 +1,7 @@
/**
* Remove the last slash from a path, if the last character is a slash.
* @param path
*/
export function removeLastSlashFromPath(path: string) {
return path.endsWith('/') ? path.slice(undefined, -1) : path;
}