\n',
- { indent_size: 2 });
+ : '';
}
-};
-
-Page.prototype.collectHeadFiles = function (baseUrl, hostBaseUrl) {
- const { head } = this.frontMatter;
- let headFiles;
- const collectedTopContent = [];
- const collectedBottomContent = [];
- if (head) {
- headFiles = head.replace(/, */g, ',').split(',').map(headFile => path.join(HEAD_FOLDER_PATH, headFile));
- } else {
- headFiles = [path.join(LAYOUT_FOLDER_PATH, this.frontMatter.layout, LAYOUT_HEAD)];
+
+ /**
+ * Builds page navigation bar with headings up to headingIndexingLevel
+ */
+ buildPageNav() {
+ if (this.isPageNavigationSpecifierValid()) {
+ const $ = cheerio.load(this.content, { xmlMode: false });
+ this.navigableHeadings = {};
+ this.collectNavigableHeadings($(`#${CONTENT_WRAPPER_ID}`)
+ .html());
+ const pageNavTitleHtml = this.generatePageNavTitleHtml();
+ const pageNavHeadingHTML = this.generatePageNavHeadingHtml();
+ this.pageSectionsHtml[`#${PAGE_NAV_ID}`]
+ = htmlBeautify(`\n`
+ + '\n'
+ + `${pageNavTitleHtml}\n`
+ + '\n'
+ + `${pageNavHeadingHTML}\n`
+ + '\n'
+ + '
\n'
+ + '\n', { indent_size: 2 });
+ }
}
- headFiles.forEach((headFile) => {
- const headFilePath = path.join(this.rootPath, headFile);
- if (!fs.existsSync(headFilePath)) {
- return;
+
+ collectHeadFiles(baseUrl, hostBaseUrl) {
+ const { head } = this.frontMatter;
+ let headFiles;
+ const collectedTopContent = [];
+ const collectedBottomContent = [];
+ if (head) {
+ headFiles = head.replace(/, */g, ',')
+ .split(',')
+ .map(headFile => path.join(HEAD_FOLDER_PATH, headFile));
+ } else {
+ headFiles = [path.join(LAYOUT_FOLDER_PATH, this.frontMatter.layout, LAYOUT_HEAD)];
}
- const headFileContent = fs.readFileSync(headFilePath, 'utf8');
- // Set head file as an includedFile
- this.includedFiles.add(headFilePath);
- // Map variables
- const newBaseUrl = calculateNewBaseUrl(this.sourcePath, this.rootPath, this.baseUrlMap) || '';
- const userDefinedVariables = this.userDefinedVariablesMap[path.join(this.rootPath, newBaseUrl)];
- const headFileMappedData = nunjucks.renderString(headFileContent, userDefinedVariables).trim();
- // Split top and bottom contents
- const $ = cheerio.load(headFileMappedData, { xmlMode: false });
- if ($('head-top').length) {
- collectedTopContent.push(nunjucks.renderString($('head-top').html(), { baseUrl, hostBaseUrl })
+ headFiles.forEach((headFile) => {
+ const headFilePath = path.join(this.rootPath, headFile);
+ if (!fs.existsSync(headFilePath)) {
+ return;
+ }
+ const headFileContent = fs.readFileSync(headFilePath, 'utf8');
+ // Set head file as an includedFile
+ this.includedFiles.add(headFilePath);
+ // Map variables
+ const newBaseUrl = Page.calculateNewBaseUrl(this.sourcePath, this.rootPath, this.baseUrlMap) || '';
+ const userDefinedVariables = this.userDefinedVariablesMap[path.join(this.rootPath, newBaseUrl)];
+ const headFileMappedData = nunjucks.renderString(headFileContent, userDefinedVariables)
+ .trim();
+ // Split top and bottom contents
+ const $ = cheerio.load(headFileMappedData, { xmlMode: false });
+ if ($('head-top').length) {
+ collectedTopContent.push(nunjucks.renderString($('head-top')
+ .html(), {
+ baseUrl,
+ hostBaseUrl,
+ })
+ .trim()
+ .replace(/\n\s*\n/g, '\n')
+ .replace(/\n/g, '\n '));
+ $('head-top')
+ .remove();
+ }
+ collectedBottomContent.push(nunjucks.renderString($.html(), {
+ baseUrl,
+ hostBaseUrl,
+ })
.trim()
.replace(/\n\s*\n/g, '\n')
.replace(/\n/g, '\n '));
- $('head-top').remove();
- }
- collectedBottomContent.push(nunjucks.renderString($.html(), { baseUrl, hostBaseUrl })
- .trim()
- .replace(/\n\s*\n/g, '\n')
- .replace(/\n/g, '\n '));
- });
- this.headFileTopContent = collectedTopContent.join('\n ');
- this.headFileBottomContent = collectedBottomContent.join('\n ');
-};
-
-Page.prototype.insertTemporaryStyles = function (pageData) {
- const $ = cheerio.load(pageData);
- // inject temporary navbar styles
- $('navbar').addClass(TEMP_NAVBAR_CLASS);
- // inject temporary dropdown styles
- $('dropdown').each((i, element) => {
- const attributes = element.attribs;
- const placeholder = `