diff --git a/docs/userGuide/developingASite.md b/docs/userGuide/developingASite.md index 26d4807653..9920c1b1fa 100644 --- a/docs/userGuide/developingASite.md +++ b/docs/userGuide/developingASite.md @@ -37,7 +37,9 @@ MarkBind will generate the site in a folder named `_site` in the current directo | Options | Description | |----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `-f`, `--force-reload` | Force a full reload of all site files when a file is changed. | | `-p`, `--port ` | The port used for serving your website. | +| `-s`, `--site-config ` | Specify the site config file (default: site.json) | | --no-open | Don't open browser automatically. | Note: Live reload is only supported for the following file types: diff --git a/docs/userGuide/userQuickStart.md b/docs/userGuide/userQuickStart.md index 9f27befc2b..015f1997f9 100644 --- a/docs/userGuide/userQuickStart.md +++ b/docs/userGuide/userQuickStart.md @@ -104,6 +104,7 @@ Live reload is enabled to regenerate the site for changes, so you could see the |---|---| | `-f`, `--force-reload` | Force a full reload of all site files when a file is changed. | | `-p`, `--port ` | The port used for serving your website. | +| `-s`, `--site-config ` | Specify the site config file (default: site.json) | | --no-open | Don't open browser automatically. | ### Build the static site diff --git a/index.js b/index.js index acdf742998..c37fb05c3b 100755 --- a/index.js +++ b/index.js @@ -129,13 +129,14 @@ program .description('build then serve a website from a directory') .option('-f, --force-reload', 'force a full reload of all site files when a file is changed') .option('-p, --port ', 'port for server to listen on (Default is 8080)') + .option('-s, --site-config ', 'specify the site config file (default: site.json)') .option('--no-open', 'do not automatically open the site in browser') .action((root, options) => { const rootFolder = path.resolve(root || process.cwd()); const logsFolder = path.join(rootFolder, '_markbind/logs'); const outputFolder = path.join(rootFolder, '_site'); - const site = new Site(rootFolder, outputFolder, options.forceReload); + const site = new Site(rootFolder, outputFolder, options.forceReload, options.siteConfig); const addHandler = (filePath) => { logger.info(`[${new Date().toLocaleTimeString()}] Reload for file add: ${filePath}`); diff --git a/lib/Site.js b/lib/Site.js index 2a963200de..8efec354d5 100644 --- a/lib/Site.js +++ b/lib/Site.js @@ -99,8 +99,8 @@ const GENERATE_SITE_LOGGING_KEY = 'Generate Site'; const MARKBIND_WEBSITE_URL = 'https://markbind.github.io/markbind/'; const MARKBIND_LINK_HTML = `MarkBind ${CLI_VERSION}`; -function Site(rootPath, outputPath, forceReload = false) { - const configPath = findUp.sync(SITE_CONFIG_NAME, { cwd: rootPath }); +function Site(rootPath, outputPath, forceReload = false, siteConfigPath = SITE_CONFIG_NAME) { + const configPath = findUp.sync(siteConfigPath, { cwd: rootPath }); this.rootPath = configPath ? path.dirname(configPath) : rootPath; this.outputPath = outputPath; this.tempPath = path.join(rootPath, TEMP_FOLDER_NAME); @@ -119,6 +119,7 @@ function Site(rootPath, outputPath, forceReload = false) { this.baseUrlMap = {}; this.forceReload = forceReload; this.siteConfig = {}; + this.siteConfigPath = siteConfigPath; this.userDefinedVariablesMap = {}; } @@ -235,7 +236,7 @@ Site.initSite = function (rootPath) { Site.prototype.readSiteConfig = function (baseUrl) { return new Promise((resolve, reject) => { - const siteConfigPath = path.join(this.rootPath, SITE_CONFIG_NAME); + const siteConfigPath = path.join(this.rootPath, this.siteConfigPath); fs.readJsonAsync(siteConfigPath) .then((config) => { this.siteConfig = config; @@ -243,7 +244,7 @@ Site.prototype.readSiteConfig = function (baseUrl) { resolve(this.siteConfig); }) .catch((err) => { - reject(new Error('Failed to read the site config file \'site.json\' at' + reject(new Error(`Failed to read the site config file '${this.siteConfigPath}' at` + `${this.rootPath}:\n${err.message}\nPlease ensure the file exist or is valid`)); }); }); @@ -332,7 +333,7 @@ Site.prototype.collectAddressablePages = function () { Site.prototype.collectBaseUrl = function () { const candidates = walkSync(this.rootPath, { directories: false }) - .filter(x => x.endsWith(SITE_CONFIG_NAME)) + .filter(x => x.endsWith(this.siteConfigPath)) .map(x => path.resolve(this.rootPath, x)); this.baseUrlMap = candidates.reduce((pre, now) => {