|
1 | | -import { initStringExemptionLists, isFeatureBroken, registerMessageSecret } from './utils'; |
| 1 | +import { initStringExemptionLists, isFeatureBroken, isGloballyDisabled, platformSpecificFeatures, registerMessageSecret } from './utils'; |
2 | 2 | import { platformSupport } from './features'; |
3 | 3 | import { PerformanceMonitor } from './performance'; |
4 | 4 | import platformFeatures from 'ddg:platformFeatures'; |
@@ -41,13 +41,23 @@ export function load(args) { |
41 | 41 | injectName: import.meta.injectName, |
42 | 42 | }; |
43 | 43 |
|
44 | | - const featureNames = typeof importConfig.injectName === 'string' ? platformSupport[importConfig.injectName] : []; |
| 44 | + const bundledFeatureNames = typeof importConfig.injectName === 'string' ? platformSupport[importConfig.injectName] : []; |
45 | 45 |
|
46 | | - for (const featureName of featureNames) { |
47 | | - const ContentFeature = platformFeatures['ddg_feature_' + featureName]; |
48 | | - const featureInstance = new ContentFeature(featureName, importConfig, args); |
49 | | - featureInstance.callLoad(); |
50 | | - features.push({ featureName, featureInstance }); |
| 46 | + // prettier-ignore |
| 47 | + const featuresToLoad = isGloballyDisabled(args) |
| 48 | + // if we're globally disabled, only allow `platformSpecificFeatures` |
| 49 | + ? platformSpecificFeatures |
| 50 | + // if available, use `site.enabledFeatures`. The extension doesn't have `site.enabledFeatures` at this |
| 51 | + // point, which is why we fall back to `bundledFeatureNames`. |
| 52 | + : args.site.enabledFeatures || bundledFeatureNames; |
| 53 | + |
| 54 | + for (const featureName of bundledFeatureNames) { |
| 55 | + if (featuresToLoad.includes(featureName)) { |
| 56 | + const ContentFeature = platformFeatures['ddg_feature_' + featureName]; |
| 57 | + const featureInstance = new ContentFeature(featureName, importConfig, args); |
| 58 | + featureInstance.callLoad(); |
| 59 | + features.push({ featureName, featureInstance }); |
| 60 | + } |
51 | 61 | } |
52 | 62 | mark.end(); |
53 | 63 | } |
|
0 commit comments