Skip to content

Commit 90eedd4

Browse files
committed
index.js - extra logic to handle searching for apps folder in href
1 parent 57e4675 commit 90eedd4

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

js/index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function extractAppNameFromHref(href) {
110110
if (!href) return null;
111111

112112
try {
113-
const u = new URL(href, window.location.href);
113+
const u = new URL(href);
114114
href = u.pathname;
115115
} catch (e) {
116116
// ignore - just use href as-is
@@ -123,14 +123,22 @@ function extractAppNameFromHref(href) {
123123

124124
const parts = href.split('/').filter(Boolean);
125125
if (parts.length === 0) return null;
126-
// allow './apps/appname' or './appname' by dropping leading '.' segments
126+
// allow './' prefixes by dropping leading '.' segments
127127
while (parts.length && parts[0] === '.') parts.shift();
128128
if (parts.length === 0) return null; // skip if it was current dir only
129-
if (parts[0] === '..') return null; // skip parent redirect
130-
if (parts[0].toLowerCase() === 'apps') parts.shift(); // skip over apps folder
131-
if (parts.length === 0) return null;
132-
if (parts[0].includes('.')) return null;
133-
return parts[0];
129+
// reject any parent-directory references anywhere
130+
if (parts.some(p => p === '..')) return null;
131+
// prefer an 'apps' segment anywhere in the path; otherwise use first folder
132+
const appsIdx = parts.findIndex(p => p.toLowerCase() === 'apps');
133+
let candidate;
134+
if (appsIdx >= 0 && appsIdx + 1 < parts.length) candidate = parts[appsIdx + 1];
135+
else candidate = parts[0];
136+
if (!candidate) return null;
137+
// if the only thing we found is 'apps', ignore it
138+
if (candidate.toLowerCase() === 'apps') return null;
139+
// skip names with periods
140+
if (candidate.includes('.')) return null;
141+
return candidate;
134142
}
135143

136144
httpGet(Const.APPS_JSON_FILE).then(apps=>{

0 commit comments

Comments
 (0)