kubernetes-handbook/gitbook/gitbook-plugin-page-footer-ex/lib/plugin.js

36 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-09-19 21:38:03 +08:00
module.exports = function(book, page) {
2017-08-21 17:44:43 +08:00
/**
2017-09-19 21:38:03 +08:00
* 在package.json中配置的默认值这里可以直接使用
* [config: config option]
2017-08-21 17:44:43 +08:00
* @type {Object}
*/
2017-09-19 21:38:03 +08:00
var config = book.config.get('pluginsConfig')['page-footer-ex'];
2017-08-21 17:44:43 +08:00
2017-09-19 21:38:03 +08:00
var wrapIfMarkdown = function(input) {
if (!config.markdown) {
return input;
} else {
return book.renderInline('markdown', input);
}
}
// Gitbook Markdown rendering is asynchronous.
return Promise.all([wrapIfMarkdown(config.copyright), wrapIfMarkdown(config.update_label)])
.then(function(labels) {
var copyright = labels[0];
var updateLabel = labels[1];
page.content += '\n\n' + [
'<footer class="page-footer-ex">',
'<span class="page-footer-ex-copyright">',
copyright,
'</span>',
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'<span class="page-footer-ex-footer-update">',
updateLabel,
'{{ file.mtime | dateFormat("' + config.update_format + '") }}',
'</span>',
'</footer>'
].join(' ');
return page;
});
2017-08-21 17:44:43 +08:00
}