Skip to content

Commit

Permalink
feat(atomic): replace getAssetPath (#4844)
Browse files Browse the repository at this point in the history
Replace `getAssetPath` from stencil with a in-house method

https://coveord.atlassian.net/browse/KIT-3828

---------

Co-authored-by: Louis Bompart <lbompart@coveo.com>
Co-authored-by: renovate-coveo[bot] <115253437+renovate-coveo[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent 28b022b commit 4aa0206
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/atomic/src/components/common/interface/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {getAssetPath} from '@stencil/core';
import DOMPurify from 'dompurify';
import Backend, {HttpBackendOptions} from 'i18next-http-backend';
import availableLocales from '../../../generated/availableLocales.json';
import {getAssetPath} from '../../../utils/utils';
import {AnyEngineType} from './bindings';
import {BaseAtomicInterface} from './interface-common';

Expand Down
12 changes: 8 additions & 4 deletions packages/atomic/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {getAssetPath} from '@stencil/core';
import {NODE_TYPES} from '@stencil/core/mock-doc';
import DOMPurify from 'dompurify';

/**
Expand Down Expand Up @@ -57,11 +55,11 @@ export function parseHTML(string: string) {
}

export function isElementNode(node: Node): node is Element {
return node.nodeType === NODE_TYPES.ELEMENT_NODE;
return node.nodeType === Node.ELEMENT_NODE;
}

export function isTextNode(node: Node): node is Text {
return node.nodeType === NODE_TYPES.TEXT_NODE;
return node.nodeType === Node.TEXT_NODE;
}

export function isVisualNode(node: Node) {
Expand All @@ -84,6 +82,12 @@ export function containsVisualElement(node: Node) {
return false;
}

export function getAssetPath(path: string): string {
const baseUrl = window.location.origin;
const assetUrl = new URL(path, baseUrl);
return assetUrl.origin !== baseUrl ? assetUrl.href : assetUrl.pathname;
}

export function parseAssetURL(url: string, assetPath = './assets') {
const [, protocol, remainder] =
url.match(/^([a-z]+):\/\/(.*?)(\.svg)?$/) || [];
Expand Down

0 comments on commit 4aa0206

Please sign in to comment.