aboutsummaryrefslogtreecommitdiffstats
path: root/extension
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2020-12-22 18:32:08 -0800
committerOmar Rizwan <omar@omar.website>2020-12-22 18:32:08 -0800
commite6f9ce7437d8f83076680391be0d260f80a018c3 (patch)
tree3dc44abeb9552d269f15c8cba8cd96e27b200169 /extension
parentde9a792a2113ca48458d5142f2cd06353419793c (diff)
fixup ancestor algorithm so extensions/ appears
Diffstat (limited to 'extension')
-rw-r--r--extension/background.js20
1 files changed, 10 insertions, 10 deletions
diff --git a/extension/background.js b/extension/background.js
index ee3976e..4fb5923 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -339,15 +339,15 @@ for (let key in router) {
if (path == '') path = '/';
if (!router[path]) {
+ function depth(p) { return p === '/' ? 0 : (p.match(/\//g) || []).length; }
+
// find all direct children
- let children = Object.keys(router)
- .filter(k => k.startsWith(path) &&
- (k.match(/\//g) || []).length ===
- (path.match(/\//g) || []).length + 1)
- .map(k => k.substr((path === '/' ? 0 : path.length) + 1).split('/')[0]);
- children = [".", "..", ...new Set(children)];
-
- router[path] = { readdir() { return { entries: children }; } };
+ let entries = Object.keys(router)
+ .filter(k => k.startsWith(path) && depth(k) === depth(path) + 1)
+ .map(k => k.substr((path === '/' ? 0 : path.length) + 1).split('/')[0]);
+ entries = [".", "..", ...new Set(entries)];
+
+ router[path] = { readdir() { return { entries }; } };
}
}
}
@@ -355,8 +355,8 @@ if (TESTING) { // I wish I could color this section with... a pink background, o
const assert = require('assert');
(async () => {
assert.deepEqual(await router['/tabs/by-id/*'].readdir(), { entries: ['.', '..', 'url', 'title', 'text', 'screenshot.png', 'resources', 'scripts', 'control'] });
- assert.deepEqual(await router['/'].readdir(), { entries: ['.', '..', 'tabs', 'extensions'] });
- assert.deepEqual(await router['/tabs'].readdir(), { entries: ['.', '..', 'by-id', 'by-title'] });
+ assert.deepEqual(await router['/'].readdir(), { entries: ['.', '..', 'extensions', 'tabs'] });
+ assert.deepEqual(await router['/tabs'].readdir(), { entries: ['.', '..', 'create', 'by-id', 'by-title', 'last-focused'] });
assert.deepEqual(findRoute('/tabs/by-id/TABID/url'), router['/tabs/by-id/*/url']);
})()