publicpath.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. // We dynamically set the webpack public path based on the page config
  4. // settings from the JupyterLab app. We copy some of the pageconfig parsing
  5. // logic in @jupyterlab/coreutils below, since this must run before any other
  6. // files are loaded (including @jupyterlab/coreutils).
  7. /**
  8. * Get global configuration data for the Jupyter application.
  9. *
  10. * @param name - The name of the configuration option.
  11. *
  12. * @returns The config value or an empty string if not found.
  13. *
  14. * #### Notes
  15. * All values are treated as strings.
  16. * For browser based applications, it is assumed that the page HTML
  17. * includes a script tag with the id `jupyter-config-data` containing the
  18. * configuration as valid JSON. In order to support the classic Notebook,
  19. * we fall back on checking for `body` data of the given `name`.
  20. */
  21. function getOption(name) {
  22. let configData = Object.create(null);
  23. // Use script tag if available.
  24. if (typeof document !== 'undefined' && document) {
  25. const el = document.getElementById('jupyter-config-data');
  26. if (el) {
  27. configData = JSON.parse(el.textContent || '{}');
  28. }
  29. }
  30. return configData[name] || '';
  31. }
  32. // eslint-disable-next-line no-undef
  33. __webpack_public_path__ = getOption('fullStaticUrl') + '/';