diff --git a/packages/core/src/Page/PageConfig.js b/packages/core/src/Page/PageConfig.js index 59277e5ae8..4ecbb10f8b 100644 --- a/packages/core/src/Page/PageConfig.js +++ b/packages/core/src/Page/PageConfig.js @@ -13,10 +13,6 @@ class PageConfig { * @type {Object} */ this.asset = args.asset; - /** - * @type {string} - */ - this.baseUrl = args.baseUrl; /** * @type {Set} the set of urls representing the sites' base directories */ @@ -25,10 +21,6 @@ class PageConfig { * @type {boolean} */ this.dev = args.dev; - /** - * @type {boolean} - */ - this.enableSearch = args.enableSearch; /** * @type {string} */ @@ -37,15 +29,6 @@ class PageConfig { * @type {Object|{}} */ this.frontmatterOverride = args.frontmatterOverride || {}; - /** - * @type {boolean} - */ - this.globalOverride = args.globalOverride; - /** - * Default maximum heading level to index for all pages. - * @type {number} - */ - this.headingIndexingLevel = args.headingIndexingLevel; /** * @type {string} */ @@ -92,14 +75,6 @@ class PageConfig { * @type {string|string} */ this.title = args.title || ''; - /** - * @type {string} - */ - this.titlePrefix = args.titlePrefix; - /** - * @type {string} - */ - this.titleSuffix = args.titleSuffix; /** * @type {string} */ @@ -108,11 +83,6 @@ class PageConfig { * @type {VariableProcessor} */ this.variableProcessor = args.variableProcessor; - /** - * Array of file types to ignore - * @type {Array} - */ - this.ignore = args.ignore; /** * Array of page source objects * @type {Array} @@ -122,15 +92,6 @@ class PageConfig { * @type {LayoutManager} */ this.layoutManager = args.layoutManager; - /** - * @type {boolean} - */ - this.intrasiteLinkValidation = args.intrasiteLinkValidation; - /** - * Default setting to display line numbers for code blocks - * @type {boolean} - */ - this.codeLineNumbers = args.codeLineNumbers; } } diff --git a/packages/core/src/Page/index.js b/packages/core/src/Page/index.js index 609f3c0fd4..f53b08edac 100644 --- a/packages/core/src/Page/index.js +++ b/packages/core/src/Page/index.js @@ -36,14 +36,21 @@ cheerio.prototype.options.decodeEntities = false; // Don't escape HTML entities class Page { /** * @param {PageConfig} pageConfig + * @param {SiteConfig} siteConfig */ - constructor(pageConfig) { + constructor(pageConfig, siteConfig) { /** * Page configuration passed from {@link Site}. * This should not be mutated. * @type {PageConfig} */ this.pageConfig = pageConfig; + + /** + * Site configuration passed from {@link Site}. + * @type {SiteConfig} + */ + this.siteConfig = siteConfig; } /** @@ -126,11 +133,11 @@ class Page { prepareTemplateData(content, hasPageNav) { let { title } = this; - if (this.pageConfig.titlePrefix) { - title = this.pageConfig.titlePrefix + (title ? TITLE_PREFIX_SEPARATOR + title : ''); + if (this.siteConfig.titlePrefix) { + title = this.siteConfig.titlePrefix + (title ? TITLE_PREFIX_SEPARATOR + title : ''); } - if (this.pageConfig.titleSuffix) { - title = (title ? title + TITLE_SUFFIX_SEPARATOR : '') + this.pageConfig.titleSuffix; + if (this.siteConfig.titleSuffix) { + title = (title ? title + TITLE_SUFFIX_SEPARATOR : '') + this.siteConfig.titleSuffix; } // construct temporary asset object with only POSIX-style paths const asset = {}; @@ -139,7 +146,7 @@ class Page { }); return { asset, - baseUrl: this.pageConfig.baseUrl, + baseUrl: this.siteConfig.baseUrl, content, pageUserScriptsAndStyles: this.pageUserScriptsAndStyles.join('\n'), layoutUserScriptsAndStyles: this.asset.layoutUserScriptsAndStyles.join('\n'), @@ -148,7 +155,7 @@ class Page { faviconUrl: this.pageConfig.faviconUrl, markBindVersion: `MarkBind ${PACKAGE_VERSION}`, title, - enableSearch: this.pageConfig.enableSearch, + enableSearch: this.siteConfig.enableSearch, }; } @@ -167,7 +174,7 @@ class Page { */ generateElementSelectorForPageNav(pageNav) { if (pageNav === 'default') { - return `${Page.generateHeadingSelector(this.pageConfig.headingIndexingLevel)}, panel`; + return `${Page.generateHeadingSelector(this.siteConfig.headingIndexingLevel)}, panel`; } else if (Number.isInteger(pageNav)) { return `${Page.generateHeadingSelector(parseInt(pageNav, 10))}, panel`; } @@ -246,7 +253,7 @@ class Page { */ collectHeadingsAndKeywordsInContent(content, lastHeading, excludeHeadings, sourceTraversalStack) { let $ = cheerio.load(content); - const headingsSelector = Page.generateHeadingSelector(this.pageConfig.headingIndexingLevel); + const headingsSelector = Page.generateHeadingSelector(this.siteConfig.headingIndexingLevel); $('modal').remove(); $('panel').not('panel panel') .each((index, panel) => { @@ -271,8 +278,8 @@ class Page { const src = panel.attribs.src.split('#')[0]; const buildInnerDir = path.dirname(this.pageConfig.sourcePath); const resultInnerDir = path.dirname(this.pageConfig.resultPath); - const includeRelativeToBuildRootDirPath = this.pageConfig.baseUrl - ? path.relative(this.pageConfig.baseUrl, src) + const includeRelativeToBuildRootDirPath = this.siteConfig.baseUrl + ? path.relative(this.siteConfig.baseUrl, src) : src.substring(1); const includeAbsoluteToBuildRootDirPath = path.resolve(this.pageConfig.rootPath, includeRelativeToBuildRootDirPath); @@ -299,7 +306,7 @@ class Page { } }); $ = cheerio.load(content); - if (this.pageConfig.headingIndexingLevel > 0) { + if (this.siteConfig.headingIndexingLevel > 0) { $('modal').remove(); $('panel').remove(); if (!excludeHeadings) { @@ -343,7 +350,7 @@ class Page { processFrontMatter(frontMatter) { this.frontMatter = { ...frontMatter, - ...this.pageConfig.globalOverride, + ...this.siteConfig.globalOverride, ...this.pageConfig.frontmatterOverride, }; @@ -459,14 +466,16 @@ class Page { * @type {FileConfig} */ const fileConfig = { + baseUrl: this.siteConfig.baseUrl, + ignore: this.siteConfig.ignore, + intrasiteLinkValidation: this.siteConfig.intrasiteLinkValidation, + codeLineNumbers: this.siteConfig.style.codeLineNumbers, + baseUrlMap: this.pageConfig.baseUrlMap, - baseUrl: this.pageConfig.baseUrl, rootPath: this.pageConfig.rootPath, - headerIdMap: this.headerIdMap, - ignore: this.pageConfig.ignore, addressablePagesSource: this.pageConfig.addressablePagesSource, - intrasiteLinkValidation: this.pageConfig.intrasiteLinkValidation, - codeLineNumbers: this.pageConfig.codeLineNumbers, + + headerIdMap: this.headerIdMap, }; const { diff --git a/packages/core/src/Site/SiteConfig.js b/packages/core/src/Site/SiteConfig.js index f841bc1100..a3b1092864 100644 --- a/packages/core/src/Site/SiteConfig.js +++ b/packages/core/src/Site/SiteConfig.js @@ -38,9 +38,18 @@ class SiteConfig { * @type {Object} */ this.style = siteConfigJson.style || {}; + + /** + * @type {string} + */ this.style.codeTheme = this.style.codeTheme || 'dark'; + + /** + * Default hide display of line numbers for code blocks + * @type {string} + */ this.style.codeLineNumbers = this.style.codeLineNumbers !== undefined - ? this.style.codeLineNumbers : false; // hide line numbers by default + ? this.style.codeLineNumbers : false; /** * @type {string} @@ -62,6 +71,7 @@ class SiteConfig { this.pagesExclude = siteConfigJson.pagesExclude || []; /** + * Array of file types to ignore * @type {Array} */ this.ignore = siteConfigJson.ignore || []; diff --git a/packages/core/src/Site/index.js b/packages/core/src/Site/index.js index 0c0b28512e..c4d3869a17 100644 --- a/packages/core/src/Site/index.js +++ b/packages/core/src/Site/index.js @@ -284,7 +284,6 @@ class Site { createPage(config) { const sourcePath = path.join(this.rootPath, config.pageSrc); const resultPath = path.join(this.outputPath, fsUtil.setExtension(config.pageSrc, '.html')); - const { codeTheme, codeLineNumbers } = this.siteConfig.style; const pageConfig = new PageConfig({ asset: { @@ -303,7 +302,8 @@ class Site { 'material-icons', 'material-icons.css')), highlight: path.relative(path.dirname(resultPath), - path.join(this.siteAssetsDestPath, 'css', HIGHLIGHT_ASSETS[codeTheme])), + path.join(this.siteAssetsDestPath, 'css', + HIGHLIGHT_ASSETS[this.siteConfig.style.codeTheme])), markBindCss: path.relative(path.dirname(resultPath), path.join(this.siteAssetsDestPath, 'css', 'markbind.min.css')), markBindJs: path.relative(path.dirname(resultPath), @@ -324,14 +324,10 @@ class Site { jQuery: path.relative(path.dirname(resultPath), path.join(this.siteAssetsDestPath, 'js', 'jquery.min.js')), }, - baseUrl: this.siteConfig.baseUrl, baseUrlMap: this.baseUrlMap, dev: this.dev, - enableSearch: this.siteConfig.enableSearch, faviconUrl: config.faviconUrl, frontmatterOverride: config.frontmatter, - globalOverride: this.siteConfig.globalOverride, - headingIndexingLevel: this.siteConfig.headingIndexingLevel, layout: config.layout, layoutsAssetPath: path.relative(path.dirname(resultPath), path.join(this.siteAssetsDestPath, LAYOUT_SITE_FOLDER_NAME)), @@ -344,17 +340,12 @@ class Site { sourcePath, src: config.pageSrc, title: config.title || '', - titlePrefix: this.siteConfig.titlePrefix, - titleSuffix: this.siteConfig.titleSuffix, template: this.pageTemplate, variableProcessor: this.variableProcessor, - ignore: this.siteConfig.ignore, addressablePagesSource: this.addressablePagesSource, layoutManager: this.layoutManager, - intrasiteLinkValidation: this.siteConfig.intrasiteLinkValidation, - codeLineNumbers, }); - return new Page(pageConfig); + return new Page(pageConfig, this.siteConfig); } /**