From 2f3a48cfcee226463fa4b27391e093942f97e56f Mon Sep 17 00:00:00 2001 From: Marvin Chin Date: Mon, 15 Apr 2019 01:13:13 +0800 Subject: [PATCH] Fix site-nav.css not being added when layout contains site nav When passing data to the page template, the siteNav variable only checks for the existence of the site nav specified in the frontmatter. The site-nav.css file is thus only added when the site nav is specified in the frontmatter. When a page has a layout with a site nav, but no site nav is specified in the frontmatter, the site-nav.css file is not added, which causes the styling of the site nav to break. Let's update the logic when forming template data to check for the existence of a site nav in the template when determining the value of the siteNav variable. --- src/Page.js | 8 +++++++- test/functional/test_site/expected/testLayouts.html | 2 +- .../test_site/expected/testLayoutsOverride.html | 2 +- test/functional/test_site_convert/expected/Home.html | 2 +- test/functional/test_site_convert/expected/Page-1.html | 2 +- test/functional/test_site_convert/expected/_Footer.html | 2 +- test/functional/test_site_convert/expected/_Sidebar.html | 2 +- test/functional/test_site_convert/expected/about.html | 2 +- test/functional/test_site_convert/expected/index.html | 2 +- 9 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Page.js b/src/Page.js index 07b7bef43a..21e1c1024c 100644 --- a/src/Page.js +++ b/src/Page.js @@ -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; } /** @@ -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, @@ -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; // Set siteNav file as an includedFile this.includedFiles[siteNavPath] = true; // Map variables diff --git a/test/functional/test_site/expected/testLayouts.html b/test/functional/test_site/expected/testLayouts.html index e80b188608..8786a72147 100644 --- a/test/functional/test_site/expected/testLayouts.html +++ b/test/functional/test_site/expected/testLayouts.html @@ -16,7 +16,7 @@ - + diff --git a/test/functional/test_site/expected/testLayoutsOverride.html b/test/functional/test_site/expected/testLayoutsOverride.html index 33aceb48a2..033cbe62fb 100644 --- a/test/functional/test_site/expected/testLayoutsOverride.html +++ b/test/functional/test_site/expected/testLayoutsOverride.html @@ -16,7 +16,7 @@ - + diff --git a/test/functional/test_site_convert/expected/Home.html b/test/functional/test_site_convert/expected/Home.html index caff4f6de9..faac0d4892 100644 --- a/test/functional/test_site_convert/expected/Home.html +++ b/test/functional/test_site_convert/expected/Home.html @@ -15,7 +15,7 @@ - + diff --git a/test/functional/test_site_convert/expected/Page-1.html b/test/functional/test_site_convert/expected/Page-1.html index dd4e749f6e..d9d09a24c1 100644 --- a/test/functional/test_site_convert/expected/Page-1.html +++ b/test/functional/test_site_convert/expected/Page-1.html @@ -15,7 +15,7 @@ - + diff --git a/test/functional/test_site_convert/expected/_Footer.html b/test/functional/test_site_convert/expected/_Footer.html index 22bb483e29..47085df3e6 100644 --- a/test/functional/test_site_convert/expected/_Footer.html +++ b/test/functional/test_site_convert/expected/_Footer.html @@ -15,7 +15,7 @@ - + diff --git a/test/functional/test_site_convert/expected/_Sidebar.html b/test/functional/test_site_convert/expected/_Sidebar.html index 662a32265d..eb49f4e333 100644 --- a/test/functional/test_site_convert/expected/_Sidebar.html +++ b/test/functional/test_site_convert/expected/_Sidebar.html @@ -15,7 +15,7 @@ - + diff --git a/test/functional/test_site_convert/expected/about.html b/test/functional/test_site_convert/expected/about.html index a18d1928cb..f02da09040 100644 --- a/test/functional/test_site_convert/expected/about.html +++ b/test/functional/test_site_convert/expected/about.html @@ -15,7 +15,7 @@ - + diff --git a/test/functional/test_site_convert/expected/index.html b/test/functional/test_site_convert/expected/index.html index 87f04865fc..74b7197c2c 100644 --- a/test/functional/test_site_convert/expected/index.html +++ b/test/functional/test_site_convert/expected/index.html @@ -15,7 +15,7 @@ - +