配置 - peento/peento-blog GitHub Wiki
-
插件的专属配置需要加上其前缀,比如插件
peento-blog-comment-disqus
其前缀为comment_disqus
,若要获取配置项short_name
,则配置名称为comment_disqus_short_name
(将“-”和“.”统一转换为“_”) -
在程序中通过
app.call('config.get', 'comment_disqus_short_name', callback)
来获取 -
在模板中通过
_config_comment_disqus_short_name
来获取该配置信息 -
初始化插件时,在插件的入口文件中通过
app.call('config.set_if_not_exists', name, value, callback)
来初始化,比如:
module.exports = function (ns, plugin, debug) {
plugin.load(__dirname);
var app = ns('app');
app.once('start', function () {
// init config
function callback (err) {
if (err) {
console.error(err);
}
}
app.call('config.set_if_not_exists', {
name: 'search_google_host',
value: ''
}, callback);
});
};