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
2 changes: 2 additions & 0 deletions docs/userGuide/developingASite.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <port>` | The port used for serving your website. |
| `-s`, `--site-config <file>` | 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:
Expand Down
1 change: 1 addition & 0 deletions docs/userGuide/userQuickStart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <port>` | The port used for serving your website. |
| `-s`, `--site-config <file>` | Specify the site config file (default: site.json) |
| --no-open | Don't open browser automatically. |

### Build the static site
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>', 'port for server to listen on (Default is 8080)')
.option('-s, --site-config <file>', '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}`);
Expand Down
11 changes: 6 additions & 5 deletions lib/Site.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ 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, forceReload = false) {
const configPath = findUp.sync(SITE_CONFIG_NAME, { cwd: rootPath });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this line of code means that the user can no longer serve inside the subdirectories, but have to always go back to the root directory and serve. Not sure whether it is a good idea since it can be a convenience feature for the user.

@jamos-tay jamos-tay Oct 1, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm alright, then it might be better to revert this change and enforce that all alternate site.json files be in the root folder. I don't really want to mess with the config path logic in case something messes up

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);
Expand All @@ -119,6 +119,7 @@ function Site(rootPath, outputPath, forceReload = false) {
this.baseUrlMap = {};
this.forceReload = forceReload;
this.siteConfig = {};
this.siteConfigPath = siteConfigPath;
this.userDefinedVariablesMap = {};
}

Expand Down Expand Up @@ -235,15 +236,15 @@ 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;
this.siteConfig.baseUrl = (baseUrl === undefined) ? this.siteConfig.baseUrl : 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`));
});
});
Expand Down Expand Up @@ -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) => {
Expand Down