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,
|
|
|
|
codeblock: theme.codeblock,
|
|
|
|
toc: theme.toc,
|
2020-11-09 10:02:41 +08:00
|
|
|
back2top: theme.back2top,
|
2020-11-17 10:50:55 +08:00
|
|
|
side_tools: theme.side_tools,
|
|
|
|
style: theme.style
|
2020-10-21 19:36:38 +08:00
|
|
|
};
|
|
|
|
if (config.search) {
|
|
|
|
exportConfig.path = config.search.path;
|
|
|
|
}
|
|
|
|
return `<script id="hexo-configurations">
|
2020-11-20 12:02:22 +08:00
|
|
|
let KEEP = window.KEEP || {};
|
2020-03-29 19:54:28 +08:00
|
|
|
let CONFIG = ${JSON.stringify(exportConfig)};
|
|
|
|
</script>`;
|
|
|
|
});
|