From ed8ea2edf3da8611a0da78b9623e4fef9cd78d49 Mon Sep 17 00:00:00 2001 From: Kaveh Khorram Date: Sun, 18 Mar 2018 22:27:00 -0700 Subject: [PATCH 1/8] added support for html5 tables and CSS3 styles. --- docs/getting-started-publishing.md | 44 ++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/docs/getting-started-publishing.md b/docs/getting-started-publishing.md index a812ff6e1cb5..85c6ee1646ba 100644 --- a/docs/getting-started-publishing.md +++ b/docs/getting-started-publishing.md @@ -33,8 +33,20 @@ Most of the work to publish to GitHub pages is done for you automatically throug Two of the required parameters are set in the [`siteConfig.js`](api-site-config.md): -- `organizationName`: The GitHub user or organization that owns the repository. In the case of Docusaurus, that would be the "facebook" GitHub organization. -- `projectName`: The name of the GitHub repository for your project. For example, Docusaurus is hosted at https://github.com/facebook/docusaurus, so our project name in this case would be "docusaurus". + + + + + + + + + + + + + +
NameDescription
organizationNameThe GitHub user or organization that owns the repository. In the case of Docusaurus, that would be the "facebook" GitHub organization.
projectNameThe name of the GitHub repository for your project. For example, Docusaurus is hosted at https://github.com/facebook/docusaurus, so our project name in this case would be "docusaurus".
> Docusaurus also supports deploying [user or organization sites](https://help.github.com/articles/user-organization-and-project-pages/#user--organization-pages). These sites will be served from the `master` branch of the repo. So, you will want to have the Docusaurus infra, your docs, etc. in another branch (e.g., maybe call it `source`). To do this, just set `projectName` to "_username_.github.io" (where _username_ is your username or organization name on GitHub) and `organizationName` to "_username_". The publish script will automatically deploy your site to the root of the `master` branch to be served. @@ -42,13 +54,33 @@ Two of the required parameters are set in the [`siteConfig.js`](api-site-config. One of the required parameters is set as a environment variable: -- `GIT_USER`: The username for a GitHub account that has commit access to this repo. For your own repositories, this will usually be your own GitHub username. + + + + + + + + + +
NameDescription
GIT_USERThe username for a GitHub account that has commit access to this repo. For your own repositories, this will usually be your own GitHub username.
There are also two optional parameters that are set as environment variables: -- `USE_SSH`: If this is set to `true`, then SSH is used instead of HTTPS for the connection to the GitHub repo. HTTPS is the default if this variable is not set. - -- `CURRENT_BRANCH`: The branch that contains the latest docs changes that will be deployed. Usually, the branch will be `master`, but it could be any branch (default or otherwise) except for `gh-pages`. If nothing is set for this variable, then the current branch will be used. + + + + + + + + + + + + + +
NameDescription
USE_SSHIf this is set to true, then SSH is used instead of HTTPS for the connection to the GitHub repo. HTTPS is the default if this variable is not set.
CURRENT_BRANCH The branch that contains the latest docs changes that will be deployed. Usually, the branch will be master, but it could be any branch (default or otherwise) except for gh-pages. If nothing is set for this variable, then the current branch will be used.
Once you have the parameter value information, you can go ahead and run the publish script, ensuring you have inserted your own values inside the various parameter placeholders: From bd985de9d7734888e0eda20acc88fa514e04e9de Mon Sep 17 00:00:00 2001 From: Kaveh Khorram Date: Sun, 18 Mar 2018 22:38:58 -0700 Subject: [PATCH 2/8] server file --- lib/server/server.js | 56 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/lib/server/server.js b/lib/server/server.js index 39894e06c492..cf454b70359f 100644 --- a/lib/server/server.js +++ b/lib/server/server.js @@ -82,7 +82,6 @@ function execute(port) { function reloadSiteConfig() { removeModuleAndChildrenFromCache(join(CWD, 'siteConfig.js')); siteConfig = require(join(CWD, 'siteConfig.js')); - if (siteConfig.highlight && siteConfig.highlight.hljs) { siteConfig.highlight.hljs(require('highlight.js')); } @@ -133,7 +132,7 @@ function execute(port) { app.get(/docs\/.*html$/, (req, res, next) => { let url = req.path.toString().replace(siteConfig.baseUrl, ''); - + // let url = 'docs/en/installation.html' // links is a map from a permalink to an id for each document let links = {}; Object.keys(Metadata).forEach(id => { @@ -524,23 +523,54 @@ function execute(port) { // "redirect" requests to pages ending with "/" or no extension so that, // for example, request to "blog" returns same result as "blog/index.html" - app.get(/\/[^\.]*\/?$/, (req, res) => { + app.get(/\/[^\.]*\/?$/, redirect_page); + + function redirect_page(req, res) { let slash = req.path.toString().endsWith('/') ? '' : '/'; - request.get( - 'http://localhost:' + port + req.path + slash + 'index.html', - (err, response, body) => { - if (!err) { - if (response) { - res.status(response.statusCode).send(body); + let requestURL = + 'http://localhost:' + port + req.path + slash + 'index.html'; + request.get(requestURL, (err, response, body) => { + if (!err) { + if (response) { + if (response.statusCode === 404) { + // For some reason, http://localhost:3000/blog/.../introducing-docusaurus/index.html + // gives a page with a response code of 200 and a blank page is rendered. + redirect_page_noHTML(req.path, res); } else { - console.error('No response'); + res.status(response.statusCode).send(body); } } else { - console.error('request failed:', err); + console.log('No response'); } + } else { + console.log('request failed:', err); } - ); - }); + }); + } + + /* +This function is called when a user wants to visit a page w/o using the .html extension. + +e.g. + +now, both: http://localhost:3001/docs/en/installation.html +and +http://localhost:3001/docs/en/installation render the same page. + */ + function redirect_page_noHTML(path, res) { + let requestURL = 'http://localhost:' + port + path + '.html'; + request.get(requestURL, (err, response, body) => { + if (!err) { + if (response) { + res.status(response.statusCode).send(body); + } else { + console.log('No response'); + } + } else { + console.log('request failed:', err); + } + }); + } app.listen(port); console.log('Open http://localhost:' + port + '/'); From 5a3b73b69477632316748601d4294e32aa55c359 Mon Sep 17 00:00:00 2001 From: Kaveh Khorram Date: Sun, 18 Mar 2018 22:43:52 -0700 Subject: [PATCH 3/8] remove prev commit --- docs/getting-started-publishing.md | 44 ++++-------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) diff --git a/docs/getting-started-publishing.md b/docs/getting-started-publishing.md index 85c6ee1646ba..a812ff6e1cb5 100644 --- a/docs/getting-started-publishing.md +++ b/docs/getting-started-publishing.md @@ -33,20 +33,8 @@ Most of the work to publish to GitHub pages is done for you automatically throug Two of the required parameters are set in the [`siteConfig.js`](api-site-config.md): - - - - - - - - - - - - - -
NameDescription
organizationNameThe GitHub user or organization that owns the repository. In the case of Docusaurus, that would be the "facebook" GitHub organization.
projectNameThe name of the GitHub repository for your project. For example, Docusaurus is hosted at https://github.com/facebook/docusaurus, so our project name in this case would be "docusaurus".
+- `organizationName`: The GitHub user or organization that owns the repository. In the case of Docusaurus, that would be the "facebook" GitHub organization. +- `projectName`: The name of the GitHub repository for your project. For example, Docusaurus is hosted at https://github.com/facebook/docusaurus, so our project name in this case would be "docusaurus". > Docusaurus also supports deploying [user or organization sites](https://help.github.com/articles/user-organization-and-project-pages/#user--organization-pages). These sites will be served from the `master` branch of the repo. So, you will want to have the Docusaurus infra, your docs, etc. in another branch (e.g., maybe call it `source`). To do this, just set `projectName` to "_username_.github.io" (where _username_ is your username or organization name on GitHub) and `organizationName` to "_username_". The publish script will automatically deploy your site to the root of the `master` branch to be served. @@ -54,33 +42,13 @@ Two of the required parameters are set in the [`siteConfig.js`](api-site-config. One of the required parameters is set as a environment variable: - - - - - - - - - -
NameDescription
GIT_USERThe username for a GitHub account that has commit access to this repo. For your own repositories, this will usually be your own GitHub username.
+- `GIT_USER`: The username for a GitHub account that has commit access to this repo. For your own repositories, this will usually be your own GitHub username. There are also two optional parameters that are set as environment variables: - - - - - - - - - - - - - -
NameDescription
USE_SSHIf this is set to true, then SSH is used instead of HTTPS for the connection to the GitHub repo. HTTPS is the default if this variable is not set.
CURRENT_BRANCH The branch that contains the latest docs changes that will be deployed. Usually, the branch will be master, but it could be any branch (default or otherwise) except for gh-pages. If nothing is set for this variable, then the current branch will be used.
+- `USE_SSH`: If this is set to `true`, then SSH is used instead of HTTPS for the connection to the GitHub repo. HTTPS is the default if this variable is not set. + +- `CURRENT_BRANCH`: The branch that contains the latest docs changes that will be deployed. Usually, the branch will be `master`, but it could be any branch (default or otherwise) except for `gh-pages`. If nothing is set for this variable, then the current branch will be used. Once you have the parameter value information, you can go ahead and run the publish script, ensuring you have inserted your own values inside the various parameter placeholders: From 56cf7ab20b0c7c48e6edfd471e09599cddad860e Mon Sep 17 00:00:00 2001 From: Kaveh Khorram Date: Sun, 18 Mar 2018 22:48:49 -0700 Subject: [PATCH 4/8] Adding code for dynamic port change funcntionality. --- lib/start-server.js | 46 +++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/lib/start-server.js b/lib/start-server.js index 6c90089f22ad..c0a980d4afa8 100755 --- a/lib/start-server.js +++ b/lib/start-server.js @@ -37,23 +37,29 @@ const program = require('commander'); program.option('--port ', 'Specify port number').parse(process.argv); -const port = parseInt(program.port, 10) || 3000; - -tcpPortUsed - .check(port, 'localhost') - .then(function(inUse) { - if (inUse) { - console.error(chalk.red('Port ' + port + ' is in use')); - process.exit(1); - } else { - console.log('Starting Docusaurus server on port ' + port + '...'); - // start local server on specified port - const server = require('./server/server.js'); - server(port); - } - }) - .catch(function(ex) { - setTimeout(function() { - throw ex; - }, 0); - }); +var port = process.env.PORT || 3000; +checkPort(); + +function checkPort() { + tcpPortUsed + .check(port, 'localhost') + .then(function(inUse) { + if (inUse) { + console.error(chalk.red('Port ' + port + ' is in use')); + // Try again but with port + 1 + port += 1; + checkPort(); + // process.exit(1); + } else { + console.log('Starting Docusaurus server on port ' + port + '...'); + // start local server on specified port + const server = require('./server/server.js'); + server(port); + } + }) + .catch(function(ex) { + setTimeout(function() { + throw ex; + }, 0); + }); +} From cc240151a093c71d0d059d7bb34434b94c2d22b7 Mon Sep 17 00:00:00 2001 From: Kaveh Khorram Date: Sun, 18 Mar 2018 22:51:56 -0700 Subject: [PATCH 5/8] do not include code from previous commit(s) --- lib/server/server.js | 56 ++++++++++---------------------------------- 1 file changed, 13 insertions(+), 43 deletions(-) diff --git a/lib/server/server.js b/lib/server/server.js index cf454b70359f..39894e06c492 100644 --- a/lib/server/server.js +++ b/lib/server/server.js @@ -82,6 +82,7 @@ function execute(port) { function reloadSiteConfig() { removeModuleAndChildrenFromCache(join(CWD, 'siteConfig.js')); siteConfig = require(join(CWD, 'siteConfig.js')); + if (siteConfig.highlight && siteConfig.highlight.hljs) { siteConfig.highlight.hljs(require('highlight.js')); } @@ -132,7 +133,7 @@ function execute(port) { app.get(/docs\/.*html$/, (req, res, next) => { let url = req.path.toString().replace(siteConfig.baseUrl, ''); - // let url = 'docs/en/installation.html' + // links is a map from a permalink to an id for each document let links = {}; Object.keys(Metadata).forEach(id => { @@ -523,54 +524,23 @@ function execute(port) { // "redirect" requests to pages ending with "/" or no extension so that, // for example, request to "blog" returns same result as "blog/index.html" - app.get(/\/[^\.]*\/?$/, redirect_page); - - function redirect_page(req, res) { + app.get(/\/[^\.]*\/?$/, (req, res) => { let slash = req.path.toString().endsWith('/') ? '' : '/'; - let requestURL = - 'http://localhost:' + port + req.path + slash + 'index.html'; - request.get(requestURL, (err, response, body) => { - if (!err) { - if (response) { - if (response.statusCode === 404) { - // For some reason, http://localhost:3000/blog/.../introducing-docusaurus/index.html - // gives a page with a response code of 200 and a blank page is rendered. - redirect_page_noHTML(req.path, res); - } else { + request.get( + 'http://localhost:' + port + req.path + slash + 'index.html', + (err, response, body) => { + if (!err) { + if (response) { res.status(response.statusCode).send(body); + } else { + console.error('No response'); } } else { - console.log('No response'); - } - } else { - console.log('request failed:', err); - } - }); - } - - /* -This function is called when a user wants to visit a page w/o using the .html extension. - -e.g. - -now, both: http://localhost:3001/docs/en/installation.html -and -http://localhost:3001/docs/en/installation render the same page. - */ - function redirect_page_noHTML(path, res) { - let requestURL = 'http://localhost:' + port + path + '.html'; - request.get(requestURL, (err, response, body) => { - if (!err) { - if (response) { - res.status(response.statusCode).send(body); - } else { - console.log('No response'); + console.error('request failed:', err); } - } else { - console.log('request failed:', err); } - }); - } + ); + }); app.listen(port); console.log('Open http://localhost:' + port + '/'); From 4e92c424dbefc590b238da857335279a8c91bf4d Mon Sep 17 00:00:00 2001 From: Kaveh Khorram Date: Tue, 10 Apr 2018 07:28:52 -0700 Subject: [PATCH 6/8] Added attempt threshold. --- lib/start-server.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/start-server.js b/lib/start-server.js index c0a980d4afa8..300c5f92d754 100755 --- a/lib/start-server.js +++ b/lib/start-server.js @@ -38,6 +38,8 @@ const program = require('commander'); program.option('--port ', 'Specify port number').parse(process.argv); var port = process.env.PORT || 3000; +var numAttempts = 0; +var maxAttempts = 10; checkPort(); function checkPort() { @@ -48,8 +50,11 @@ function checkPort() { console.error(chalk.red('Port ' + port + ' is in use')); // Try again but with port + 1 port += 1; + numAttempts += 1; checkPort(); - // process.exit(1); + } else if (inUse && numAttempts >= maxAttempts) { + console.log("Reached max attempts, exiting. Please open up some ports or increase the number of attempts and try again.") + process.exit(1) } else { console.log('Starting Docusaurus server on port ' + port + '...'); // start local server on specified port From 50296ed66781ce624a10fcea6ebc0796124f8bcc Mon Sep 17 00:00:00 2001 From: Kaveh Khorram Date: Tue, 10 Apr 2018 08:05:34 -0700 Subject: [PATCH 7/8] To help fix CI check --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e3d30748e06f..8872e6c703e1 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "url": "https://github.com/facebook/Docusaurus.git" }, "scripts": { - "ci-check": "yarn prettier:diff", + "ci-check": "yarn prettier && yarn prettier:diff", "format:source": "prettier --config .prettierrc --write \"lib/**/*.js\"", "format:examples": "prettier --config .prettierrc --write \"examples/**/*.js\"", "nit:source": "prettier --config .prettierrc --list-different \"lib/**/*.js\"", From 0dc1ace61f913b7d5aa19ac9a7583c8f7b410a48 Mon Sep 17 00:00:00 2001 From: Kaveh Khorram Date: Tue, 10 Apr 2018 08:40:23 -0700 Subject: [PATCH 8/8] Logic change --- lib/start-server.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/start-server.js b/lib/start-server.js index 300c5f92d754..56995630e080 100755 --- a/lib/start-server.js +++ b/lib/start-server.js @@ -46,15 +46,15 @@ function checkPort() { tcpPortUsed .check(port, 'localhost') .then(function(inUse) { - if (inUse) { + if (inUse && numAttempts >= maxAttempts) { + console.log("Reached max attempts, exiting. Please open up some ports or increase the number of attempts and try again.") + process.exit(1) + } else if (inUse) { console.error(chalk.red('Port ' + port + ' is in use')); // Try again but with port + 1 port += 1; numAttempts += 1; checkPort(); - } else if (inUse && numAttempts >= maxAttempts) { - console.log("Reached max attempts, exiting. Please open up some ports or increase the number of attempts and try again.") - process.exit(1) } else { console.log('Starting Docusaurus server on port ' + port + '...'); // start local server on specified port