feat(hook): new hook updateNav for update navbar content

This commit is contained in:
Anix
2020-06-18 15:54:59 +00:00
parent 714ef29afe
commit c466e5a3ae
3 changed files with 13 additions and 3 deletions
+5 -2
View File
@@ -55,6 +55,9 @@
formatUpdated: '{MM}/{DD} {HH}:{mm}',
plugins: [
function (hook, vm) {
hook.updateNav(function(nav){
return `${nav}\n- lol`
}),
hook.beforeEach(function (html) {
if (/githubusercontent\.com/.test(vm.route.file)) {
url = vm.route.file
@@ -79,9 +82,9 @@
}
</script>
<script src="/lib/docsify.js"></script>
<script src="/lib/plugins/search.js"></script>
<!-- <script src="/lib/plugins/search.js"></script>
<script src="/lib/plugins/emoji.js"></script>
<script src="/lib/plugins/front-matter.js"></script>
<script src="/lib/plugins/front-matter.js"></script> -->
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-nginx.min.js"></script>
+1
View File
@@ -5,6 +5,7 @@ export function initLifecycle(vm) {
'init',
'mounted',
'beforeEach',
'updateNav',
'afterEach',
'doneEach',
'ready',
+7 -1
View File
@@ -140,7 +140,13 @@ export function renderMixin(proto) {
};
proto._renderNav = function(text) {
text && this._renderTo('nav', this.compiler.compile(text));
if (text) {
callHook(this, 'updateNav', text, result => {
text = result || text;
this._renderTo('nav', this.compiler.compile(text));
});
}
if (this.config.loadNavbar) {
getAndActive(this.router, 'nav');
}