Fix docsify nav target

This commit is contained in:
John Hildenbiddle 2022-03-24 16:30:30 -05:00
parent 2d13255acb
commit 75d35dd8e3
3 changed files with 39 additions and 18 deletions

View File

@ -54,6 +54,18 @@
</head>
<body>
<nav
id="mynav"
style="
background: red;
color: white;
text-align: center;
padding: 1em;
font-weight: bold;
"
>
<p>Custom Nav Element</p>
</nav>
<div id="app">Loading ...</div>
<script src="//cdn.jsdelivr.net/npm/docsify-plugin-carbon@1"></script>
<script>
@ -197,7 +209,7 @@
'\n\n----\n\n' +
'<a href="https://docsify.js.org" target="_blank" style="color: inherit; font-weight: normal; text-decoration: none;">Powered by docsify</a>'
);
})
});
},
],
};

View File

@ -30,7 +30,10 @@ export function Events(Base) {
})();
if (this.config.loadNavbar) {
sidebar.getAndActive(this.router, 'nav');
sidebar.getAndActive(
this.router,
'nav.app-nav, main > aside.sidebar > nav'
);
}
}

View File

@ -299,9 +299,13 @@ export function Render(Base) {
}
_renderNav(text) {
text && this._renderTo('nav', this.compiler.compile(text));
text &&
this._renderTo(
'nav.app-nav, main > aside.sidebar > nav',
this.compiler.compile(text)
);
if (this.config.loadNavbar) {
getAndActive(this.router, 'nav');
getAndActive(this.router, 'nav.app-nav, main > aside.sidebar > nav');
}
}
@ -405,11 +409,8 @@ export function Render(Base) {
}
const id = config.el || '#app';
const navEl = dom.find('nav') || dom.create('nav');
const el = dom.find(id);
let html = '';
let navAppendToTarget = dom.body;
if (el) {
if (config.repo) {
@ -437,19 +438,24 @@ export function Render(Base) {
this.rendered = true;
}
if (config.mergeNavbar && isMobile) {
navAppendToTarget = dom.find('.sidebar');
} else {
navEl.classList.add('app-nav');
if (!config.repo) {
navEl.classList.add('no-badge');
}
}
// Add nav
if (config.loadNavbar) {
dom.before(navAppendToTarget, navEl);
const isMergedMobileNav = config.mergeNavbar && isMobile;
const navAppendToTarget = isMergedMobileNav
? dom.find('.sidebar')
: dom.find('section.cover, main');
const navEl =
dom.find('nav.app-nav, main > aside.sidebar > nav') ||
dom.create('nav');
!isMergedMobileNav && navEl.classList.add('app-nav');
!config.repo && navEl.classList.add('no-badge');
if (isMergedMobileNav) {
dom.before(navAppendToTarget, navEl);
} else {
navAppendToTarget.parentNode.insertBefore(navEl, navAppendToTarget);
}
}
if (config.themeColor) {