Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide site nav under a button #1

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/core/src/plugins/hiddenSiteNav.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* hiddenSiteNav.css */
#site-nav-show-button,
#site-nav-hide-button {
margin-right: 10px;
}

/* Media query settings were copied from core/template/default/stylesheets/main.css */
@media screen and (max-width: 991.98px) {
#site-nav-show-button,
#site-nav-hide-button {
display: none;
}
}
42 changes: 42 additions & 0 deletions packages/core/src/plugins/hiddenSiteNav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// hiddenSiteNav.js
const cheerio = module.parent.require('cheerio');

module.exports = {
processNode: (pluginContext, node) => {
if (node.name === 'navbar') {
pluginContext.navbarTheme = node.attribs.type;
}

if (node.attribs.hasOwnProperty('#brand')) {
cheerio(node)
.children('.navbar-brand')
.removeAttr('slot')
.wrap('<div slot="brand"></div>')
.before(
'<button href="#" id="site-nav-show-button" '
+ `class="fa fa-bars btn btn-${pluginContext.navbarTheme}"></button>`
)
.before(
'<button href="#" id="site-nav-hide-button" '
+ `class="fa fa-chevron-left btn btn-${pluginContext.navbarTheme}" hidden></button>`
);
}

if (node.attribs.id === 'site-nav') {
cheerio(node).attr('hidden', 'hidden');
}
},
getLinks: (pluginContext, frontMatter, content) => [
'<link rel="stylesheet" href="hiddenSiteNav.css">'
],
getScripts: (pluginContext, frontMatter, content) => [
'<script> $("#site-nav-show-button").click(() => {'
+ '$("#site-nav").removeAttr("hidden");'
+ '$("#site-nav-hide-button").removeAttr("hidden");'
+ '$("#site-nav-show-button").attr("hidden", "hidden");});'
+ '$("#site-nav-hide-button").click(() => {'
+ '$("#site-nav").attr("hidden", "hidden");'
+ '$("#site-nav-hide-button").attr("hidden", "hidden");'
+ '$("#site-nav-show-button").removeAttr("hidden")}); </script>'
]
}
8 changes: 8 additions & 0 deletions packages/core/template/default/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
],
"deploy": {
"message": "Site Update."
},
"plugins": [
"hiddenSiteNav"
],
"pluginsContext": {
"hiddenSiteNav": {
"navbarTheme": "dark"
}
}
}