2020-03-29 19:54:28 +08:00
|
|
|
/* global hexo */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const url = require('url');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Export theme config to js
|
|
|
|
*/
|
|
|
|
hexo.extend.helper.register('export_config', function() {
|
|
|
|
let { config, theme } = this;
|
|
|
|
let exportConfig = {
|
|
|
|
hostname : url.parse(config.url).hostname || config.url,
|
|
|
|
root : config.root,
|
|
|
|
localsearch: theme.local_search,
|
|
|
|
themeName: theme.theme_name,
|
2020-03-30 11:17:47 +08:00
|
|
|
themeVersion: theme.theme_version,
|
|
|
|
pageLayout: theme.page
|
2020-03-29 19:54:28 +08:00
|
|
|
};
|
|
|
|
if (config.search) {
|
|
|
|
exportConfig.path = config.search.path;
|
|
|
|
}
|
|
|
|
return `<script id="hexo-configurations">
|
|
|
|
let CONFIG = ${JSON.stringify(exportConfig)};
|
|
|
|
</script>`;
|
|
|
|
});
|