Skip to content
Merged
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
8 changes: 7 additions & 1 deletion src/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ function Page(pageConfig) {
this.keywords = {};
this.navigableHeadings = {};
this.pageSectionsHtml = {};

// Flag to indicate whether this page has a site nav
this.hasSiteNav = false;
}

/**
Expand Down Expand Up @@ -231,7 +234,7 @@ Page.prototype.prepareTemplateData = function () {
markBindVersion: `MarkBind ${CLI_VERSION}`,
pageNav: this.isPageNavigationSpecifierValid(),
pageNavHtml: this.pageSectionsHtml[`#${PAGE_NAV_ID}`] || '',
siteNav: this.frontMatter.siteNav,
siteNav: this.hasSiteNav,
siteNavHtml: this.pageSectionsHtml[`#${SITE_NAV_ID}`] || '',
title: prefixedTitle,
enableSearch: this.enableSearch,
Expand Down Expand Up @@ -575,12 +578,15 @@ Page.prototype.insertSiteNav = function (pageData) {
// Retrieve Markdown file contents
const siteNavPath = path.join(this.rootPath, siteNavFile);
if (!fs.existsSync(siteNavPath)) {
this.hasSiteNav = false;
return pageData;
}
const siteNavContent = fs.readFileSync(siteNavPath, 'utf8');
if (siteNavContent === '') {
this.hasSiteNav = false;
return pageData;
}
this.hasSiteNav = true;

@Chng-Zhi-Xuan Chng-Zhi-Xuan Apr 16, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you only modify the flag to be true at this point. If you delete the navigation.md (Or blank the contents) from the layouts folder, the site-nav will still appear in the markbind serve preview. Even though MarkBind correctly detected navigation.md has changed.

The only correct behaviour in this code is changing navigation.md slightly and the changes will reflect in the markbind serve preview.

Suggestion
Explicitly set the flag to false in the if statements above for it to be properly removed when navigation.md is deleted / blanked in preview mode.

// Set siteNav file as an includedFile
this.includedFiles[siteNavPath] = true;
// Map variables
Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_site/expected/testLayouts.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<link rel="stylesheet" href="markbind/css/markbind.css">
<link rel="stylesheet" href="STYLESHEET_LINK">
<link rel="stylesheet" href="markbind/layouts/testLayout/styles.css">

<link rel="stylesheet" href="markbind/css/site-nav.css">

<script src="/test_site/headFiles/overwriteLayoutScript.js"></script>
<link rel="icon" href="/test_site/favicon.png">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<link rel="stylesheet" href="markbind/css/markbind.css">
<link rel="stylesheet" href="STYLESHEET_LINK">
<link rel="stylesheet" href="markbind/layouts/testLayout/styles.css">

<link rel="stylesheet" href="markbind/css/site-nav.css">

<script src="/test_site/headFiles/overwriteLayoutScript.js"></script>
<link rel="icon" href="/test_site/favicon.png">
Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_site_convert/expected/Home.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<link rel="stylesheet" href="markbind/css/github.min.css">
<link rel="stylesheet" href="markbind/css/markbind.css">
<link rel="stylesheet" href="markbind/layouts/default/styles.css">

<link rel="stylesheet" href="markbind/css/site-nav.css">



Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_site_convert/expected/Page-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<link rel="stylesheet" href="markbind/css/github.min.css">
<link rel="stylesheet" href="markbind/css/markbind.css">
<link rel="stylesheet" href="markbind/layouts/default/styles.css">

<link rel="stylesheet" href="markbind/css/site-nav.css">



Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_site_convert/expected/_Footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<link rel="stylesheet" href="markbind/css/github.min.css">
<link rel="stylesheet" href="markbind/css/markbind.css">
<link rel="stylesheet" href="markbind/layouts/default/styles.css">

<link rel="stylesheet" href="markbind/css/site-nav.css">



Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_site_convert/expected/_Sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<link rel="stylesheet" href="markbind/css/github.min.css">
<link rel="stylesheet" href="markbind/css/markbind.css">
<link rel="stylesheet" href="markbind/layouts/default/styles.css">

<link rel="stylesheet" href="markbind/css/site-nav.css">



Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_site_convert/expected/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<link rel="stylesheet" href="markbind/css/github.min.css">
<link rel="stylesheet" href="markbind/css/markbind.css">
<link rel="stylesheet" href="markbind/layouts/default/styles.css">

<link rel="stylesheet" href="markbind/css/site-nav.css">



Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_site_convert/expected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<link rel="stylesheet" href="markbind/css/github.min.css">
<link rel="stylesheet" href="markbind/css/markbind.css">
<link rel="stylesheet" href="markbind/layouts/default/styles.css">

<link rel="stylesheet" href="markbind/css/site-nav.css">



Expand Down