2020-03-29 19:54:28 +08:00
|
|
|
/* global hexo */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const url = require('url');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Export theme config to js
|
|
|
|
*/
|
2020-04-18 17:33:11 +08:00
|
|
|
hexo.extend.helper.register('export_config', function () {
|
2020-10-21 19:36:38 +08:00
|
|
|
let {config, theme} = this;
|
|
|
|
let exportConfig = {
|
|
|
|
hostname: url.parse(config.url).hostname || config.url,
|
|
|
|
root: config.root,
|
|
|
|
localsearch: theme.local_search,
|
|
|
|
themeInfo: theme.theme_info,
|
|
|
|
codeblock: theme.codeblock,
|
|
|
|
toc: theme.toc,
|
|
|
|
back2top: theme.back2top
|
|
|
|
};
|
|
|
|
if (config.search) {
|
|
|
|
exportConfig.path = config.search.path;
|
|
|
|
}
|
|
|
|
return `<script id="hexo-configurations">
|
|
|
|
let ILS = window.ILS || {};
|
2020-03-29 19:54:28 +08:00
|
|
|
let CONFIG = ${JSON.stringify(exportConfig)};
|
|
|
|
</script>`;
|
|
|
|
});
|