mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-18 18:33:42 +00:00
52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
/* global hexo */
|
|
|
|
'use strict';
|
|
|
|
const { parse } = require('url');
|
|
|
|
/**
|
|
* Export theme config to js
|
|
*/
|
|
hexo.extend.helper.register('next_config', function() {
|
|
const { config, theme, __ } = this;
|
|
const exportConfig = {
|
|
hostname : parse(config.url).hostname || config.url,
|
|
root : config.root,
|
|
scheme : theme.scheme,
|
|
version : this.next_version,
|
|
exturl : theme.exturl,
|
|
sidebar : theme.sidebar,
|
|
copycode : theme.codeblock.copy_button.enable,
|
|
bookmark : theme.bookmark,
|
|
fancybox : theme.fancybox,
|
|
mediumzoom: theme.mediumzoom,
|
|
lazyload : theme.lazyload,
|
|
pangu : theme.pangu,
|
|
comments : theme.comments,
|
|
motion : theme.motion,
|
|
prism : config.prismjs.enable && !config.prismjs.preprocess,
|
|
i18n : {
|
|
placeholder: __('search.placeholder'),
|
|
empty : __('search.empty', '${query}'),
|
|
hits_time : __('search.hits_time', '${hits}', '${time}'),
|
|
hits : __('search.hits', '${hits}')
|
|
}
|
|
};
|
|
if (config.algolia && theme.algolia_search && theme.algolia_search.enable) {
|
|
exportConfig.algolia = {
|
|
appID : config.algolia.applicationID || config.algolia.appId,
|
|
apiKey : config.algolia.apiKey,
|
|
indexName: config.algolia.indexName,
|
|
hits : theme.algolia_search.hits
|
|
};
|
|
}
|
|
if (config.search && theme.local_search && theme.local_search.enable) {
|
|
exportConfig.path = this.url_for(config.search.path);
|
|
exportConfig.localsearch = theme.local_search;
|
|
}
|
|
return `<script class="hexo-configurations">
|
|
var NexT = window.NexT || {};
|
|
var CONFIG = ${JSON.stringify(exportConfig)};
|
|
</script>`;
|
|
});
|