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
39 changes: 0 additions & 39 deletions packages/core/src/Page/PageConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ class PageConfig {
* @type {Object<string, string>}
*/
this.asset = args.asset;
/**
* @type {string}
*/
this.baseUrl = args.baseUrl;
/**
* @type {Set<string>} the set of urls representing the sites' base directories
*/
Expand All @@ -25,10 +21,6 @@ class PageConfig {
* @type {boolean}
*/
this.dev = args.dev;
/**
* @type {boolean}
*/
this.enableSearch = args.enableSearch;
/**
* @type {string}
*/
Expand All @@ -37,15 +29,6 @@ class PageConfig {
* @type {Object<string, any>|{}}
*/
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}
*/
Expand Down Expand Up @@ -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}
*/
Expand All @@ -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}
Expand All @@ -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;
}
}

Expand Down
45 changes: 27 additions & 18 deletions packages/core/src/Page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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 = {};
Expand All @@ -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'),
Expand All @@ -148,7 +155,7 @@ class Page {
faviconUrl: this.pageConfig.faviconUrl,
markBindVersion: `MarkBind ${PACKAGE_VERSION}`,
title,
enableSearch: this.pageConfig.enableSearch,
enableSearch: this.siteConfig.enableSearch,
};
}

Expand All @@ -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`;
}
Expand Down Expand Up @@ -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) => {
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -343,7 +350,7 @@ class Page {
processFrontMatter(frontMatter) {
this.frontMatter = {
...frontMatter,
...this.pageConfig.globalOverride,
...this.siteConfig.globalOverride,
...this.pageConfig.frontmatterOverride,
};

Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/Site/SiteConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,18 @@ class SiteConfig {
* @type {Object<string, any>}
*/
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}
Expand All @@ -62,6 +71,7 @@ class SiteConfig {
this.pagesExclude = siteConfigJson.pagesExclude || [];

/**
* Array of file types to ignore
* @type {Array}
*/
this.ignore = siteConfigJson.ignore || [];
Expand Down
15 changes: 3 additions & 12 deletions packages/core/src/Site/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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),
Expand All @@ -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)),
Expand All @@ -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);
}

/**
Expand Down