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
1 change: 1 addition & 0 deletions docs/userGuide/userQuickStart.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Live reload is enabled to regenerate the site for changes, so you could see the

| Options | Description |
|---|---|
| `-f`, `--force-reload` | Force a full reload of all site files when a file is changed. |
| `-p`, `--port <port>` | The port used for serving your website. |
| --no-open | Don't open browser automatically. |

Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,15 @@ program
program
.command('serve [root]')
.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>', 'port for server to listen on (Default is 8080)')
.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);
const site = new Site(rootFolder, outputFolder, options.forceReload);

const addHandler = (filePath) => {
logger.info(`[${new Date().toLocaleTimeString()}] Reload for file add: ${filePath}`);
Expand Down
16 changes: 10 additions & 6 deletions lib/Site.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const GENERATE_SITE_LOGGING_KEY = 'Generate Site';
const MARKBIND_WEBSITE_URL = 'https://markbind.github.io/markbind/';
const MARKBIND_LINK_HTML = `<a href='${MARKBIND_WEBSITE_URL}'>MarkBind ${CLI_VERSION}</a>`;

function Site(rootPath, outputPath) {
function Site(rootPath, outputPath, forceReload = false) {
const configPath = findUp.sync(SITE_CONFIG_NAME, { cwd: rootPath });
this.rootPath = configPath ? path.dirname(configPath) : rootPath;
this.outputPath = outputPath;
Expand All @@ -117,6 +117,7 @@ function Site(rootPath, outputPath) {
// Other properties
this.addressablePages = [];
this.baseUrlMap = {};
this.forceReload = forceReload;
this.siteConfig = {};
this.userDefinedVariablesMap = {};
}
Expand Down Expand Up @@ -443,7 +444,8 @@ Site.prototype.buildSourceFiles = function () {
};

Site.prototype._rebuildAffectedSourceFiles = function (filePaths) {
const uniquePaths = _.uniq(filePaths);
const filePathArray = Array.isArray(filePaths) ? filePaths : [filePaths];
const uniquePaths = _.uniq(filePathArray);
logger.verbose(`Rebuild affected paths: ${uniquePaths}`);
return new Promise((resolve, reject) => {
this.regenerateAffectedPages(uniquePaths)
Expand All @@ -464,7 +466,8 @@ Site.prototype.rebuildAffectedSourceFiles
= delay(Site.prototype._rebuildAffectedSourceFiles, 1000);

Site.prototype._buildMultipleAssets = function (filePaths) {
const uniquePaths = _.uniq(filePaths);
const filePathArray = Array.isArray(filePaths) ? filePaths : [filePaths];
const uniquePaths = _.uniq(filePathArray);
const ignoreConfig = this.siteConfig.ignore || [];
const fileIgnore = ignore().add(ignoreConfig);
const fileRelativePaths = uniquePaths.map(filePath => path.relative(this.rootPath, filePath));
Expand All @@ -482,7 +485,8 @@ Site.prototype.buildAsset
= delay(Site.prototype._buildMultipleAssets, 1000);

Site.prototype._removeMultipleAssets = function (filePaths) {
const uniquePaths = _.uniq(filePaths);
const filePathArray = Array.isArray(filePaths) ? filePaths : [filePaths];
const uniquePaths = _.uniq(filePathArray);
const fileRelativePaths = uniquePaths.map(filePath => path.relative(this.rootPath, filePath));
const filesToRemove = fileRelativePaths.map(
fileRelativePath => path.join(this.outputPath, fileRelativePath));
Expand Down Expand Up @@ -578,9 +582,9 @@ Site.prototype.generatePages = function () {
Site.prototype.regenerateAffectedPages = function (filePaths) {
const builtFiles = {};
const processingFiles = [];
const shouldRebuildAllPages = this.collectUserDefinedVariablesMapIfNeeded(filePaths);
const shouldRebuildAllPages = this.collectUserDefinedVariablesMapIfNeeded(filePaths) || this.forceReload;
if (shouldRebuildAllPages) {
logger.warn('Rebuilding all pages as variables file was changed');
logger.warn('Rebuilding all pages as variables file was changed, or the --force-reload flag was set');
}
this._setTimestampVariable();
this.pages.forEach((page) => {
Expand Down