Make hint foundries configurable
Resolves #173
and the milestone from, originally, 1 Apr 2025
Change-Id: Iaa062ae4831187c96f99f339b29cc4374cc31afd
diff --git a/dev/js/src/hint/foundries.js b/dev/js/src/hint/foundries.js
index 80d7332..053954e 100644
--- a/dev/js/src/hint/foundries.js
+++ b/dev/js/src/hint/foundries.js
@@ -80,5 +80,32 @@
return '';
};
+ /**
+ * Filter available foundries based on configuration.
+ * Reads from data-hint-foundries attribute on body element.
+ * Each foundry module pushes entries like ["Name", "prefix/", "Description"]
+ * to ah["-"]. The prefix (e.g., "corenlp/") is matched against enabled list.
+ */
+ ah.filterByConfig = function () {
+ const body = document.body;
+ if (!body) return;
+
+ const configAttr = body.getAttribute('data-hint-foundries');
+ if (!configAttr) return; // No filter - show all
+
+ const enabledFoundries = configAttr.split(',').map(f => f.trim().toLowerCase());
+ if (enabledFoundries.length === 0) return;
+
+ // Filter the root foundry list ah["-"]
+ // Each entry is ["Name", "prefix/", "Description"]
+ // Match prefix (without trailing /) against enabled list
+ this["-"] = this["-"].filter(entry => {
+ if (!entry || !entry[1]) return false;
+ // Extract foundry name from prefix like "corenlp/" -> "corenlp"
+ const foundryName = entry[1].replace(/\/$/, '').toLowerCase();
+ return enabledFoundries.includes(foundryName);
+ });
+ };
+
return ah;
});