next-config.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* global hexo */
  2. 'use strict';
  3. const url = require('url');
  4. /**
  5. * Export theme config to js
  6. */
  7. hexo.extend.helper.register('next_config', function() {
  8. let { config, theme, next_version } = this;
  9. config.algolia = config.algolia || {};
  10. let exportConfig = {
  11. hostname : url.parse(config.url).hostname || config.url,
  12. root : config.root,
  13. scheme : theme.scheme,
  14. version : next_version,
  15. exturl : theme.exturl,
  16. sidebar : theme.sidebar,
  17. copycode : theme.codeblock.copy_button,
  18. back2top : theme.back2top,
  19. bookmark : theme.bookmark,
  20. fancybox : theme.fancybox,
  21. mediumzoom: theme.mediumzoom,
  22. lazyload : theme.lazyload,
  23. pangu : theme.pangu,
  24. comments : theme.comments,
  25. algolia : {
  26. appID : config.algolia.applicationID,
  27. apiKey : config.algolia.apiKey,
  28. indexName: config.algolia.indexName,
  29. hits : theme.algolia_search.hits,
  30. labels : theme.algolia_search.labels
  31. },
  32. localsearch: theme.local_search,
  33. motion : theme.motion
  34. };
  35. if (config.search) {
  36. exportConfig.path = config.search.path;
  37. }
  38. return `<script id="hexo-configurations">
  39. var NexT = window.NexT || {};
  40. var CONFIG = ${JSON.stringify(exportConfig)};
  41. </script>`;
  42. });